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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5555 - (download) (as text) (annotate)
Wed Oct 3 19:47:42 2007 UTC (12 years, 4 months ago) by sh002i
File size: 4277 byte(s)
fixed indentation of verbatim paragraphs: now using hard tabs
exclusively. the downside of this is that these get rendered as
eight-column tabs.

    1 =head1 NAME
    2 
    3 parserVectorUtils.pl - Utility macros that are useful in vector problems.
    4 
    5 =head1 DESCRIPTION
    6 
    7 Some utility routines that are useful in vector problems
    8 
    9 =cut
   10 
   11 sub _parserVectorUtils_init {}; # don't reload this file
   12 
   13 =head1 MACROS
   14 
   15 =head2 Overline
   16 
   17   Overline($vectorName)
   18 
   19 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 =cut
   27 
   28 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 =head2 BoldMath
   40 
   41   BoldMath($vectorName)
   42 
   43 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 =cut
   50 
   51 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 =head2 $GRAD
   65 
   66   TEXT($GRAD)
   67 
   68   BEGIN_TEXT
   69   $GRAD
   70   END_TEXT
   71 
   72 Grad symbol.
   73 
   74 =cut
   75 
   76 $GRAD = '\nabla ';
   77 
   78 =head2 non_zero_point
   79 
   80   non_zero_point($Dim,$L_bound,$U_bound,$step)
   81 
   82 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 =cut
   92 
   93 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 =head2 non_zero_vector, non_zero_vector2D, non_zero_vector3D
  104 
  105   non_zero_vector($Dim,$L_bound,$U_bound,$step)
  106 
  107   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 =cut
  115 
  116 sub non_zero_vector   {Vector(non_zero_point(@_))}
  117 sub non_zero_vector2D {non_zero_vector(2,@_)}
  118 sub non_zero_vector3D {non_zero_vector(3,@_)}
  119 
  120 =head2 Line
  121 
  122   $P = Point(@coords1);
  123   $V = Vector(@coords2);
  124   $t = 't';
  125   Line($P,$V);
  126   Line($P,$V,$t);
  127 
  128 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 =cut
  141 
  142 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 =head2 Plane
  152 
  153   Plane($point,$NormalVector)
  154 
  155 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 =cut
  160 
  161 sub Plane {
  162   my $P = Point(shift); my $N = Vector(shift); my @N = $N->value;
  163   my $xyz = shift; $xyz = ['x','y','z'] unless defined($xyz);
  164   die "Number of variables doesn't match dimension of normal vector"
  165     unless scalar(@N) == scalar(@{$xyz});
  166   my @terms = ();
  167   foreach my $i (0..$#N) {push(@terms,$N[$i]->TeX.$xyz->[$i])}
  168   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