Question

I'm mostly unfamiliar with vectors, so wondered if I might get some help here.

I'm working a convex hull project in 2d space. The specific function I'm working on needs to determine if a point lies to the left of a line, to the right, or directly on the line.

I've been told to do this using a cross-product. The three points create a triangle in 2d space. Computing the cross product is supposed to give me the area of the triangle. If the area is positive, points p-> q-> r work counter-clockwise, meaning that point r lies to the left of line p-q. Likewise, if the area is negative, points p->q->r work clockwise, and point r lies to the right of line p-q. If the area is 0, r lies on line p-q.

I understand what to do with the end result, I just have no idea what formula I'm supposed to be using.

My problem is that I'm unfamiliar with the cross-product, and the research I've done doesn't clarify how to do this with 3 points. My hunch is that it's the same process as doing it with 2 vectors, but if this is the case, I have no idea how exactly to translate my 3 points into 2 vectors.

Thanks very much!

Was it helpful?

Solution

Your triangle has the sides q-p and r-p, so you have to calculate

(q - p) x (r - p)

where a x b is the determinant

a x b = (a.x * b.y - a.y * b.x)

which is sometimes called "2-dimensional cross product" (see for example http://mathworld.wolfram.com/CrossProduct.html).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top