[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 5070 - (download) (as text) (annotate)
Thu Jun 28 22:49:38 2007 UTC (12 years, 6 months ago) by dpvc
File size: 4175 byte(s)
Fixed up some comments and spacing.

    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 $GRAD = '\nabla ';
   70 
   71 =cut
   72 
   73 =head3 non_zero_point($Dim,$L_bound,$U_bound,$step)
   74 
   75 #
   76 #  Create a non-zero point with the given number of coordinates
   77 #  with the given random range (which defaults to (-5,5,1)).
   78 #
   79 #  non_zero_point(n,a,b,c)
   80 #  non_zero_point_2D(a,b,c)
   81 #  non_zero_point_3D(a,b,c)
   82 #
   83 #  non_zero_point2D and 3D automatically set Dimension to 2 and 3 respectively.
   84 #
   85 
   86 =cut
   87 
   88 sub non_zero_point {
   89   my $n = shift; my $k = $n; my @v = ();
   90   my $a = shift || -5; my $b = shift || $a + 10; my $c = shift || 1;
   91   while ($k--) {push(@v,random($a,$b,$c))}
   92   if (norm(Point(@v)) == 0) {$v[random(0,$n-1,1)] = non_zero_random($a,$b,$c)}
   93   return Point(@v);
   94 }
   95 sub non_zero_point2D {non_zero_point(2,@_)}
   96 sub non_zero_point3D {non_zero_point(3,@_)}
   97 
   98 =head3 non_zero_vector($Dim,$L_bound,$U_bound,$step)
   99 
  100 #
  101 #  Functions the same as non_zero_point but for Vectors
  102 #
  103 #  non_zero_vector2D and 3D automatically set Dimension to 2 and 3 respectively.
  104 #
  105 
  106 =cut
  107 
  108 sub non_zero_vector   {Vector(non_zero_point(@_))}
  109 sub non_zero_vector2D {non_zero_vector(2,@_)}
  110 sub non_zero_vector3D {non_zero_vector(3,@_)}
  111 
  112 =head3 Line(Point(@coords1),Vector(@coords2),'variableLetter')
  113 
  114 #
  115 #  Form the vector-parametric form for a line given its point and vector
  116 #
  117 #  Usage:  Line(P,V); or Line(P,V,'t');
  118 #
  119 #  where P is the point and V the direction vector for the line, and
  120 #  t is the variable to use (default is 't').
  121 #
  122 #  Ex:  Line([1,-3],[2,1]) produces Vector("1+2t","-3+t").
  123 #  Ex:  Line(Point(1,-3),Vector(2,1)) produces Vector("1+2t","-3+t").
  124 #
  125 #  (It may be better to use the ParametricLine class from
  126 #  parserParametricLine.pl).
  127 #
  128 
  129 =cut
  130 
  131 sub Line {
  132   my @p = Point(shift)->value; my @v = Vector(shift)->value;
  133   my $t = shift; $t = 't' unless $t; $t = Formula($t);
  134   my @coords = ();
  135   die "Dimensions of point and vector don't match" unless $#p == $#v;
  136   foreach my $i (0..$#p) {push(@coords,($p[$i]+$v[$i]*$t)->reduce)}
  137   return Vector(@coords);
  138 }
  139 
  140 =head3 Plane($point,$NormalVector)
  141 
  142 #
  143 #  Creates a displayable string for a plane given its
  144 #  normal vector and a point on the plane.  (Better to use
  145 #  the ImplicitPlane class from parserImplicitPlane.pl).
  146 #
  147 #  Usage:  Plane(P,N);
  148 #
  149 
  150 =cut
  151 
  152 sub Plane {
  153   my $P = Point(shift); my $N = Vector(shift); my @N = $N->value;
  154   my $xyz = shift; $xyz = ['x','y','z'] unless defined($xyz);
  155   die "Number of variables doesn't match dimension of normal vector"
  156     unless scalar(@N) == scalar(@{$xyz});
  157   my @terms = ();
  158   foreach my $i (0..$#N) {push(@terms,$N[$i]->TeX.$xyz->[$i])}
  159   Formula(join(' + ',@terms))->reduce->TeX . " = " . ($N.$P)->TeX;
  160 }
  161 
  162 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9