Collision detection and response for cloth

Started by
4 comments, last by juxie 16 years, 1 month ago
Hi, I am currently implementing a cloth simulation using mass-spring system and RK4 integrator. I have been having problems though when colliding with sphere. This is my algorithm: Image Hosted by ImageShack.us Image Hosted by ImageShack.us<br/> What happens is that whenever I drape the cloth onto the sphere, some of the cloth's particle may be stuck in the sphere and not moving. Hopefully someone could help me, please. Thank you.
Advertisement
Sounds like the particle is in just the right position for t to be <=0. You might want to increase the magnitude of the vector used to separate the sphere and the particle. On a cosmetic note, if you write out that quadratic equation you should be able to remove the *2's and *4's.
Yes, the t is just right <= 0.
It is possible to actually increase the magnitude of the separating vector but I may get the effect of the particle jumping on the surface of the sphere.

I check the distance from the new position to centre of sphere and it gives me exactly the radius of the sphere.
I tried the other way by putting the particle onto the surface such as below.

Image Hosted by ImageShack.us

I am wondering how come this works.
Because both ways actually put position back correctly on to the surface of sphere.
While the first way has the particle stuck in the sphere, the second doesn't.
The second way, however, may not work for the other objects.
And it is not actually correct way. It looks correct now because time step is small.

Yes, the t is just right <= 0.
It is possible to actually increase the magnitude of the separating vector but I may get the effect of the particle jumping on the surface of the sphere.

I check the distance from the new position to centre of sphere and it gives me exactly the radius of the sphere.
I tried the other way by putting the particle onto the surface such as below.

Image Hosted by ImageShack.us

I am wondering how come this works.
Because both ways actually put position back correctly on to the surface of sphere.
While the first way has the particle stuck in the sphere, the second doesn't.
The second way, however, may not work for the other objects.
And it is not actually correct way. It looks correct now because time step is small.

Try handling the case where the particle is already in/on the sphere separately from the case where t>0. If floating point numbers didn't have rounding errors you could probably get away without having to perform this check.
Quote:Original post by flounder
Try handling the case where the particle is already in/on the sphere separately from the case where t>0. If floating point numbers didn't have rounding errors you could probably get away without having to perform this check.


I removed the multiplication with 2 and 4 but I got the point colliding far way outside the sphere.

bool CollisionDetector::RaySphereIntersection(const D3DXVECTOR3 &sc, 					  const D3DXVECTOR3 &p1, 							  const D3DXVECTOR3 &p2, 							  float radius, 								  float &time){	D3DXVECTOR3 v, m;		v.x = p2.x - p1.x;	v.y = p2.y - p1.y;	v.z = p2.z - p1.z;	m.x = p1.x - sc.x;	m.y = p1.y - sc.y;	m.z = p1.z - sc.z;		D3DXVec3Normalize(&v, &v);	float b = D3DXVec3Dot(&m, &v);	float c = D3DXVec3Dot(&m, &m) - radius * radius;	if( c > 0.0f && b > 0.0f ) return false;			float d = b * b - c;	if( d < 0.0f ) return false;	float t = (-b - sqrt(d));	if( t >= 0.0f && t <= 1.0f )	{		time = t;		return true;	}	return false;}


What's wrong?

This topic is closed to new replies.

Advertisement