BetaGamer
BetaGamer

Reputation: 1

Return a Value between 1 & 360

I have a function set to return a Value being used in a Quaternin Rotation. Howver when I have a reslt less than 1 or very close to 360 I recieve a result of -nan(ind). Is there a way to return a conclusive result betwen 1 & 360 to avoid any errors in calculaon. Thanks

const float ReturnAngle() const
{
    return (acosf(angle) * 180.0f * 2) / PI;
}

Update:

These are some results as to wat I receive when checking the value after applying a transformaion rotation to my quatrnion.

angle: 359.598
angle: -nan(ind)
angle: 357.843


angle: -nan(ind)
angle: -nan(ind)
angle: 0.798189
angle: 2.16383
angle: 1.75475
angle: -nan(ind)

Upvotes: 0

Views: 274

Answers (1)

Joni
Joni

Reputation: 111349

The value that you are passing to acosf is outside the allowed range -1 to 1. Review the code that sets the value for angle - perhaps you have a bug there. If it is just a rounding error and angle is outside the allowed range by a small value, "clamping" it to the valid range may be a good solution.

const float ReturnAngle() const
{
    if (angle < -1f) angle = -1f;
    if (angle > +1f) angle = +1f;
    return (acosf(angle) * 180.0f * 2) / PI;
}


Upvotes: 1

Related Questions