Jump to content

Check if points is Line


ketxu

Recommended Posts

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 :ouch:

(sorry for my bad English)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

;;;++++++++++ 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

Link to comment
Share on other sites

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 ^^)

Link to comment
Share on other sites

;;;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

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :thumbsup:

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...