Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/math/Quaternion.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,19 +533,21 @@ Object.assign( Quaternion.prototype, {

}

var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;

if ( Math.abs( sinHalfTheta ) < 0.001 ) {
if ( sqrSinHalfTheta <= Number.EPSILON ) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Math.abs() is no longer needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no : a square is always non negative !
do you prefer a update of this PR with a call to normalize() or a simply implementing slerp with a subcall to slerpFlat ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If cosHalfTheta = - 1.00001 due to roundoff then sqrSinHalfTheta could be negative.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but that is no longer an issue : negative sqrSinHalfTheta corresponds to cases where the cos is round off errors away from 1 or -1, which corresponds to tiny values of the sin, for which lerp makes sense. (it WAS however an issue as the sqrt was not guarded against negative values and would output NaN values...)


this._w = 0.5 * ( w + this._w );
this._x = 0.5 * ( x + this._x );
this._y = 0.5 * ( y + this._y );
this._z = 0.5 * ( z + this._z );
var s = 1 - t;
this._w = s * w + t * this._w;
this._x = s * x + t * this._x;
this._y = s * y + t * this._y;
this._z = s * z + t * this._z;

return this;

}

var sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
Expand Down