Author 
Message 
hello

Posted: Thu Jun 05, 2003 8:27 pm Post subject: Triangle Collision Detection 


Ok i have rectangle collision detection and circular collision detection
but i need triangle detection somehow any ideas on how???






Sponsor Sponsor



Tony

Posted: Thu Jun 05, 2003 8:38 pm Post subject: (No subject) 


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..

Tony's programming blog. DWITE  a programming contest. 




hello

Posted: Thu Jun 05, 2003 9:47 pm Post subject: (No subject) 


Its a triangle and then a cricle will hit it
so....
its ok i was just wondering






AsianSensation

Posted: Thu Jun 05, 2003 9:59 pm Post subject: (No subject) 


couldn't you just check to see if a vertex of the triangle is inside the circle?






Tony

Posted: Thu Jun 05, 2003 10:10 pm Post subject: (No subject) 


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.

Tony's programming blog. DWITE  a programming contest. 




Catalyst

Posted: Thu Jun 05, 2003 10:11 pm Post subject: (No subject) 


there a way to do it by summing up angle from a point but thats very slow






hello

Posted: Fri Jun 06, 2003 3:02 pm Post subject: (No subject) 


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

Posted: Fri Jun 06, 2003 7:10 pm Post subject: (No subject) 


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

Tony's programming blog. DWITE  a programming contest. 




bugzpodder

Posted: Fri Jun 06, 2003 8:19 pm Post subject: (No subject) 


ahem, tony, the equation of circle you got there is wrong. it is actually:
(xa)^2+(yb)^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

Posted: Fri Jun 06, 2003 8:40 pm Post subject: (No subject) 


the angle summation method checks if a point is inside a polygon
(nothing to do with ovals)






bugzpodder

Posted: Fri Jun 06, 2003 8:57 pm Post subject: (No subject) 


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

Posted: Fri Jun 06, 2003 9:21 pm Post subject: (No subject) 


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

Posted: Sat Jun 07, 2003 7:29 pm Post subject: (No subject) 


Wow you people really go far to make things way more complicated than they have to be..






PaddyLong

Posted: Sat Jun 07, 2003 7:33 pm Post subject: (No subject) 


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






