🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Swept sphere triangle intersection

Started by
13 comments, last by taby 5 years, 3 months ago

You have the original triangle, the original position of the sphere and a vector that describes how much the sphere is moving in one frame. Now flip the sign of that vector and imagine it's the triangle moving instead. It should be clear that a collision happens in one situation if and only if it happens in the other situation.

Now, the set of points that are part of the triangle at some time in the frame is a triangular prism, obtained by adding the vector to each of the vertices. So you have the original triangle, the displaced triangle, and three quadrilateral faces that make the walls of the prism.

It's not true that the ball only collides if it changes courts. At least not if you just check what court the center is on. The ball can collide against the net when the center of the ball is less than a radius away from the plane of the net. This may or may nor matter for your project, however.

Advertisement

Thank you again!

Yeah, in my code, if the ball clips the net, it bounces back. If it is desirable to not reflect the velocity vector in this case, then a solution can be made via code, or via alteration of the geometry of the net -- currently we use a regulation net that is taut, 3.5 feet at the sides, and 3 feet in the middle. I can also make the ball radius smaller and smaller to the point where it's almost a point object. That way if it clips the net, the velocity vector will not be reflected. It's whatever the project manager wants, basically, which is fine by me. In the end we may come up with a better system, or something. I'm learning as I'm going here. :)

P.S. The C++ code is in the public domain: https://github.com/sjhalayka/tennis

Alvaro can probably see the proceed_symplectic_4 function that I stole from him LOL.

One can also try out the rectangular net geometry (two triangles), and the saggy net geometry (like, 20 triangles or so).

OK, so it would have eaten my soul if I didn't get around to it, which is why the code now handles the cases where the ball clips the net. :)

court-4.thumb.png.9cc453d55f1fe99ba1fb41f80d1b7683.png

This topic is closed to new replies.

Advertisement