Movement in a line
On this page we are looking at the situation where the steering wheels are pointing straight ahead. In the next page we will go on to cornering.
Since the car is driving in a straight line, we only need to model its movement in 2 dimensions. In two dimensions there is only one direction of rotation, the orientation of the car can therefore be represented by the angle: theta. (we will model any rocking of the car on its springs separately so it is ignored here).
However, we want to update the position of the car in every frame, to derive this from the angle theta would require the calculation of sin(theta) and cos(theta) in every frame. It is therefore more efficient to store the orientation of the car by a two dimensional vector [dir]. This is a unit length vector which points in the direction of the car, so,
[dir] = [sin(theta), cos(theta)]
This can be represented as a normalised complex number as explained on this page. This will allow rotations to be combined by multiplying complex numbers.
First lets assume that the velocity is constant. Since we are traveling in a straight line we can use the 1 dimensional (scalar) equations of motion and multiply them by the direction vector to give the position in 2 dimensions:
[s] = (s(0)+v(0)*t)[dir]
- [s] = position of centre of mass as a function of time, this is a 2D vector value.
- s(0) = position along the vector at time=0, this is a scalar value.
- v = constant velocity, this is a scalar value.
- t = time, this is a scalar value.
- [dir] = unit direction vector, this is a 2D vector value.
The time t, is the time since the start of the simulation, if the frames of the animation are generated at a constant rate then, we can just increment t by a fixed amount each frame. This will add a fixed 2D vector value to the position each time.
Now lets look at the situation where the car is accelerating or decelerating, it will then follow this equation:
[s] = (s(0)+v(0)*t+ 0.5 a*t2)[dir]
- a = constant acceleration, this is a scalar value.
- v(0) = velocity at time t=0, this is a scalar value.
- other values as above.
So how do we represent the status of the car, in the program, so far? That is, the values that might possibly change in every frame, I think we need to hold the following structure: