Advertisement

Since Sequential Impulse remove constants, How do I use a constraint that has one?

Started by May 04, 2020 01:22 PM
2 comments, last by raigan 4 years, 8 months ago

So I've written a constraint for keeping an object at a fixed distance from a fixed point,you can call circular constraint (it is in 2D), so the math equation for this is : (x-2)^2+(y-2^2)=1,assuming the fixed point coords are (2,2) and the fixed distance is 1,anyway when I differentiate it , it removes the constant which is very important for the constraint , and once I apply it, it assumes that the fixed distance is the distance from my object and the fixed point , here is the solver,I'm using a very basic form since it's a single object in 2D, So how do I solve that out?!

float lambda = -mass*((velocity.x * (2 * centroid.x - 4) + velocity.y * (2 * centroid.y - 4)) / ((2 * centroid.x - 4) * (2 * centroid.x - 4)+(2*centroid.y-4)*(2*centroid.y-4)));
	vec2 deltaVelo;
	deltaVelo.x = (lambda * (2 * centroid.x - 4)) / mass;
	deltaVelo.y = (lambda * (2 * centroid.y - 4)) / mass;
	velocity += deltaVelo;

Hello there, just have a few questions to help me understand your problem. Would you mind elaborating a little further on what “constant” is being removed from your constraint? Are you talking about the fixed coordinate point where your circular boundary is located?

Advertisement

You need “stabilization”, ie you need to solve the constraint on both the position and velocity level, not just velocity. Otherwise you'll get position error/drift. If you google those terms you might find something useful, and/or look at Box2D source code.

The simplest approach is Baumgarte stabilization, which just feeds the position error into the velocity correction.

This topic is closed to new replies.

Advertisement