Moving sphere to triangle collision

Started by
14 comments, last by simotix 13 years, 11 months ago
Granted that I am correct about my elapsed time idea, I have one other problem I want to tackle with this algorithm before I was my hands of it. It deals with having a radius of other than one for the sphere.

In my test case I did a radius of 0.5, a base point of (2.5, 1.0, 0) and a velocity of (0, -0.5, 0), this should cause it to just touch at (2.5, 0, 0), the issue is that I do not report collision or no collision, I just seem to not fall into a case.

I get that my Normal dot Velocitty is -0.5, that is almost obvious. I then have the following to work off of radius

I did this because of the way the documentation explains the collision "If the distance is greater than 1 then we know that a collision cannot ever happen and we can return early from the function." I figured by one they mean that because of their radius being one.

if (fabs(signedDistToTrianglePlane) >= fRadius) 


At this point normal dot velocity would not allow this if to get checked, so that next leads

t0=(-fRadius-signedDistToTrianglePlane)/normalDotVelocity;t1=( fRadius-signedDistToTrianglePlane)/normalDotVelocity;


However, my trail runs cold after that. It was suggested in the other thread that I do

c = squaredLength(p1-base) - (fRadius*fRadius);


However, I am not sure what else should be changed due to the radius? I know that their should be collision, but I am not sure how to have this be based off of the radius unfortunately
Advertisement
Does anyone have any suggestions on how I can incorporate the radius approach I was talking about?
Quote:Original post by simotix
Granted that I am correct about my elapsed time idea, I have one other problem I want to tackle with this algorithm before I was my hands of it. It deals with having a radius of other than one for the sphere.

In my test case I did a radius of 0.5, a base point of (2.5, 1.0, 0) and a velocity of (0, -0.5, 0), this should cause it to just touch at (2.5, 0, 0), the issue is that I do not report collision or no collision, I just seem to not fall into a case.

I get that my Normal dot Velocitty is -0.5, that is almost obvious. I then have the following to work off of radius

I did this because of the way the documentation explains the collision "If the distance is greater than 1 then we know that a collision cannot ever happen and we can return early from the function." I figured by one they mean that because of their radius being one.


Yes, but the time of collision would be 2.0. Is that getting rejected? The comment "distance > 1" probably means, the distance along the path of travel. If you have a distance of 2.0, then it will get rejected, and picked up at another frame.

Quote:
if (fabs(signedDistToTrianglePlane) >= fRadius) 



That code is to check if the sphere is already embedded in the plane. If it is, it's a special case. The time the sphere hits the plane will be zero, and you can use the current sphere position for further checks.

if the sphere is not already embedded with the plane, you can run that code
Quote:
t0=(-fRadius-signedDistToTrianglePlane)/normalDotVelocity;t1=( fRadius-signedDistToTrianglePlane)/normalDotVelocity;



Quote:
However, I am not sure what else should be changed due to the radius? I know that their should be collision, but I am not sure how to have this be based off of the radius unfortunately



taking the collision paper as it is, these are the lines that should be replaced with a radius.

if (fabs(signedDistToTrianglePlane) >= 1.0f) {


replace with

if (fabs(signedDistToTrianglePlane) >= radius) {









else {// N dot D is not 0. Calculate intersection interval:t0=(-1.0-signedDistToTrianglePlane)/normalDotVelocity;t1=( 1.0-signedDistToTrianglePlane)/normalDotVelocity;


replace with

else {// N dot D is not 0. Calculate intersection interval:t0=(-radius-signedDistToTrianglePlane)/normalDotVelocity;t1=( radius-signedDistToTrianglePlane)/normalDotVelocity;






// P1b = 2.0*(velocity.dot(base-p1));c = (p1-base).squaredLength() - 1.0;if (getLowestRoot(a,b,c, t, &newT)) {t = newT;


replace with

// P1b = 2.0*(velocity.dot(base-p1));c = (p1-base).squaredLength() - (radius * radius);if (getLowestRoot(a,b,c, t, &newT)) {t = newT;


and for P2, and P3.


then the edges

// Calculate parameters for equationc = edgeSquaredLength*(1-baseToVertex.squaredLength())+edgeDotBaseToVertex*edgeDotBaseToVertex;


replace with

// Calculate parameters for equationc = edgeSquaredLength*((radius*radius)-baseToVertex.squaredLength())+edgeDotBaseToVertex*edgeDotBaseToVertex;



The algorithm also assumes that the time lapse is in the range [0, 1]. This is where the time comparisons for 't', 't0', 't1', and 'f' with 1's come from.

Everything is better with Metal.

Ah, ok that make sense. Thank you for the help. There is one other false positive that could still happen I believe.

The sphere is at the point of (2.5, 1.0, 0) (base point) about to collide on a triangle with a normal of (0, 1, 0). This will create a planeIntersectionPoint of (2.5, 0.0, 0.0) which will report collision. However, it does not matter what the spheres radius is there. I was wondering what the best approach on dealing this would be? For instance, if my radius was 1.0 that collision would be true, but if it was say 0.2, it would not be.
I'm not I get what you say... This is already accounted for in the top part of the collision function. That's what these code do

if (fabs(signedDistToTrianglePlane) >= fRadius) 


t0=(-fRadius-signedDistToTrianglePlane)/normalDotVelocity;t1=( fRadius-signedDistToTrianglePlane)/normalDotVelocity;


Everything is better with Metal.

Ah, I just confused my self for a second. Everything looks like it is going perfect, thank you for the help

This topic is closed to new replies.

Advertisement