Angle A is a degree angle that keeps increasing by increments and Angle B is the stopping point of Angle A (think 'Spin-the-bottle' where Angle A is the current angle of the bottle Angle B is the angle needed to point to your crush and the bottle spins at a fixed rate clock-wise).
To do this, I've been trying to compare Angle A and Angle B with inequalities. If Angle A is 60 degrees and Angle B is 80 degrees, this is no problem. If Angle A is 350 degrees and Angle B is 10 degrees however, the inequality thinks that Angle A has crossed Angle B even though it hasn't.
How do I compare angles when they wraparound at 360 degrees?
This is some pseudo-code for what I have so far:
int AngleB = 30;
int AngleA = 300;
void Update() {
AngleA += 13;
if (AngleA > AngleB) {
AngleA = AngleB;
}
}
Update: Here's my new method that wraps Angle A relative to Angle B:
double GetAngleDifference(double from, double to)
{
double difference = to - from;
while (difference < -180) double += 360;
while (difference > 180) double-= 360;
return difference;
}