The following pseudo code works for modelling linear acceleration (applying calculateNextStep
and doNextStep
for each time tick):
class myObject{
vector positionVector
vector velocityVector
vector accelerationVector
vector forceVector
function calculateNextStep(){
resetForceVector()
calculateNetForces()
}
function doNextStep(){
accelerationVector = forceVector.getCopy()
accelerationVector.divideBy(mass)
velocityVector.add(accelerationVector)
positionVector.add(velocityVector)
}
}
My understanding is that for circular motion we need to apply a force orthogonal to the velocity of the object. The size of that force will determine the radius of the circle:
function calculateNextStep() {
resetForceVector()
orthogonalForce = velocityVector.getCopy.getOrthogonalVector()
orthogonalForce.setLength(sizeOfForce)
}
When I apply this approach the object doesn't travel in a circular path. Instead it spirals outwards, increasing in velocity.
I assume this is because the tangential force only applies instantaneously ie. as soon as the object moves the tangential force should change accordingly but I don't know how to account for this in my model.
I assume this has been tackled before but can't find anything. Is there a correction term I should be applying? Something to do with limits / integrals?
This question was based on trying to apply linear mechanics to a problem of angular mechanics!
Circular motion only happens if the force is orthogonal to motion and the direction of motion is turning!
I resolved this by adding angular velocity to the model
class myObject{
vector positionVector
vector velocityVector
vector accelerationVector
vector forceVector
scalar mass
scalar torque
scalar angularAccelleration
scalar angularVelocity
scalar orientation
scalar rotationalInertia
function calculateNextStep(){
resetForceVector()
angularAccelleration = 0
calculateNetForces()
}
function doNextStep(){
accelerationVector = forceVector.getCopy()
accelerationVector.divideBy(mass)
velocityVector.add(accelerationVector)
positionVector.add(velocityVector)
angularAcceleration = torque / rotationalInertia
angularVelocity += angularAccelleration
orientation += angularVelocity
}
}