Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cavewhere thinks 1° and 359° are 358° apart, rather than 2° (when backsight is marked corrected) #195

Open
jedwards1211 opened this issue Oct 19, 2020 · 0 comments

Comments

@jedwards1211
Copy link
Contributor

jedwards1211 commented Oct 19, 2020

image

Here are some angle functions I use. The fmod can be omitted if you don't expect the inputs to be outside the range [0, 360].

// returns rotation in the range [-180, 180] such that from + rotation = to (mod 360)
float rotationBetween(float from, float to) {
  float raw = fmod((to - from), 360f);
  return raw < -180f
    ? raw + 360f
    : raw > 180f
    ? raw - 360f
    : raw;
}

// more efficient version of fabs(rotationBetween(a, b))
// returns absolute difference in the range [0, 180]
float absAngleDifference(float a, float b) {
  float raw = fmod(fabs(a - b), 360f);
  return raw > 180f ? 360f - raw : raw;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant