I was wondering if someone could help me. I’m writing a program that has circles that bounce on the screen with air friction, collision friction and gravity all incorporated. I was wondering how would I incorporate triangles into the program and have then bounce off the circles and rotate accordingly as if in the real world.
oooh, that’s a tricky one. My old thinker is drawing a zero on how to do the collision detection, but I suggest you think of the triangles having “weight” at each vertex, and when there’s a collision you apply a force with the appropriate lever arm to the center of the triangle’s mass. Taken physics 1? That’s prolly the only way to make it all seem real.
Hmm… collision… I suppose each line of the triangle can split the screen into two halfspaces. If the ball is at all within the halfspace shared by the triangle, keep on testing. Otherwise, it isn’t colliding.
Test all three halfspaces, if the ball is touching or within all three halfspaces, it may very well be hitting the triangle. Draw the whole thing out on paper… You’ll see there are some error regions, so you’ll have to test for those.
this involves getting into rigid body dynamics. unlike particles, which are just point masses, larger objects have a center of mass. this is the point about which an object will rotate. think if you apply a force to one tip of the triangle. it will start to spin. the point it spins around is the center of mass. also, if the force is applied more towards the center of the triangle, it will spin less and be pushed a little more.
here’s a great link to some siggraph papers that talk about physics and dynamics (from the ground up).
warning: bone up on your calculus, as it’s used heavily in these articles