How to determine whether a line is at the clockwise side of another line?

904 Views Asked by At

This is my first post in math-overflow , I am trying to implement an algorithm where , i am given 2 lines , two lines have one point in common , i need to determine if one line is at the clockwise side of another line ? My points are in 2D.

Let , p is a point not actually in any of the x-axis or y-axis . There is ray(Line) from pw3 Now I need to determine The edges incident to w3 => w3w1 and w2w3 , are they in the clockwise or anticlockwise side of the Ray ? Like in this scenario both the edges are at anti clockwise direction to pw3 Scenario 1

But in scenario 2, when the Ray is passing through pw2, edge w2w3 is at clockwise direction whereas w1w2 is at anti-clockwise direction Scenario 2

How to possibly determine this ?

2

There are 2 best solutions below

0
On BEST ANSWER

For points $P$, $A$ and $B$ in the $xy$ plane, the sign of the $z$ component of the 3-dimensional cross product of $\vec{PA} \times \vec{PB}$ is positive (negative) if $B$ is on the left-hand side (right-hand side) of the ray from $P$ towards $A$, and zero if $B$ is exactly on the line $PA$. See e.g. the illustrations in the Wikipedia page Cross product. You can use this to determine on which side the endpoints of the line segments, and thus the line segment, are.

0
On

Suppose that the equation of the red line is Ax + By + C = 0.

Let f(x, y) = Ax + By + C

Use some known point as reference. (Usually that point is (0, 0) when C is not zero.)

Note the sign of f(0, 0).

Suppose that W1 = (p, q).

If the sign of f(p, q) is the same as that of f(0, 0), then they are on the same side of the red line. (And of course on different sides when otherwise.)