Jump to content
  • Advertisement
Sign in to follow this  
drvannostrand

2D angular constraints in verlet

This topic is 4263 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

I've been trying to get an implementation of 2D angular constraints going in my sim and the one realisation i've come to is, trying to do this can induce a large ulcer and/or brain anurysm. There always seems to be some specific case where extra energy can be introduced depending on, say, the user dragging on one of the 3 particles, or stress being put on the resolved angle. In searching around it seems like there are two strategies, the first being that only two particles are moved -- eg the knee and the ankle, but not the hip. The other strategy is to resolve the angle using p1 and p3 and then reposition everything via a center of mass/center of gravity type of thing. (there is jakobsen's original approach of just using an on and off spring constraint, but as I understand it, that has too many problems) My first general question is: is it a given that an angular constraint will be composed of two component linear constraints? It seems like most implementations don't account for the linear distance of the particles, and have to be handled by the component linear constraints. Another question: Lets say I use the two particle approach. I understand that if I resolve with p1 and p2 then no energy will be put on p3 and p3 can be attached to some other configuration without introducing energy to it. But the movement of p2 will change the length of p1p2 -- assuming that is held in place by a linear constraint -- so wont that then in turn introduce unwanted energy there? It all seems so confusing.

Share this post


Link to post
Share on other sites
Advertisement
This is probably a shot in the dark, but when you move particles to satisfy constaints, are you also modifying the previous position as well?

If not, then you're going to be changing the velocity if the particle and hence its kinetic energy.

Share this post


Link to post
Share on other sites
I'm just moving the current position, but that's how Im doing it for the linear constraints and it works well. It seems like most resolving code never touches the previous position. I'll try playing around with setting both and see what happens.

My goal is angular constraints that:
- properly model varying masses of particles
- properly model leverage of the particles
- are stable when free or connected to other configurations

Share this post


Link to post
Share on other sites
If you're not changing the old position, you're implicitly changing velocity, which may or may not matter to your purposes. Also, if you're trying to model rigid constraints, you should also normalize the velocity on both ends of the bar so that the two pionts aren't trying to pull away or come toward each other.

I can provide specifics if you like.

Share this post


Link to post
Share on other sites
I won't pretend I have all the answers, but this is what I've discovered so far.

First, when you modify the positions of particles to satisfy constraints, you must take into account velocity changes if you are using regular verlet.

For a rigid body constraint (the 2 particles must remain within x distance from each other), you'll want to "normalize" (for lack of a better word) the velocity of both particles so they aren't fighting the constraint. Otherwise you're just going to be making your job alot harder in future frames, and your particles might even behave eratically.

First, let's say that the vector dir = position of particle B - position of particle A. That is, dir is your constraint vector.

You'll want to extract and store the length and normalize this vector.

Then, you need to find the velocity of the particles with respect to the constraint (that is, their velocity component parallel to the constraint).

VelocityA = pos of A - opos of A
VelocityB = pos of B - opos of B

VelocityAParallel = VelocityA dot dir
VelocityBParallel = VelocityB dot dir

Momentum = VelocityAParallel * Mass of A + VelocityBParallel * Mass of B
Constraint's velocity = (Momentum / (Mass of A + Mass of B)) * dir

NewVelocityA = Constraint's velocity - VelocityA
NewVelocityB = Constraint's velocity - VelocityB

Now, perform your constraints.

Then you'll need to change the opos of both particles to reflect the new desired velocity.

oposA = posA - NewVelocityA
oposB = posB - NewVelicityB

That should be it. Like I said above, this is pretty much as far as I ever got before I tried moving on to other problems. Satisfying multiple constraints is alot of work that can get very confusing very fast. Tell me if this was helpful at all.

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!