Jump to content

Find the list of the nearest 3 points


motee-z

Recommended Posts

hello

it will be great for me and for others

to creat a lisp that can find the list of the nearest three points to optional point my goal is to calculate the level of any point in the drawing contain of a group of 3d points every 3points form a triangle (surface) so if i want to find level in a space point inside the triangle i must obtain the list of these 3point

then i have a routin that can calculate the level if i know three points

i will submit it as soon as i got above

thanks to all

Link to comment
Share on other sites

If someone is modelling the ground surface, they should have used software that generated A DTM (digital terrain model) usually using a TINs (triangular irregular networks). It would be better to use the TIN to determine elevation of any point, rather than the 3 nearest points (which might not be the correct points/elevations). But lacking a DTM, using the 3 nearest points could provide sufficient accuracy. Usually.

 

Are these standard AutoCAD point objects?

Link to comment
Share on other sites

thank you carlB for your reply

there are many programs that can calculate the level in any point of a tin like land development

but the challenge is to calculted in autocad2002-up to2008

i think they use idea that i wrote,if there is a tin in autocad you can know level only on lines connected between points but if the required point inside the triangle i think you have to know the nearst 3points then retrive elevation from the even formed by them

i think any routin do this must follow this step

1- retrive the list of all points in drawing and keep it in afile (x,y,z)

2-compar distance between requied point to all points

3-form a list of the nearest 3 point

4-retrive the level of these points

5-to this step i got an even defined by three points then i can know (z)of any insider point to make it belong to this even

thanks

Link to comment
Share on other sites

I think that:

 

(defun c:npts(/ ptSet tPt ptLst outLst)
 (if
   (and
     (setq ptSet(ssget "_X" '((0 . "POINT"))))
     (<= 3(sslength ptSet))
     (setq tPt(getpoint "\nSpecify testing point: "))
     ); end and
   (progn
     (setq ptLst(vl-sort
	   (mapcar '(lambda(x)(cons(distance x tPt)x))
	    (mapcar 'cdr
	     (mapcar '(lambda(x)(assoc 10 x))
                     (mapcar 'entget(vl-remove-if 'listp
                      (mapcar 'cadr(ssnamex ptSet)))))))
                '(lambda(a b)(<(car a)(car b)))))
     (setq outLst(mapcar 'cdr
		  (list(car ptLst)(cadr ptLst)(nth 2 ptLst))))
     ); end progn
   ); end if
 ); end of c:npts

 

Variable ptLst is list with members (distance X-coord Y-coord Z-coord) for each point which sorted to minimum distance to tested point . outLst - is 3 fist members of ptLst. Apply (mapcar 'last to get Z-coords. Some cases you can have several points with equal distances to testing point or all distances will equal (points on a sphere and testing point in center).

Link to comment
Share on other sites

thank you mr.asmi

actualy i did'not expect that someone could do what i ask for thanks again

one thing more please can you allow the user to select the points and keep them in a permanent name to be used latter because my be i do'nt want all the points to be considered and not to select them every time

and the routin ask me for the name of group points

thanks

Link to comment
Share on other sites

To me up to the end not clearly as it should work. However you can keep sets of points in corresponding variables:

 

(setq mySetX(ssget '((0 . "POINT"))))

 

And use it in function:

 

(defun Get_Nearest_Points(ptSet / ptSet tPt ptLst outLst)
 (princ "\n<<< Select points >>> ")
 (if
   (and
     ptSet
     (<= 3(sslength ptSet))
     ); end and
   (progn
     (if
(setq tPt(getpoint "\nSpecify testing point: "))
 (progn
     		(setq ptLst(vl-sort
	   (mapcar '(lambda(x)(cons(distance x tPt)x))
	     (mapcar '(lambda(x)(cdr(assoc 10 x)))
                     (mapcar 'entget(vl-remove-if 'listp
                      (mapcar 'cadr(ssnamex ptSet))))))
                '(lambda(a b)(<(car a)(car b))))
                     outLst(mapcar 'cdr
		    (list(car ptLst)(cadr ptLst)(nth 2 ptLst)))
	      ); end setq
   (grdraw(car outLst)tPt 1)
   (grdraw(cadr outLst)tPt 1)
   (grdraw(nth 2 outLst)tPt 1)
     ); end progn
    (princ "\nInvalid or empty input! ")
    ); end if
   ); end progn
   (princ "\nYou need at least 3 points! ")
  ); end if
 outLst
 ); end of Get_Nearest_Points

 

(Get_Nearest_P mySetX)

 

Remember that AutoCAD supports only 128 selection sets.

npts.gif

Link to comment
Share on other sites

i think they use idea that i wrote,if there is a tin in autocad you can know level only on lines connected between points but if the required point inside the triangle i think you have to know the nearst 3points then retrive elevation from the even formed by them

 

If you form a TIN in LDD, you can enable elevation tracking

ElevationTracking.jpg

Link to comment
Share on other sites

here is the routin after some modification

with note that the function distance in autolisp means 3d distance so it gives error if we have high elevation

so i modify to get 2d distance and show the nearest 3 point surronded with circle

i did 'nt undestand your routin after modification please add it to my modification

;cod

(defun c:evenv(/)

(if(null txth)

(setq txth 1.25))

(setq txthnew(getreal(strcat"\n enter text height<1>

 

 

Link to comment
Share on other sites

waiting for your opinion mr ASMI

i try the lisp in many drawings it gives correct value except when the test point located outside the outlst points any support or suggestion will be wellcome

Link to comment
Share on other sites

  • 2 years later...
To me up to the end not clearly as it should work. However you can keep sets of points in corresponding variables:

 

(setq mySetX(ssget '((0 . "POINT"))))

 

And use it in function:

 

(defun Get_Nearest_Points(ptSet / ptSet tPt ptLst outLst)
 (princ "\n<<< Select points >>> ")
 (if
   (and
     ptSet
     (<= 3(sslength ptSet))
     ); end and
   (progn
     (if
(setq tPt(getpoint "\nSpecify testing point: "))
 (progn
     		(setq ptLst(vl-sort
	   (mapcar '(lambda(x)(cons(distance x tPt)x))
	     (mapcar '(lambda(x)(cdr(assoc 10 x)))
                     (mapcar 'entget(vl-remove-if 'listp
                      (mapcar 'cadr(ssnamex ptSet))))))
                '(lambda(a b)(<(car a)(car b))))
                     outLst(mapcar 'cdr
		    (list(car ptLst)(cadr ptLst)(nth 2 ptLst)))
	      ); end setq
   (grdraw(car outLst)tPt 1)
   (grdraw(cadr outLst)tPt 1)
   (grdraw(nth 2 outLst)tPt 1)
     ); end progn
    (princ "\nInvalid or empty input! ")
    ); end if
   ); end progn
   (princ "\nYou need at least 3 points! ")
  ); end if
 outLst
 ); end of Get_Nearest_Points

 

(Get_Nearest_P mySetX)

 

Remember that AutoCAD supports only 128 selection sets.

Hi Asmi..

In the same way.is it can be done in Visual Basic for Finding nearest points from an point

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...