Kowal Posted November 29, 2013 Share Posted November 29, 2013 How to get the coordinates of a point on the extension of the LWpoliline. If I use the function with the argument T is not getting the expected result. (vlax-curve-getClosestPointTo curve-obj givenPnt [extend]) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 29, 2013 Share Posted November 29, 2013 The extend option will only extend certain objects, e.g.: (defun c:test ( / ent pnt ) (if (and (setq pnt (getpoint "\nPick point: ")) (setq ent (car (entsel))) ) (entmake (list '(0 . "POINT") (cons 10 (vlax-curve-getclosestpointto ent (trans pnt 1 0) t)))) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
dong95 Posted November 30, 2013 Share Posted November 30, 2013 Great explanation, Lee. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 30, 2013 Share Posted November 30, 2013 Thank you dong Quote Link to comment Share on other sites More sharing options...
Kowal Posted December 1, 2013 Author Share Posted December 1, 2013 Thank you Lee. I tried to use 3DPOLYLINE. But another problem appeared. At the end of 3DPolyline does not function properly. How to do at the end of the line is perpendicular. Sorry for my english Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 1, 2013 Share Posted December 1, 2013 How to do at the end of the line is perpendicular. Sorry, I don't understand your question Maybe you require vlax-curve-getclosestpointtoprojection? - an explanation of the difference can be found here. Quote Link to comment Share on other sites More sharing options...
GP_ Posted December 1, 2013 Share Posted December 1, 2013 (edited) One... If I have understood correctly. (defun c:test ( / 3dp p p_end p_prev) (if (and (setq 3dp (vlax-ename->vla-object (car (entsel "\nSelect 3Dpolyline")))) (setq p (trans (getpoint "\nSelect Point") 1 0)) ) (progn (setq p_end (vlax-curve-getEndPoint 3dp)) (setq p_prev (vlax-curve-getPointAtParam 3dp (- (vlax-curve-getEndParam 3dp) 0.5))) (setq p_perp (LM:ProjectPointToLine p p_end p_prev)) (entmake (list '(0 . "POINT") (cons 10 p_perp) ) ) ) ) (princ) ) ;---------------------------------------------------------------- (defun LM:ProjectPointToLine ( pt p1 p2 / nm ) (setq nm (mapcar '- p2 p1) p1 (trans p1 0 nm) pt (trans pt 0 nm) ) (trans (list (car p1) (cadr p1) (caddr pt)) nm 0) ) Edited December 1, 2013 by GP_ Quote Link to comment Share on other sites More sharing options...
Kowal Posted December 1, 2013 Author Share Posted December 1, 2013 I need projection point to LWpolylne or 3Dpolyline (0 level). I have a entitiy lwpolyline and coordinate red points. I need coordinate green points. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 1, 2013 Share Posted December 1, 2013 I need projection point to LWpolylne or 3Dpolyline (0 level). Try this: (defun closestpointto ( ent pnt ) (if (vlax-curve-isclosed ent) (vlax-curve-getclosestpointto ent pnt) (car (vl-sort (list (vlax-curve-getclosestpointto ent pnt) (LM:projectpointtoline pnt (vlax-curve-getpointatparam ent (vlax-curve-getstartparam ent)) (vlax-curve-getpointatparam ent (1+ (vlax-curve-getstartparam ent))) ) (LM:projectpointtoline pnt (vlax-curve-getpointatparam ent (vlax-curve-getendparam ent)) (vlax-curve-getpointatparam ent (1- (vlax-curve-getendparam ent))) ) ) '(lambda ( a b ) (< (distance pnt a) (distance pnt b))) ) ) ) ) ;; Project Point to Line - Lee Mac ;; Projects pt onto the line defined by p1,p2 (defun LM:projectpointtoline ( pt p1 p2 / nm ) (setq nm (mapcar '- p2 p1) p1 (trans p1 0 nm) pt (trans pt 0 nm) ) (trans (list (car p1) (cadr p1) (caddr pt)) nm 0) ) (vl-load-com) (princ) Test code: (defun c:test ( / ent pnt ) (if (and (setq pnt (getpoint "\nPick point: ")) (setq ent (car (entsel))) ) (entmake (list '(0 . "POINT") (cons 10 (closestpointto ent (trans pnt 1 0))))) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Kowal Posted December 2, 2013 Author Share Posted December 2, 2013 Than you Lee. Code is great. But for lwpolyline coordinates'((0.000 0.000) (18.028 0.890) (40.211 2.298 )) not working properly. Point (35.924 1.679) returns (35.919 1.773). Correctly (35.924 1.679) -> (35.902 2.024). Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 2, 2013 Share Posted December 2, 2013 Than you Lee. Code is great. But for lwpolyline coordinates'((0.000 0.000) (18.028 0.890) (40.211 2.298 )) not working properly. Point (35.924 1.679) returns (35.919 1.773). Correctly (35.924 1.679) -> (35.902 2.024). Good catch! - try this instead: (defun closestpointto ( ent pnt ) (if (vlax-curve-isclosed ent) (vlax-curve-getclosestpointto ent pnt) (car (vl-sort (list (vlax-curve-getclosestpointto ent pnt) (LM:projectpointtoray pnt (vlax-curve-getpointatparam ent (1+ (vlax-curve-getstartparam ent))) (vlax-curve-getpointatparam ent (vlax-curve-getstartparam ent)) ) (LM:projectpointtoray pnt (vlax-curve-getpointatparam ent (1- (vlax-curve-getendparam ent))) (vlax-curve-getpointatparam ent (vlax-curve-getendparam ent)) ) ) '(lambda ( a b ) (< (distance pnt a) (distance pnt b))) ) ) ) ) ;; Project Point to Ray - Lee Mac ;; Projects pt onto the ray defined by p1,p2 (defun LM:projectpointtoray ( pt p1 p2 / nm ) (setq nm (mapcar '- p2 p1) p1 (trans p1 0 nm) pt (trans pt 0 nm) ) (trans (list (car p1) (cadr p1) (max (caddr p1) (caddr pt))) nm 0) ) (vl-load-com) (princ) Quote Link to comment Share on other sites More sharing options...
Kowal Posted December 3, 2013 Author Share Posted December 3, 2013 Thank you Lee. Code works great. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 3, 2013 Share Posted December 3, 2013 Excellent to hear Kowal, thanks. Quote Link to comment Share on other sites More sharing options...
thanhduan2407 Posted July 27, 2021 Share Posted July 27, 2021 Hello Lee Mac! First of all I would like to thank you very much for what you bring to the worldwide community and I myself use a lot. I have used your program above, but when I draw a 3D Polyline triangle like the picture above, it doesn't work as expected. Hope you answer. Quote Link to comment Share on other sites More sharing options...
thanhduan2407 Posted July 27, 2021 Share Posted July 27, 2021 When I view 3D, I understand how it is. But I want to lower the perpendicular in the XY plane, how will I do it? Quote Link to comment Share on other sites More sharing options...
thanhduan2407 Posted July 27, 2021 Share Posted July 27, 2021 (defun TD:ClosestPointTo (eObj Pnt / LTSVER OBJPLINE2D PT1 PT2 TYPEOBJ X) (setq TypeObj (cdr (assoc 0 (entget eObj)))) (cond ((= TypeObj "POLYLINE") (progn (setq LtsVer (mapcar '(lambda (x) (list (car x) (cadr x) 0.0)) (acet-geom-vertex-list eObj))) (entmake (append (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 90 (length LtsVer)) ) (mapcar (function (lambda (x) (cons 10 x))) LtsVer) ) ) (setq ObjPline2D (entlast)) (if (vlax-curve-isclosed (vlax-ename->vla-object eObj)) (vla-put-closed (vlax-ename->vla-object ObjPline2D) :vlax-true) ) (setq Pt1 (ClosestPointTo (vlax-ename->vla-object ObjPline2D) Pnt)) (setq Para (vlax-curve-getParamAtPoint (vlax-ename->vla-object ObjPline2D) Pt1)) (setq Pt2 (vlax-curve-getPointAtParam (vlax-ename->vla-object eObj) Para)) (entdel ObjPline2D) ) ) ((= TypeObj "LWPOLYLINE") (setq Pt2 (ClosestPointTo (vlax-ename->vla-object eObj) Pnt)) ) ) Pt2 ) I figured it out and made it like this! Don't know is that okay? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.