Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Triangle Collision Detection
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???

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:
(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

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

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
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 14 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: