You could check each line's equation, checking whether the point is in the correct relation of each of the three lines. I'd bet there's a more efficient way, though.
The time you enjoy wasting is not wasted time. Bertrand Russell
Actually, I meant check the inequality of each line against the point. Something like this:
(viewed with picture)
For x = y, the point must be below the line. Therefore, the inequality x >= y must hold true. For x = 1, it must be to the right of the line. Therefore, the inequality of x <= 1 must hold true. With the line y = 0, the point must be above the line. Therefore, the inequality y >= 0 must hold true.
Plugging it all in, 0.5 >= 0.25; 0.5 <= 1; 0.25 >= 0. They are all true and the point is then on the line.
Like I said, it's inefficient and difficult to implement. I'd bet there is another way involving angles or the length of line segments.
The time you enjoy wasting is not wasted time. Bertrand Russell
ABX is a clockwise turn OR
BCX is a clockwise turn OR
CAX is a clockwise turn
a point X is inside of a triangle ABC if
Code:
B
/X\
C A
ABX is a counter clockwise turn AND
BCX is a counter clockwise turn AND
CAX is a counter clockwise turn
You can determine clockwise/counterclockwise by taking the determinant:
if ( (Determinant(A.x, A.y, B.x, B.y, X.x, X.y) == CW) ||
(Determinant(B.x, B.y, C.x, C.y, X.x, X.y) == CW) ||
(Determinant(C.x, C.y, A.x, A.y, X.x, X.y) == CW))
{
Point X is outside
}
else
{
Point X is inside
}
Last edited by sunburnt; Mar 31st, 2004 at 12:57 AM.
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
I should mention that you need to have the verteces of the triangle in Counter Clockwise order for this to work!
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
I've got one problem though...
When porting it to c code, the functions seem to always return true. You seem to know some c, so i ask you here. What's wrong with this code?