Diff of /lib/Panotools/Matrix.pm [000000] .. [b69cf9]  Maximize  Restore

Switch to unified view

a b/lib/Panotools/Matrix.pm
1
package Panotools::Matrix;
2
3
=head1 NAME
4
5
Panotools::Matrix - Miscellaneous math for panoramic images
6
7
=head1 SYNOPSIS
8
9
$matrix = rollpitchyaw2matrix ($roll, $pitch, $yaw);
10
11
All angles are in radians not degrees.
12
13
=head1 DESCRIPTION
14
15
rollpitchyaw2matrix returns a Math::Matrix object that encapsulates a
16
transformation suitable for rotating a vector/point by three degrees of freedom
17
(roll, pitch and yaw).
18
19
roll is positive rotation around the x-axis
20
21
pitch is negative rotation around the y-axis
22
23
yaw is negative rotation around the z axis
24
25
=head1 USAGE
26
27
use Math::Matrix;
28
29
use Panotools::Matrix;
30
31
my $point  = new Math::Matrix ([$x1], [$y1], [$z1]);
32
33
my $matrix = rollpitchyaw2matrix ($roll, $pitch, $yaw);
34
35
my $result = $matrix->multiply ($point);
36
37
($x2, $y2, $z2) = ($result->[0][0], $result->[1][0], $result->[2][0]);
38
39
=head1 FILES
40
41
Requires Math::Matrix as this is all matrix mathematics.
42
43
=head1 COPYRIGHT
44
45
Copyright (c) 2001 Bruno Postle <bruno@postle.net>. All Rights Reserved. This
46
module is Free Software. It may be used, redistributed and/or modified under
47
the same terms as Perl itself.
48
49
This module is partly based on Math::Geometry by Greg McCarroll
50
<greg@mccarroll.demon.co.uk>
51
52
=cut
53
54
use Math::Matrix;
55
use Math::Trig;
56
use Math::Trig ':radial';
57
use strict;
58
59
use Exporter;
60
use vars qw(@ISA @EXPORT);
61
@ISA = qw(Exporter);
62
@EXPORT = qw(rollpitchyaw2matrix matrix2rollpitchyaw); 
63
64
sub rollpitchyaw2matrix {
65
    my ($roll, $pitch, $yaw) = @_;
66
67
    my $cosr = cos ($roll);
68
    my $sinr = sin ($roll);
69
    my $cosp = cos ($pitch);
70
    my $sinp = sin (0 - $pitch);
71
    my $cosy = cos ($yaw);
72
    my $siny = sin (0 - $yaw);
73
74
    my $rollm  = new Math::Matrix ([        1,       0,       0 ],
75
                                   [        0,   $cosr,-1*$sinr ],
76
                                   [        0,   $sinr,   $cosr ]);
77
78
    my $pitchm = new Math::Matrix ([    $cosp,       0,   $sinp ],
79
                                   [        0,       1,       0 ],
80
                                   [ -1*$sinp,       0,   $cosp ]);
81
82
    my $yawm   = new Math::Matrix ([    $cosy,-1*$siny,       0 ],
83
                                   [    $siny,   $cosy,       0 ],
84
                                   [        0,       0,       1 ]);
85
86
    $yawm->multiply ($pitchm)->multiply ($rollm);
87
}
88
89
# following copied from a spreadsheet by Stuart Milne
90
91
sub matrix2rollpitchyaw
92
{
93
    my $matrix = shift;
94
    my $roll = atan2 ($matrix->[2]->[1], $matrix->[2]->[2]);
95
    my $pitch = -1 * asin (-1 * $matrix->[2]->[0]);
96
    my $yaw = atan2 (-1 * $matrix->[1]->[0], $matrix->[0]->[0]);
97
    return ($roll, $pitch, $yaw);
98
}
99
100
1;
101

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks