Hello,
What is the method to calculate the direction of rotation of a vector ? I'm trying to calculate the angular velocity from starting from a linear velocity, but the result is always positive. Here's my code (my source is here) :
I want to apply an identical angular velocity to the object2 regardless of the distance of the point where the force is applied.
What is the method to calculate the direction of rotation of a vector ? I'm trying to calculate the angular velocity from starting from a linear velocity, but the result is always positive. Here's my code (my source is here) :
Code:
// the center of the body2 is the origin
var distance:b2Vec2 = new b2Vec2( body1.GetPosition( ).x, body1.GetPosition( ).y );
distance.Subtract( body2.GetPosition( ) );
var velocity:b2Vec2 = new b2Vec2(body1.GetLinearVelocity( ).x, body1.GetLinearVelocity( ).y);
velocity.Normalize( );
var angle:Number = velocity.AngleTo( distance );
var angleVel:Number = Math.sin( angle ) * velocity.Length( ) / 1; // radius = 1
body2.SetAngularVelocity( angleVel );
var distance:b2Vec2 = new b2Vec2( body1.GetPosition( ).x, body1.GetPosition( ).y );
distance.Subtract( body2.GetPosition( ) );
var velocity:b2Vec2 = new b2Vec2(body1.GetLinearVelocity( ).x, body1.GetLinearVelocity( ).y);
velocity.Normalize( );
var angle:Number = velocity.AngleTo( distance );
var angleVel:Number = Math.sin( angle ) * velocity.Length( ) / 1; // radius = 1
body2.SetAngularVelocity( angleVel );
I want to apply an identical angular velocity to the object2 regardless of the distance of the point where the force is applied.