Combining then splitting angular and linear velocity

Member
Posts: 320
Joined: 2003.06
Post: #1
Hi

I am trying to give accurate 2D collision response to a box hitting a line mesh. I think I have most of it right, the offsetting of positions is correct, it is the velocities I'm having troubles with. Linear velocity by itself is fine but angular velocity is causing me a bit of grief.

My problem appears to be in the conversion from the separate linear and angular components of the corner of a box to a single linear velocity for the corner, and then back again to separate components after the response velocity vector is calculated. If anyone can see that I'm doing it all wrong, or can see some slight errors please let me know. This must be a fairly common problem?

This is the part of the code that does the velocity stuff:

(I also later add each corner's rotation velocity together to get a combined rotation velocity for the whole quad - could be dodgy too)

Code:
vec2 combinedVelocity = vec2(boxVelocity[VX] - pointOffsetFromCenterOfMass[VY] * boxRotationalVelocity,
                             boxVelocity[VY] + pointOffsetFromCenterOfMass[VX] * boxRotationalVelocity);
                          
vec2 reflectVector = reflect(combinedVelocity, surfaceNormal);
vec2 bounceComponent = reflectVector * surfaceNormal;
vec2 frictionComponent = reflectVector - bounceComponent;
vec2 newVelocity = bounceComponent * bounce + frictionComponent * (1.0f - friction);

float linearVelocityFraction = fabsf(newVelocityNormal.dotProduct(newPositionNormalFromCenterOfMass));
velocityOffsets[i] = newVelocity * linearVelocityFraction - boxVelocity;

vec2 linearVelocityDifference = (newVelocity - velocityOffsets[i]);
vec2 offset = ((quad[i] + newPositionOnLineOffset) - centerOfMass);

if((linearVelocityDifference[VX] * offset[VY] - linearVelocityDifference[VY] * offset[VX]) >= 0)
{
    rotationalVelocityOffsets[i] = -atanf(linearVelocityDifference.length() / offset.length()) - boxRotationalVelocity;
}
else
{
    rotationalVelocityOffsets[i] = atanf(linearVelocityDifference.length() / offset.length()) - boxRotationalVelocity;
}

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #2
First of all, are you using impulses? I don't really recognize any of your equations. Seeing atan() in there has me a bit worried that you're trying something hacky.

To answer your original question: The velocity at any given point on a rigid body is the rotational velocity multiplied by the perpendicular vector to the offset added to the translational velocity.

v_point = v + w*offset_perp

You might find this a good resource: Box2D
I'm really digging his time-stepping algorithm. It has problems compiling under GCC due to some issue with the STL though. OSC might still have the quick fix that would allow you to compile it for evaluation purposes though.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #3
You should probably have a read of this http://www.d6.com/users/checker/pdfs/gdmphys3.pdf
The physics formulas get pretty complicated by it does kinda make sense.. good luck anyway.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #4
unknown Wrote:You should probably have a read of this http://www.d6.com/users/checker/pdfs/gdmphys3.pdf
The physics formulas get pretty complicated by it does kinda make sense.. good luck anyway.

Ah, I had forgotten about Chris Hecker. That's good stuff too.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #5
Thanks for your replies, the links look very useful. I'll let you know how I get on when I sit down and give it another crack this weekend.

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Cutting and Splitting Polygons Maedi 3 6,547 Sep 13, 2011 07:40 AM
Last Post: Skorche
  OpenGL Velocity and Grouping of Lines (C++, Xcode) TheThirdL3g 2 3,119 Jul 29, 2010 01:28 PM
Last Post: SethWillits
  Modelling Tank Velocity Danny77uk 5 5,498 Feb 7, 2008 02:24 AM
Last Post: Danny77uk
  More angular problems Leroy 5 3,082 Jun 24, 2007 02:09 PM
Last Post: Leroy
  Speed distance velocity and other headaches Thinker 6 3,524 Jul 3, 2003 09:55 AM
Last Post: Thinker