File tree Expand file tree Collapse file tree 2 files changed +8
-7
lines changed Expand file tree Collapse file tree 2 files changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -33,15 +33,16 @@ func TestRotationConversions(t *testing.T) {
3333 Rotation (2 * math .Pi , Vec {X : 1 }),
3434 Rotation (0 , Vec {X : 1 }),
3535 }
36- tolroot := math .Sqrt (math .Sqrt (tol ))
36+ maxAngle := 5 * math .Pi / 180
37+ angleTol := math .Cos (maxAngle / 2 )
3738 rng := newRNG (1 )
3839 for _ , rot := range rotations {
3940 angle , axis := rot .Rotation ()
4041 gotrot := Rotation (angle , axis )
4142 if ! EqualQuat (rot , gotrot , tol ) {
4243 t .Errorf ("want %v, got %v" , rot , gotrot )
4344 }
44- if ! rot .EqualOrientation (gotrot , tolroot ) {
45+ if ! rot .EqualOrientation (gotrot , angleTol ) {
4546 t .Errorf ("not equal orientations %v, got %v" , rot , gotrot )
4647 }
4748 m3 := rot .RotationMat3 ()
Original file line number Diff line number Diff line change @@ -120,14 +120,14 @@ func RotationBetweenVecs(start, dest Vec) Quat {
120120}
121121
122122// EqualOrientation returns whether the quaternions represents the same orientation with a given tolerence
123- func (q1 Quat ) EqualOrientation (q2 Quat , tolsq float32 ) bool {
124- // n1sq, n2sq := q1.Dot(q1), q2.Dot(q2 )
125- n1sq , n2sq := q1 . Norm (), q2 .Norm ( )
123+ func (q1 Quat ) EqualOrientation (q2 Quat , tol float32 ) bool {
124+ n1sq := q1 .Dot (q1 )
125+ n2sq := q2 .Dot ( q2 )
126126 if n1sq == 0 || n2sq == 0 {
127127 return false // Degenerate quaternion.
128128 }
129- dot := math . Abs ( q1 .Dot (q2 ) / ( n1sq * n2sq ) )
130- return dot > 1 - tolsq
129+ d := q1 .Dot (q2 )
130+ return d * d >= tol * tol * ( n1sq * n2sq )
131131}
132132
133133/*
You can’t perform that action at this time.
0 commit comments