[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 4997 - (download) (as text) (annotate)
Mon Jun 11 18:16:40 2007 UTC (12 years, 8 months ago) by gage
File size: 4025 byte(s)
Fixing docementation so that it can be read from the web.

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9