[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 2933 - (download) (as text) (annotate)
Tue Oct 19 00:11:50 2004 UTC (15 years, 4 months ago) by dpvc
File size: 3475 byte(s)
Changed the order of variables in calls to Plane() so that it
corresponds to the usage in ImplictPlane().  Also fixed a typo in
capitalization of @N.

    1 #####################################################################
    2 #
    3 #   Some utility routines that are useful in vector problems
    4 #
    5 
    6 sub _parserVectorUtils_init {}; # don't reload this file
    7 
    8 ##################################################
    9 
   10 #
   11 #  formats a vector name (should be used in math mode)
   12 #
   13 #  Vectors will be in bold italics in HTML modes, and
   14 #  will be overlined in TeX modes.  (Bold italic could also work in
   15 #  TeX modes, but the low resolution on screen made it less easy
   16 #  to distinguish the difference between bold and regular letters.)
   17 #
   18 sub Overline {
   19   my $v = shift;
   20   my $HTML = '<B><I>'.$v.'</B></I>';
   21   MODES(
   22     TeX => "\\overline{$v}",
   23     HTML => $HTML,
   24     HTML_tth => '\begin{rawhtml}'.$HTML.'\end{rawhtml}',
   25     HTML_dpng => "\\overline{$v}",
   26   );
   27 }
   28 
   29 #
   30 #  This gets a bold letter in TeX as well as HTML modes.
   31 #  Although \boldsymbol{} works fine on screen in latex2html mode,
   32 #  the PDF file produces non-bold letters.  I haven't been able to
   33 #  track this down, so used \mathbf{} in TeX mode, which produces
   34 #  roman bold, not math-italic bold.
   35 #
   36 sub BoldMath {
   37   my $v = shift;
   38   my $HTML = '<B><I>'.$v.'</B></I>';
   39   MODES(
   40     TeX => "\\boldsymbol{$v}", #  doesn't seem to work in TeX mode
   41 #    TeX => "\\mathbf{$v}",      #  gives non-italic bold in TeX mode
   42     Latex2HTML => "\\boldsymbol{$v}",
   43     HTML => $HTML,
   44     HTML_tth => '\begin{rawhtml}'.$HTML.'\end{rawhtml}',
   45     HTML_dpng => "\\boldsymbol{$v}",
   46   );
   47 }
   48 
   49 #
   50 #  Grad sumbol
   51 #
   52 $GRAD = '\nabla ';
   53 
   54 #
   55 #  Create a non-zero point with the given number of coordinates
   56 #  with the given random range (which defaults to (-5,5,1)).
   57 #
   58 #  non_zero_point(n,a,b,c)
   59 #
   60 sub non_zero_point {
   61   my $n = shift; my $k = $n; my @v = ();
   62   my $a = shift || -5; my $b = shift || $a + 10; my $c = shift || 1;
   63   while ($k--) {push(@v,random($a,$b,$c))}
   64   if (norm(Point(@v)) == 0) {$v[random(0,$n-1,1)] = non_zero_random($a,$b,$c)}
   65   return Point(@v);
   66 }
   67 sub non_zero_point2D {non_zero_point(2,@_)}
   68 sub non_zero_point3D {non_zero_point(3,@_)}
   69 
   70 #
   71 #  Same but for Vectors
   72 #
   73 sub non_zero_vector {Vector(non_zero_point(@_))}
   74 sub non_zero_vector2D {non_zero_vector(2,@_)}
   75 sub non_zero_vector3D {non_zero_vector(3,@_)}
   76 
   77 #
   78 #  Form the vector-parametric form for a line given its point and vector
   79 #
   80 #  Usage:  Line(P,V); or Line(P,V,'t');
   81 #
   82 #  where P is the point and V the direction vector for the line, and
   83 #  t is the variable to use (default is 't').
   84 #
   85 #  Ex:  Line([1,-3],[2,1]) produces Vector("1+2t","-3+t").
   86 #  Ex:  Line(Point(1,-3),Vector(2,1)) produces Vector("1+2t","-3+t").
   87 #
   88 sub Line {
   89   my @p = Point(shift)->value; my @v = Vector(shift)->value;
   90   my $t = shift; $t = 't' unless $t; $t = Formula($t);
   91   my @coords = ();
   92   die "Dimensions of point and vector don't match" unless $#p == $#v;
   93   foreach my $i (0..$#p) {push(@coords,($p[$i]+$v[$i]*$t)->reduce)}
   94   return Vector(@coords);
   95 }
   96 
   97 #
   98 #  Creates a displayable string for a plane given its
   99 #  normal vector and a point on the plane.  (Better to use
  100 #  the ImplicitPlane class from parserImplicitPlane.pl).
  101 #
  102 #  Usage:  Plane(P,N);
  103 #
  104 sub Plane {
  105   my $P = Point(shift); my $N = Vector(shift); my @N = $N->value;
  106   my $xyz = shift; $xyz = ['x','y','z'] unless defined($xyz);
  107   die "Number of variables doesn't match dimension of normal vector"
  108     unless scalar(@N) == scalar(@{$xyz});
  109   my @terms = ();
  110   foreach my $i (0..$#N) {push(@terms,$N[$i]->TeX.$xyz->[$i])}
  111   Formula(join(' + ',@terms))->reduce->TeX . " = " . ($N.$P)->TeX;
  112 }
  113 
  114 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9