Jump to content
  • Advertisement
Sign in to follow this  

Sphere Polygon Collision

This topic is 2571 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Just implementing some sphere vs triangle collision detection (static at the moment) and its a very long winded process.

So had a thought...

Once the sphere has been projected onto the plane and an intersection is confirmed can you then do this...

project the sphere orthographically from 3 view points (front, left, and top relative to the plane) and then do 3 simple 2d line vs sphere intersections... (assuming one can get the projected radius easily,,, not sure how to do that but sure its possible, maybe someone can tell me)

Am sure it would work to confirm a collision or not and would work like SAT in terms of any separation would confirm no intersection.

If this much works do you think you can also generate a response.. or would that still need to be done the old fashioned way?

Just a though? What you guys think? possible? faster? slower?

:P cheers

Share this post

Link to post
Share on other sites
I'm tired, but here's my take on it (and I have no experience with the field, and failed my last calculus class, so keep that in mind)

It sounds like you have an arbitrary 3 sided face oriented in 3 dimensions (ie three points, which conveniently define a plane) and a sphere somewhere, and you want to find out if the sphere intersects with this triangle. If that's not the case, skip the rest of this and clarify what you mean (a sphere is a 3 dimensional object, a triangle is 2 dimensional, and as such, any interaction between the two is a little awkward)

It seems to me like if you wanted to do this, you could just use <insert proper forumula> to calculate the normal vector to the sphere from the plane defined by the three vertices of the triangle. If the length of this vector is greater than the radius of the sphere, no collision is possible.

Once you have ruled out those cases, there are a number of things left to do, depending on how much optimization you want to do. The first thing that comes to mind is to project the center of the sphere onto that plane defined by the vertices and see if it is within radius distance to any of the three points, but at this point we still do not have a definite positive, because if the center of the sphere is not coplanar with the three points, the actual radius you are concerned with will be smaller.

A quick brainstorm tells me it shouldn't be too difficult to use the result from the first calculation (how far the sphere is from the plane) to determine the proper radius to be used in the second calculation. I don't know it off of the top of my head (and it is up to you to discover it) but a casual contemplation of the subject tells me that if d is the distance to the plane from the center of the sphere, and r is the radius of said sphere, as d starts at zero and approaches r, r', the radius of the circle formed by the intersection of the plane and the surface of the sphere, starts at r and approaches zero(when the sphere is precisely r distance from the plane, it intersects it at precisely one point, which has an area of zero). This function should decrease slowly at first and accelerate more rapidly as you get towards the end, leading me to believe it is logarithmic or exponentially related. Once you have r' and the vector from the first calculation, the problem is just finding out if a circle of radius r' at that location contains any of the three vertices, OR if the center of the circle is contained within the triangle defined by the three vertices (the second part is necessary if the circle exists entirely inside the triangle but never contains a vertex).

To summarize, the calculations necessary are:
1. Find the equation of a plane from 3 points(triangle vertices)
2. Find the vector from a point(center of sphere) to a plane
(if the length of previous vector, v, is greater than the radius, r of the sphere)
3. use the magic function to discover the radius r' of the circle created by cutting a plane through a sphere of radius r at a right angle to its radius |v| distance from the center
4. check if this circle on the plane from step 1 contains or is itself contained by the vertices of the triangle (2d math here, we're operating on their plane now)

Upon looking over that, it seems like there ought to be a simpler way, but I am certain the 'magic function' i humorously allude to in step 3 actually exists, and altogether this entire process should not take that much time computationally (though I hope you are a bamf with point projections onto an arbitrary plane)

Good luck!

EDIT: LOL that magic function is the pythagorean theorem, apparently. SOURCE: http://anse.rs/isYAf0

Share this post

Link to post
Share on other sites
wow thanks for the extensive reply!!!

more content to get through than on some technical papers!

will deffo give that a whirl and see if I can get it to work! thanks again for the time.
steps 1 and 2 are in place so its just the elusive 3 and 4!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!