[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 6058 - (view) (download) (as text)

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9