blib/lib/Math/synopsis.pl untested

filter: Statementstmt 0.0% 0 / 56 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 60 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/perl
2 #
3 # Direct extraction of the VectorReal POD synopsis
4 #
5 # location of my libraries (I normally set this via PERL5LIB)
6 # # #use lib '/home/anthony/lib/perl5'; # location of my libraries
7 use FindBin;
8 use lib "$FindBin::Bin/blib/lib";
9  
10 use Math::VectorReal qw(:all); # Include O X Y Z axis constant vectors
11  
12 $a = vector( 1, 2, .5 );
13 print "Vector as string (default ouput format)\n\$a => ", $a;
14 print "\n";
15  
16 print "Specified output format\n";
17 print $a->stringify("\$a => { %g, %g, %g }\n");
18 print "\n";
19  
20 # I hate newline in the default output format (defined as MatrixReal)
21 $Math::VectorReal::FORMAT = "[ %.5f %.5f %.5f ]";
22 print "Modified default output format\n\$a => $a\n";
23 print "\n";
24  
25 print "General Vector Mathematics\n";
26 print "length\n", $a->length, "\n";
27 print "normalised\n", $a->norm, "\n";
28 print 'string concat $a."**" = ', $a."**", "\n";
29 print 'vector constant X = ', X, "\n";
30 print 'subtraction $a - Z = ', $a - Z, "\n";
31 print 'scalar divide $a / 3 = ', $a / 3, "\n";
32 print 'dot product $a . Y = ', $a . Y, "\n";
33 print 'cross product $a x Y = ', $a x Y, "\n";
34 print "\n";
35  
36  
37 print "Plane containing points X, \$a, Z (in anti-clockwise order)\n";
38 ($n,$d) = plane( X, $a, Z ); # return normal and disance from O
39 print ' normal = $n = ', $n, "\n";
40 print ' disance from O = $d = ', $d, "\n";
41 print ' Y axis intersect = $d/($n.Y) = ', $d/($n.Y), "\n";
42 print "\n";
43  
44 use Math::MatrixReal; # Not required for pure vector math as above
45  
46 print "Conversions to MatrixReal objects\n";
47 $r = $a->vector2matrix_row; # convert to MatrixReal Row Vector
48 $c = $a->vector2matrix_col; # convert to MatrixReal Column Vector
49 print 'Vector as a MatrixReal Row $r (vector -> matrix) => ', "\n", $r;
50 print 'Vector as a MatrixReal Col $c (vector -> matrix) => ', "\n", $c;
51 print "\n";
52  
53 print "Rotation Matrix from 3 Vectors\n";
54 $nx = $a->norm; $ny = $nx x Z; $nz = $nx x $ny; # orthogonal vectors
55 $R = vector_matrix( $nx, $ny, $nz ); # make the rotation matrix
56 print '$R => ',"\n", $R, "\n";
57  
58 print "Extract the Y row from the matrix as a VectorReal\n";
59 print '$R->matrix_row2vector(1) => ', $R->matrix_row2vector(1), "\n\n";
60  
61 print "Rotate a vector with above rotation matrix\n";
62 print '$a * $R (vector -> vector)',"\n", $a * $R, "\n\n";
63  
64 print "Rotate a MatrixReal column (post multiply)\n";
65 print "(NB: matrix must be transposed (~) to match column format)\n";
66 print '~$R * $c (col_matrix -> col_matrix) =>',"\n", ~$R * $c, "\n";
67