verlet with velocity?

BlitzMax Forums/BlitzMax Programming/verlet with velocity?

dXter(Posted 2007) [#1]
I'm trying to adapt a ported version of the FLADE flash verlet physics engine into Blitzmax to fit my needs, and so far it's been pretty good, but now I'm kind of stuck. One of the things I'm trying to change is to include velocity in the engine, instead of having particles store their current and previous velocities and figure the velocity from that. The biggest problem with including velocity is how to resolve constraints. With the current and previous velocities, it is relatively easy, but adding velocity complicates things.

Method resolve() 

	Local delta:Vector = p1.curr.minusNew(p2.curr)
	Local deltaLength# = p1.curr.distance(p2.curr)

	Local diff# = (deltaLength - restLength) / deltaLength
	Local dmd:Vector = delta.mult(diff * stiffness)

	p1.curr.minus(dmd)
	p2.curr.plus(dmd)
End Method



p1 = first particle constrained
p2 = second particle constrained
curr = current position (vector)


I tried to simply replace the last two lines with

        p1.vel.minus(dmd)
        p2.vel.plus(dmd)


But when i ran a test, the particles joined by constraints get all jiggly and get messed up when a collision occurs.

Can verlet constraints be achieved with velocity?


dXter(Posted 2007) [#2]
okay, i kind of got it fixed now... I just set it up to change both particles' position AND velocity, like this:


Method resolve() 

	Local delta:Vector = p1.p.minusNew(p2.p)
	Local deltaLength# = p1.p.distance(p2.p)

	Local diff# = (deltaLength - restLength) / deltaLength
	Local dmd:Vector = delta.mult(diff * stiffness)

	p1.p.minus(dmd)
	p2.p.plus(dmd)
		
	p1.v.minus(dmd)
	p2.v.plus(dmd)
End Method



where p is a particle's position and v is its velocity.

This seemed okay at first, it behaved just like the velocity-less implementation, but there's some kind of problem with collisions with other particles now. Constrained particles like this exert an unpredictable amount of energy on other particles and themselves when they collide, probably because i'm changing the velocity a lot, but i'm not sure. Help, anyone?


Stevie G(Posted 2007) [#3]
dXter,

Each particle should only be moved 1/2 the dmd vector to resolve the constraint in the example above. This may be causing you issues elsewhere.

Stevie


dXter(Posted 2007) [#4]
Stevie, I fiddled around with it for a while and then i realized that the stiffness variable is by default set to 0.5, so i guess the halfing of the distance is already done when dmd is declared. When the stiffness is set lower, it isn't as rigid and feels more wobbly. I haven't figured out how to do constraints with velocity yet, I might just go with the normal verlet implementation if i don't figure it out soon. Is there such thing as collidable constraints in verlet engines? Now that would be pretty cool...


Who was John Galt?(Posted 2007) [#5]
If you want velocity, calculate it from the change in position and store it in a field. The velocity is a result of the relaxation calculation and this is the quickest way to calculate it.