Skip to main content
gamedev.net
🔒 Locked

TriangleIntersection using vectors (2D)

Started by VanKurt Dec 6, 2001 at 6:34 AM 1 replies 700+ views
Original Post
VanKurt
VanKurt
I''m really getting CRAZY. I''ve been working on this 2D problem for about one month now, and IT DOES NOT WORK ! Perhaps you have some ideas..... I have two "triangles" which are defined by two vectors: Va1 + Va2 and Vb1 + Vb2. And I have two angles, that tell me how the "triangles" are turned: Angle1 and Angle2. My problem is now how I can figure out if the triangles intersect. I tried something like building the cross product of two vectors and checking if it is + or -, but that didn''t really work....... Do you have an idea ? tx,Kurty
JOL
JOL
There is a good tut in the resources section of this site -
you find it here
Game Programming/Collision Detection/Crashing into the new year.......

I''ll try to explain what I remember - I HOPE THIS IS CORRECT, I''m not a math wiz

there is a simple way to do this using the Dot product.
using the dot product you can find out what side of a line a point is.
You can iterate through the endpoints of triangle A and all lines of triangle B , checking if the dot(point A, line Bnormal) has the same SIGN, if they do the point is inside the triangle.

this is how you do it...
you have vector AC - the line segment from A to C - the vector B which is a point you''d like to check if it is inside the triangle containing AC. You then do this...

Translate all three vectors by A giving two new vectors that origins in A = 0,0. You do this by subtracting A from AC and B.

V1 = AC - A
V2 = B - A

we let V1 become the Normal to V1 - (turn it 90 degress counterclockwise )

temp = V1.x
V1.x = -V1.y
V1.y = temp

now take the dot of the two vectors.

value = Dot(V1, V2)

now iterate through the rest of the vertices of the triangle with this procedure - if in all these iterations you have the same SIGN on value(+ or -) the point is inside the triangle otherwise it is outside...
check if all points of triangle A is inside OR outside triangle B to find out if the lines intersect...


hope it helps
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~I'm looking for work
VanKurt
VanKurt
Well, thanks ! I''ll try that :-) ...........

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.