I am working on some simulation software, in which I have an entity that is spiralling around a particular point.
As the entity starts spiralling around the point, and the radius of the spiral continues to grow, I want to display the number of circuits that the entity has completed to the user (completion of a circuit is defined as the location/ time at which the entity reaches the same angle from the origin that it was at when it started spiralling). I also want to display to the user, the distance from the aircraft's current location to the point at which it will complete the current circuit.
I am doing this using the following section of code:
if (m_OVF_TURN_DIR == TURN_LEFT)
{
arcAngle = 360 - (NormalAngle360(NormalAngle360(ldFAZ_CentrePos_AC) + NormalAngle360(m_circuitStartAngle)));
m_SteerData.DistanceToGo = (arcAngle * PI * m_currentRadius);
}
else
{
arcAngle = 360 - (NormalAngle360(NormalAngle360(m_circuitStartAngle) + NormalAngle360(ldFAZ_CentrePos_AC)));
m_SteerData.DistanceToGo = ((arcAngle * PI * m_currentRadius) / 180.0); // Nm
}
In this code, the lines:
m_SteerData.DistanceToGo = (arcAngle * PI * m_currentRadius);
and
m_SteerData.DistanceToGo = ((arcAngle * PI * m_currentRadius) / 180.0);
are what is calculating the distance from the aircraft's current location to the point at which it will complete a circuit.
The first block is used to calculate the distance when the entity is spiralling in an anti-clockwise direction, and the second block is used when the entity is spiralling in a clockwise direction.
The clockwise direction seems to be working correctly- it displays a number for the distance to go, and this number decreases steadily as the entity follows the path of the spiral. However, the anti-clockwise direction seems to start at a random number, and then increase steadily as the entity follows the path of the spiral... rather than decrease as it should (because the entity is moving closer to the point at which the circuit will be completed).
This suggests to me that I am using an incorrect symbol somewhere in this block (+, -, * or /), but I can't seem to figure out where... Can anyone point me in the right direction?
I found the issue- it was an incorrect symbol (or a symbol that I had left out, rather than using an incorrect one). I was able to resolve this by changing the code in the
ifpart of the statement to:Using
-NormalAngle360(...)in the innermost bracket resolved the problem.