Computer Science Canada Triangle Collision Detection |

Author: | hello [ 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??? |

Author: | Tony [ Thu Jun 05, 2003 8:38 pm ] |

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

Author: | hello [ Thu Jun 05, 2003 9:47 pm ] |

Post subject: | |

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

Author: | AsianSensation [ Thu Jun 05, 2003 9:59 pm ] |

Post subject: | |

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

Author: | Tony [ Thu Jun 05, 2003 10:10 pm ] |

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

Author: | Catalyst [ Thu Jun 05, 2003 10:11 pm ] |

Post subject: | |

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

Author: | hello [ Fri Jun 06, 2003 3:02 pm ] |

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

Author: | Tony [ Fri Jun 06, 2003 7:10 pm ] |

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

Author: | bugzpodder [ Fri Jun 06, 2003 8:19 pm ] |

Post subject: | |

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

Author: | Catalyst [ Fri Jun 06, 2003 8:40 pm ] |

Post subject: | |

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

Author: | bugzpodder [ Fri Jun 06, 2003 8:57 pm ] |

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

Author: | Catalyst [ Fri Jun 06, 2003 9:21 pm ] |

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

Author: | SilverSprite [ Sat Jun 07, 2003 7:29 pm ] |

Post subject: | |

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

Author: | PaddyLong [ Sat Jun 07, 2003 7:33 pm ] |

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

: |

You can syndicate this boards posts using the file backend.php or view the topic map using sitemap.php.