[system] / trunk / pg / macros / parserVectorUtils.pl Repository:
ViewVC logotype

Annotation of /trunk/pg/macros/parserVectorUtils.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5553 - (view) (download) (as text)

1 : sh002i 5553 =head1 NAME
2 : gage 4997
3 : sh002i 5553 parserVectorUtils.pl - Utility macros that are useful in vector problems.
4 :    
5 : gage 4997 =head1 DESCRIPTION
6 :    
7 : sh002i 5553 Some utility routines that are useful in vector problems
8 : dpvc 2729
9 : gage 4997 =cut
10 :    
11 : dpvc 2729 sub _parserVectorUtils_init {}; # don't reload this file
12 :    
13 : sh002i 5553 =head1 MACROS
14 : gage 4997
15 : sh002i 5553 =head2 Overline
16 : dpvc 2729
17 : sh002i 5553 Overline($vectorName)
18 : gage 4997
19 : sh002i 5553 formats a vector name (should be used in math mode)
20 :    
21 :     Vectors will be in bold italics in HTML modes, and
22 :     will be overlined in TeX modes. (Bold italic could also work in
23 :     TeX modes, but the low resolution on screen made it less easy
24 :     to distinguish the difference between bold and regular letters.)
25 :    
26 : gage 4997 =cut
27 :    
28 : dpvc 2729 sub Overline {
29 :     my $v = shift;
30 :     my $HTML = '<B><I>'.$v.'</B></I>';
31 :     MODES(
32 :     TeX => "\\overline{$v}",
33 :     HTML => $HTML,
34 :     HTML_tth => '\begin{rawhtml}'.$HTML.'\end{rawhtml}',
35 :     HTML_dpng => "\\overline{$v}",
36 :     );
37 :     }
38 :    
39 : sh002i 5553 =head2 BoldMath
40 : gage 4997
41 : sh002i 5553 BoldMath($vectorName)
42 : gage 4997
43 : sh002i 5553 This gets a bold letter in TeX as well as HTML modes.
44 :     Although \boldsymbol{} works fine on screen in latex2html mode,
45 :     the PDF file produces non-bold letters. I haven't been able to
46 :     track this down, so used \mathbf{} in TeX mode, which produces
47 :     roman bold, not math-italic bold.
48 :    
49 : gage 4997 =cut
50 :    
51 : dpvc 2729 sub BoldMath {
52 :     my $v = shift;
53 :     my $HTML = '<B><I>'.$v.'</B></I>';
54 :     MODES(
55 :     TeX => "\\boldsymbol{$v}", # doesn't seem to work in TeX mode
56 :     # TeX => "\\mathbf{$v}", # gives non-italic bold in TeX mode
57 :     Latex2HTML => "\\boldsymbol{$v}",
58 :     HTML => $HTML,
59 :     HTML_tth => '\begin{rawhtml}'.$HTML.'\end{rawhtml}',
60 :     HTML_dpng => "\\boldsymbol{$v}",
61 :     );
62 :     }
63 :    
64 : sh002i 5553 =head2 $GRAD
65 : gage 4997
66 : sh002i 5553 TEXT($GRAD)
67 : dpvc 2729
68 : sh002i 5553 BEGIN_TEXT
69 :     $GRAD
70 :     END_TEXT
71 :    
72 :     Grad symbol.
73 :    
74 : gage 4997 =cut
75 :    
76 : dpvc 5373 $GRAD = '\nabla ';
77 :    
78 : sh002i 5553 =head2 non_zero_point
79 : gage 4997
80 : sh002i 5553 non_zero_point($Dim,$L_bound,$U_bound,$step)
81 : gage 4997
82 : sh002i 5553 Create a non-zero point with the given number of coordinates
83 :     with the given random range (which defaults to (-5,5,1)).
84 :    
85 :     non_zero_point(n,a,b,c)
86 :     non_zero_point_2D(a,b,c)
87 :     non_zero_point_3D(a,b,c)
88 :    
89 :     non_zero_point2D and 3D automatically set Dimension to 2 and 3 respectively.
90 :    
91 : gage 4997 =cut
92 :    
93 : dpvc 2729 sub non_zero_point {
94 :     my $n = shift; my $k = $n; my @v = ();
95 :     my $a = shift || -5; my $b = shift || $a + 10; my $c = shift || 1;
96 :     while ($k--) {push(@v,random($a,$b,$c))}
97 :     if (norm(Point(@v)) == 0) {$v[random(0,$n-1,1)] = non_zero_random($a,$b,$c)}
98 :     return Point(@v);
99 :     }
100 :     sub non_zero_point2D {non_zero_point(2,@_)}
101 :     sub non_zero_point3D {non_zero_point(3,@_)}
102 :    
103 : sh002i 5553 =head2 non_zero_vector, non_zero_vector2D, non_zero_vector3D
104 : gage 4997
105 : sh002i 5553 non_zero_vector($Dim,$L_bound,$U_bound,$step)
106 : gage 4997
107 : sh002i 5553 non_zero_vector2D($L_bound,$U_bound,$step)
108 :    
109 :     non_zero_vector3D($L_bound,$U_bound,$step)
110 :    
111 :     Functions the same as non_zero_point but for Vectors. non_zero_vector2D and
112 :     non_zero_vector3D automatically set Dimension to 2 and 3 respectively.
113 :    
114 : gage 4997 =cut
115 :    
116 : dpvc 5070 sub non_zero_vector {Vector(non_zero_point(@_))}
117 : dpvc 2729 sub non_zero_vector2D {non_zero_vector(2,@_)}
118 :     sub non_zero_vector3D {non_zero_vector(3,@_)}
119 :    
120 : sh002i 5553 =head2 Line
121 : gage 4997
122 : sh002i 5553 $P = Point(@coords1);
123 :     $V = Vector(@coords2);
124 :     $t = 't';
125 :     Line($P,$V);
126 :     Line($P,$V,$t);
127 : gage 4997
128 : sh002i 5553 Form the vector-parametric form for a line given its point and vector, where $P
129 :     is the point and $V the direction vector for the line, and $t is the variable to
130 :     use (default is 't').
131 :    
132 :     For example:
133 :    
134 :     Line([1,-3],[2,1]); # produces Vector("1+2t","-3+t").
135 :     Line(Point(1,-3),Vector(2,1)); # produces Vector("1+2t","-3+t").
136 :    
137 :     (It may be better to use the ParametricLine class from
138 :     parserParametricLine.pl).
139 :    
140 : gage 4997 =cut
141 :    
142 : dpvc 2729 sub Line {
143 :     my @p = Point(shift)->value; my @v = Vector(shift)->value;
144 :     my $t = shift; $t = 't' unless $t; $t = Formula($t);
145 :     my @coords = ();
146 :     die "Dimensions of point and vector don't match" unless $#p == $#v;
147 :     foreach my $i (0..$#p) {push(@coords,($p[$i]+$v[$i]*$t)->reduce)}
148 :     return Vector(@coords);
149 :     }
150 :    
151 : sh002i 5553 =head2 Plane
152 : gage 4997
153 : sh002i 5553 Plane($point,$NormalVector)
154 : gage 4997
155 : sh002i 5553 Creates a displayable string for a plane given its
156 :     normal vector and a point on the plane. (Better to use
157 :     the ImplicitPlane class from parserImplicitPlane.pl).
158 :    
159 : gage 4997 =cut
160 :    
161 : dpvc 2729 sub Plane {
162 : dpvc 2933 my $P = Point(shift); my $N = Vector(shift); my @N = $N->value;
163 : dpvc 2729 my $xyz = shift; $xyz = ['x','y','z'] unless defined($xyz);
164 :     die "Number of variables doesn't match dimension of normal vector"
165 : dpvc 2933 unless scalar(@N) == scalar(@{$xyz});
166 : dpvc 2729 my @terms = ();
167 : dpvc 2933 foreach my $i (0..$#N) {push(@terms,$N[$i]->TeX.$xyz->[$i])}
168 : dpvc 2729 Formula(join(' + ',@terms))->reduce->TeX . " = " . ($N.$P)->TeX;
169 :     }
170 :    
171 :     1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9