[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 5373 - (download) (as text) (annotate)
Sun Aug 19 02:01:57 2007 UTC (12 years, 3 months ago) by dpvc
File size: 4235 byte(s)
Normalized comments and headers to that they will format their POD
documentation properly.  (I know that the POD processing was supposed
to strip off the initial #, but that doesn't seem to happen, so I've
added a space throughout.)

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9