Skip to content

Commit 9fdba91

Browse files
committed
Quaternion::as_matrix normalise to ensure acos in-range
1 parent 0017dd8 commit 9fdba91

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

lib/PDL/Graphics/TriD/Quaternion.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ sub rotate {
134134

135135
sub as_matrix {
136136
my ($this) = @_;
137+
$this->normalise;
137138
my ($rot, $vec) = map PDL->pdl(PDL::float, $_), $this->[0], [@$this[1..3]];
138139
$rot->inplace->acos; $rot *= 2;
139140
$vec->inplace->norm;

t/quaternion.t

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ is_qua $q4, $q1_q2;
6666

6767
my $q_45_about_111 = PDL::Graphics::TriD::Quaternion->new(cos(PI/8),1,1,1);
6868
is_pdl $q_45_about_111->as_matrix, float('
69-
0.804738 -0.310617 0.505879 0;
70-
0.505879 0.804738 -0.310617 0;
71-
-0.310617 0.505879 0.804738 0;
72-
0 0 0 1
69+
-0.038003 0.039506 0.998496 0;
70+
0.998496 -0.038003 0.039506 0;
71+
0.039506 0.998496 -0.038003 0;
72+
0 0 0 1
7373
');
7474

7575
done_testing;

0 commit comments

Comments
 (0)