# Thread: Position of point with respect to a line

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

Aloy

2. Hi Aloy,

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

5. Originally Posted by aloy
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. 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. 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)))```

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

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

10. 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
(+
)
)
(and
(> area 0)
(not (equal area 0 0.0000001))
)
)```

#### Posting Permissions

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