+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 24
  1. #1
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Jun 2012
    Posts
    350

    Default Position of point with respect to a line

    Registered forum members do not see this ad.

    Hello everybody,

    I have three points A(x1,y1), B(x2, y2) and C(x3, y3). How can I find which side C is when looked from A to B. That is whether point C is on the left or right of line AB by a calculation with the coordinates of the three points.

    Thanks in advance.

    Aloy

  2. #2
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,026

    Default

    Hi Aloy,

    Please try this.
    Code:
    (and (setq a (getpoint "\nSpecify point A :"))
         (setq b (getpoint "\nSpecify point B :" a))
         (setq c (getpoint "\nSpecify point C :"))
         (alert (strcat "Point resides on the " (if (minusp (sin (- (angle a b) (angle a c)))) "Left" "Right") " Side."))
         )

  3. #3
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Jun 2012
    Posts
    350

    Default

    Thanks Tharwat. Actually I wanted the three points to be assigned by a program to handle area calculations automatically for cut and fills in earthworks. I think I can make use of the last line.
    Thanks again.

    Aloy

  4. #4
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,635

    Default

    There is a also a vector answer similar to Tharwat solution I know I used it but am struggling to find it, uses x & y

    Found an example it returns a + or - answer. Now to find my lisp version.

    Code:
    (p2.X-p1.X)*(p3.Y-p1.Y)-(p2.Y-p1.Y)*(p3.X-p1.X)
    A man who never made mistakes never made anything

  5. #5
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,026

    Default

    Quote Originally Posted by aloy View Post
    Thanks Tharwat. Actually I wanted the three points to be assigned by a program to handle area calculations automatically for cut and fills in earthworks. I think I can make use of the last line.
    Thanks again.

    Aloy
    You are welcome Aloy and good luck.

  6. #6
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Jun 2012
    Posts
    350

    Default

    Hi Bigal,
    I found similar vector cross product thing when I searched. But I thought it is too long. Besides it involves determinants and transpose etc. Thanks for pointing out.

    Aloy

  7. #7
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Jun 2012
    Posts
    350

    Default

    Hi Tharwat,
    It works very nicely. I will post the code and the drawing that was generated for working out the areas of cuts and fills auomatically.

    Here x2 is point of intersection at the end of cut or fill, q3 is A, q4 is B and pz is C. It gave me the sum of two cuts and one fill. You saved lot of time for me.

    Aloy
    Code:
    (if x2 (progn (setq i2 (angle q3 q4)) (setq i3(angle q3 pz))))    
        (if (and x2 (and (> (sin (- i2 i3)) 0.0))) (setq fill (+ fill a)))
        (if (and x2 (and (< (sin (- i2 i3)) 0.0))) (setq cut (+ cut a)))
    Attached Images

  8. #8
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,305

    Default

    Here's another way, using the vector cross product:
    Code:
    (defun c:test ( / a b c )
        (if (and (setq a (getpoint "\n1st point of line: "))
                 (setq b (getpoint "\n2nd point of line: " a))
                 (setq c (getpoint "\nPoint to test: "))
            )
            (LM:clockwise-p a c b)
        )
    )
    
    ;; Clockwise-p - Lee Mac
    ;; Returns T if p1,p2,p3 are clockwise oriented
    
    (defun LM:clockwise-p ( a b c )
        (apply '> (mapcar '* (mapcar '- c a) (reverse (mapcar '- b a '(0 0)))))
    )
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  9. #9
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Jun 2012
    Posts
    350

    Default

    Thanks LM. I will try this also. I am sure it would work. Pretty difficult to understand the last line though.

  10. #10
    Forum Newbie
    Using
    not applicable
    Join Date
    Jan 2010
    Posts
    1

    Default

    Registered forum members do not see this ad.

    give this a try
    Code:
    ;determines the orientation on the basis of pointaxis P1 -> P2
    ;Points in current UCS
    ;example function:
    
    ;(setq
    ;  pt1 (getpoint "\nfirst point: ")
    ;  pt2 (getpoint "\nsecond point: " pt1)
    ;)
    ;(while
    ;  (/= (car (setq pt3 (grread 'T 1 0))) 3)
    ;  (if (leftright-p pt1 pt2 (cadr pt3))
    ;    (princ "\nyou are left: ")
    ;    (princ "\nyou are right: ")
    ;  )
    ;)
    ;returns T=left nil=right
    
    (defun leftright-p
      ( pt1 pt2 pt3 /
        area
      )
      (setq area
        (+
          (- (* (car pt1) (cadr pt2)) (* (cadr pt1) (car pt2)))
          (- (* (cadr pt1) (car pt3)) (* (car pt1) (cadr pt3)))
          (- (* (car pt2) (cadr pt3)) (* (car pt3) (cadr pt2)))
        )
      )
      (and
        (> area 0)
        (not (equal area 0 0.0000001))
      )
    )

Similar Threads

  1. Replies: 63
    Last Post: 27th Jun 2016, 11:35 pm
  2. Lisp to determine position of blocks respect to a reference block
    By sadhu in forum AutoLISP, Visual LISP & DCL
    Replies: 6
    Last Post: 30th Mar 2013, 01:36 am
  3. How to position a sketch plane at the end of a line
    By KarolR in forum Autodesk Inventor
    Replies: 1
    Last Post: 20th Sep 2012, 02:48 pm
  4. Trim to a point or cursor position
    By czyktech in forum AutoCAD Beginners' Area
    Replies: 9
    Last Post: 11th Dec 2008, 01:45 am
  5. The leader line adjusts its position when I place it
    By Siberian in forum AutoCAD General
    Replies: 1
    Last Post: 26th Aug 2008, 10:13 am

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts