ketxu Posted July 13, 2011 Share Posted July 13, 2011 Could you help me how and which is fastest to check if multi point is lie in Line (all direction)?. I just think idea calculate k with x,y, and check loop three point as pair, but it might too slow (sorry for my bad English) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 13, 2011 Share Posted July 13, 2011 Hi , Select a line and the routine would select all points that lie on the selected line . (defun c:test (/ e ent lst i ss ents) ;; Tharwat 13. 07. 2011 (if (and (setq e (car (entsel "\n Select a Line :"))) (eq (cdr (assoc 0 (setq ent (entget e)))) "LINE") ) (progn (setq lst (ssget "_f" (list (cdr (assoc 10 ent)) (cdr (assoc 11 ent))) ) ) (repeat (setq i (sslength lst)) (setq ss (ssname lst (setq i (1- i)))) (setq ents (entget ss)) (if (not (eq (cdr (assoc 0 ents)) "POINT")) (ssdel ss lst) ) ) ) (princ) ) (if lst (sssetfirst nil lst ) ) (princ) ) Tharwat Quote Link to comment Share on other sites More sharing options...
David Bethel Posted July 13, 2011 Share Posted July 13, 2011 ;;;++++++++++ 3D Is Point On Line ++++++++++++++++++++++++++++++++++++++ ;;;ARG -> TestPt LinePt1 LinePt2 Fuzz ;;;RET T nil (defun is_pt_online (pt l1 l2 fz) (equal (distance l1 l2) (+ (distance l1 pt) (distance l2 pt)) fz)) -David Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 13, 2011 Share Posted July 13, 2011 Geometric Functions Quote Link to comment Share on other sites More sharing options...
ketxu Posted July 13, 2011 Author Share Posted July 13, 2011 Thanks all and nice to be helped ^^ @tharwat : sorry for my Bad English, so it harder and harder to me to described, it can make misunderstanding ^^ I have no Point object, just a point to check @David : it like to check in a segment. How about if pt is still on line, but it out of l1 l2 (extend of l1-l2)? so, i will add more cond ^^ @LeeMac : oh, just say thanks and copy. I like LM:ListCollinear-p but it more difficult to understand (to me ^^) Quote Link to comment Share on other sites More sharing options...
David Bethel Posted July 13, 2011 Share Posted July 13, 2011 ;;;Are Points CoLinear ;;;ARG -> 3 Points and Fuzz ;;;RET -> T nil (defun is_pt_colinear (p1 p2 p3 fz) (or (equal (distance p1 p3) (+ (distance p1 p2) (distance p2 p3)) fz) (equal (distance p1 p2) (+ (distance p1 p3) (distance p3 p2)) fz) (equal (distance p2 p3) (+ (distance p1 p2) (distance p1 p3)) fz))) -David Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 13, 2011 Share Posted July 13, 2011 @LeeMac : oh, just say thanks and copy. I like LM:ListCollinear-p but it more difficult to understand (to me ^^) You're welcome. A quick explanation of my collinear predicate functions: LM:Collinear-p uses the triangle inequality to test the collinearity of three points, LM:ListCollinear-p uses the fact that the vector dot product between two collinear unit vectors will equal +/- 1. Quote Link to comment Share on other sites More sharing options...
ketxu Posted July 15, 2011 Author Share Posted July 15, 2011 You're welcome. A quick explanation of my collinear predicate functions: LM:Collinear-p uses the triangle inequality to test the collinearity of three points, LM:ListCollinear-p uses the fact that the vector dot product between two collinear unit vectors will equal +/- 1. Tks Lee ^^ (link is so useful) Ah, i have just wrote a more simple (to me) collinear, but i don't sure it's going right. Please recommend to help me (defun ST:Geo-Linear (p1 p2 p3 fuzz) ((lambda ( a b ) (or (equal (abs (- a b)) pi fuzz) (equal (abs (- a b)) 0 fuzz) ) ) (angle p1 p2)(angle p1 p3) )) (defun ST:Geo-ListLinear (lst / tmp) (setq i 2) (cond ((and (= (length lst) 3)(ST:Geo-Linear(car lst)(cadr lst)(caddr lst) 1e-)(setq tmp T)) (T (while (and (< i (1- (length lst))) (setq tmp (ST:Geo-Linear (nth 0 lst)(nth 1 lst) (nth (setq i (1+ i)) lst) 1e-)) tmp ) ) ) tmp ) Cause function will stop immediately when it find out three point not "in Line", so i think it a bit more quickly Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 15, 2011 Share Posted July 15, 2011 The angle function will measure angles from the X-axis of the UCS plane. Quote Link to comment Share on other sites More sharing options...
ketxu Posted July 15, 2011 Author Share Posted July 15, 2011 The angle function will measure angles from the X-axis of the UCS plane. I thinked about it, but i guess (not sure) it may not problem if only compare angle.If it linear, when X-axis change, subtract of 3 point in Line still eq 0 or pi (i'm not sure). Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 15, 2011 Share Posted July 15, 2011 I thinked about it, but i guess (not sure) it may not problem if only compare angle.If it linear, when X-axis change, subtract of 3 point in Line still eq 0 or pi (i'm not sure). Set your UCS to World and try: (ST:Geo-Linear '(1.0 1.0 1.0) '(2.0 2.0 4.0) '(3.0 3.0 3.0)) Cause function will stop immediately when it find out three point not "in Line", so i think it a bit more quickly If you study my function a little closer you will notice that the recursive call will not be reached if any three points are not collinear. Quote Link to comment Share on other sites More sharing options...
devitg Posted July 15, 2011 Share Posted July 15, 2011 Other way to skin a cat (defun c:point@line (/AUX-PT E E-OBJ ENT PT PT-XYZ ) ;; Tharwat 13. 07. 2011 ;; add by DEVITG (VL-LOAD-COM) (if (and (setq e (car (entsel "\n Select a Line :"))) (eq (cdr (assoc 0 (setq ent (entget e)))) "LINE") (setq pt (car (entsel "\n Select a point :"))) (eq (cdr (assoc 0 (setq ent (entget pt)))) "POINT") );_and (progn (setq e-obj (vlax-ename->vla-object e)) (setq pt-xyz (cdr (assoc 10 (setq ent (entget pt))))) (setq aux-pt (vlax-curve-getclosestpointto e-obj pt-xyz t)) (if (equal aux-pt pt-xyz) (alert "point belong to line") (alert "point is out the line") ) );_ progn );_ if );_ end defun Quote Link to comment Share on other sites More sharing options...
ketxu Posted July 16, 2011 Author Share Posted July 16, 2011 Set your UCS to World and try: (ST:Geo-Linear '(1.0 1.0 1.0) '(2.0 2.0 4.0) '(3.0 3.0 3.0)) If you study my function a little closer you will notice that the recursive call will not be reached if any three points are not collinear. Oh, now i understand ^^ It don't look in Z coord ^^ So i will return distance.. In your listcollinear, it use "recursive", and i not good in this case.Hihi.. I still have to study more and more. Thank you so much . Have a good day Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 16, 2011 Share Posted July 16, 2011 Thank you so much . Have a good day You're welcome, you too 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.