Author Topic: Find 2 nearest points from a variant-list to a startpoint  (Read 1278 times)

0 Members and 1 Guest are viewing this topic.

Peter2

  • Swamp Rat
  • Posts: 653
Find 2 nearest points from a variant-list to a startpoint
« on: August 16, 2017, 01:29:09 PM »
I have a startpoint with coords 10,15,0

Then I have some points, originally in a variant, but converted to list:
(10 12 10 18 9 12 8 5 7 12)

I have to find the 2 points which are the nearest to my startpoint. It's obviously not insolvable, but does anyone knows an existing solution?

Thanks   :-)
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Find 2 nearest points from a variant-list to a startpoint
« Reply #1 on: August 16, 2017, 01:42:16 PM »
Code - Auto/Visual Lisp: [Select]
  1. (vl-sort listofpoints '(lambda (a b) (< (distance basepoint a) (distance basepoint b))))


The first two points in the sorted list are what you want. (car ..) (cadr ..)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

DEVITG

  • Bull Frog
  • Posts: 480
Re: Find 2 nearest points from a variant-list to a startpoint
« Reply #2 on: August 16, 2017, 07:46:48 PM »
Peter , your start point is some XYZ , and the others no way , it could be XYZ but it are 10 values
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Peter2

  • Swamp Rat
  • Posts: 653
Re: Find 2 nearest points from a variant-list to a startpoint
« Reply #3 on: August 17, 2017, 09:03:34 AM »
Thanks to both  :-)
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23