I am wondering if someone has an elegant way of calculating the following scenario.
I have an object of (n) number of squares, random shapes, but we will pretend they are all rectangles.
We are dealing with no gravity, so consider the object in space, from a top down perspective. I am applying a force to the object at a specific square (as illustrated below).
How do I calculate the rotational angle, based on the force being applied, at the location being applied. If applied in the center square, it would go straight. How should it behave the further I move from the center? How do I calculate the rotational velocity?
Answer
You're trying to calculate the Torque. Torque depends on the applied force F, the point of application, and the center of mass of the object.
1) Center of Mass. Define the center of mass of the object.
2) Point of Application: Define the point at which the force acts on.
3) Moment Arm: The distance between the two points defined above.
Point centerofMass
Point applicationPoint
Vector momentArm = applicationPoint - centerofMass
4) Angular force: Divide your force F into two orthogonal vectors, one Parallel to the line in 3) and one Perpendicular. The parallel component does not affect angular momentum. The perpendicular one does. You can calculate the parallel component by vector projection. You can subtract that from the original to get the perpendicular component. In pseudocode (dot
means dot-product)
Vector myForce
Vector momentArm
parallelComponent = momentArm * (dot(myForce, momentArm) / dot(momentArm, momentArm))
angularForce = myForce - parallelComponent
5) Torque: The perpendicular component of the force multiplied by the length of the moment arm.
Vector angularForce
Vector torque = angularForce * momentArm.Length
To get from Torque to angular velocity:
1) Moment of Inertia: A definition of how much rotational inertia a given object has. For example, it takes more torque to rotate a long bar than a sphere of the same mass. If you aren't concerned about realism, you can pretend the moment of inertia is relative to the mass, or you could ignore the shape and mass of the object entirely.
2) Angular acceleration:
Vector angularAcceleration = torque / momentOfInertia
3) Angular Velocity: The Angular velocity will keep increasing as long as torque is being applied. So a formula will roughly be "Angular Velocity at time T is the cumulative sum of Angular acceleration up until T." This is expressed in pseudocode as
void Update(float elapsedSeconds):
orientation += 0.5 * angularVelocity * elapsedSeconds;
angularVelocity += angularAcceleration * elapsedSeconds;
orientation += 0.5 * angularVelocity * elapsedSeconds;
No comments:
Post a Comment