
-----------------------------------
hello
Thu Jun 05, 2003 8:27 pm

Triangle Collision Detection
-----------------------------------
Ok i have rectangle collision detection and circular collision detection 
but i need triangle detection somehow any ideas on how???

-----------------------------------
Tony
Thu Jun 05, 2003 8:38 pm


-----------------------------------
I'm thinking... check if a vertex of one triangle is between the vertices of other :? Not too sure of how to code that though..

-----------------------------------
hello
Thu Jun 05, 2003 9:47 pm


-----------------------------------
Its a triangle and then a cricle will hit it
so....
its ok i was just wondering

-----------------------------------
AsianSensation
Thu Jun 05, 2003 9:59 pm


-----------------------------------
couldn't you just check to see if a vertex of the triangle is inside the circle?

-----------------------------------
Tony
Thu Jun 05, 2003 10:10 pm


-----------------------------------
yeah.... using the oval collision detection assuming each of triangle's verticies to be an oval with radius of 0. You have to check all three thow.

-----------------------------------
Catalyst
Thu Jun 05, 2003 10:11 pm


-----------------------------------
there a way to do it by summing up angle from a point but thats very slow

-----------------------------------
hello
Fri Jun 06, 2003 3:02 pm


-----------------------------------
But that will only check if the oval has hit the vertices of the triangle 
wat if it hit the side of the triangle

-----------------------------------
Tony
Fri Jun 06, 2003 7:10 pm


-----------------------------------
oh, thats tricky, but I just figured the way to do it.

equation for the line is y = mx + b, equation for the circle is  x^2 + y^2 = radius

take what you know and try to solve both equations for X and Y. If solutions are real numbers, then that line intersects the circle at those points. If both answers are not real values (your program will probably crash unless you protect it) then no collision occured  :D

-----------------------------------
bugzpodder
Fri Jun 06, 2003 8:19 pm


-----------------------------------
ahem, tony, the equation of circle you got there is wrong.  it is actually:
(x-a)^2+(y-b)^2=r^2 where (a,b) is the center of the circle.  after you found the point of intersection x1 and x2, since you are working with line segments (sides of triangle are formed by line segments, not lines) you must further check if x1 and/or x2 is within the domain of hte line segment.  also if the line is vertical, m would be infinity, which causes problems.  so the best equation to use is Ax+By+C=0.  try not to divide by A and/or B cuz one of them might be 0 or you can just do seperate cases if they are 0.

-----------------------------------
Catalyst
Fri Jun 06, 2003 8:40 pm


-----------------------------------
the angle summation method checks if a point is inside a polygon
(nothing to do with ovals)

-----------------------------------
bugzpodder
Fri Jun 06, 2003 8:57 pm


-----------------------------------
i know a method to do the same thing but it has nothing to do with summing up angels.  plz elaborate your method, Catalyst.

-----------------------------------
Catalyst
Fri Jun 06, 2003 9:21 pm


-----------------------------------
you take the cross and dot products from the vector (between the point and the polygon vertex) then you divide (this gives the tangent)
after summing all this up a number close to 0 means it is outside the polygon

-----------------------------------
SilverSprite
Sat Jun 07, 2003 7:29 pm


-----------------------------------
Wow you people really go far to make things way more complicated than they have to be..

-----------------------------------
PaddyLong
Sat Jun 07, 2003 7:33 pm


-----------------------------------
nah.. I think it'd be easier to have one set of calculations that'll work every time, rather than a few messy if statements, that might mess up once in a while
