jmasterx
jmasterx

Reputation: 54153

Interpolating Radian Angles?

If I'm given a start angle of 1.0f, and an end angle of 6.0f, then what I really want to interpolate is not the 5 in between 1 and 6, but the smaller portion. This will cause counter clockwise interpolation. How can I account of this when interpolating?

Essentially, when given 2 radian angles from 0 to 6.283, how can I know if I should interpolate clockwise or counter clockwise based on which would be "shorter"?

Thanks

Upvotes: 3

Views: 1536

Answers (3)

Robᵩ
Robᵩ

Reputation: 168726

To provide a programming solution to this math problem:

Direction WhichDirection(double start, double finish) {
    return ( std::fmod( (finish - start +2*PI), 2*PI) > PI) ? COUNTER : CLOCK;
}

Upvotes: 0

abelenky
abelenky

Reputation: 64710

The reciprocal of any angle θ is θ-π.

So why not just calculate your θ, and θ-π, and see which one is smaller?

BTW: this seems math related, and not related to programming.

Upvotes: 0

EboMike
EboMike

Reputation: 77752

Get the target angle minus starting angle. If that is greater than PI, go counterclockwise.

Invert the logic if the value is negative.

Upvotes: 7

Related Questions