[system] / trunk / pg / macros / parserVectorUtils.pl Repository: Repository Listing bbplugincoursesdistsnplrochestersystemwww

# Diff of /trunk/pg/macros/parserVectorUtils.pl

Revision 4997 Revision 5070
75# 75#
76# Create a non-zero point with the given number of coordinates 76# Create a non-zero point with the given number of coordinates
77# with the given random range (which defaults to (-5,5,1)). 77# with the given random range (which defaults to (-5,5,1)).
78# 78#
79# non_zero_point(n,a,b,c) 79# non_zero_point(n,a,b,c)
80# non_zero_point_2D(a,b,c)
81# non_zero_point_3D(a,b,c)
80# 82#
81# non_zero_point2D and 3D automatically set Dimension to 2 and 3 respectively. 83# non_zero_point2D and 3D automatically set Dimension to 2 and 3 respectively.
82# 84#
83 85
84=cut 86=cut
101# non_zero_vector2D and 3D automatically set Dimension to 2 and 3 respectively. 103# non_zero_vector2D and 3D automatically set Dimension to 2 and 3 respectively.
102# 104#
103 105
104=cut 106=cut
105 107
106sub non_zero_vector {Vector(non_zero_point(@_))} 108sub non_zero_vector {Vector(non_zero_point(@_))}
107sub non_zero_vector2D {non_zero_vector(2,@_)} 109sub non_zero_vector2D {non_zero_vector(2,@_)}
108sub non_zero_vector3D {non_zero_vector(3,@_)} 110sub non_zero_vector3D {non_zero_vector(3,@_)}
109 111
111 113
112# 114#
113# Form the vector-parametric form for a line given its point and vector 115# Form the vector-parametric form for a line given its point and vector
114# 116#
115# Usage: Line(P,V); or Line(P,V,'t'); 117# Usage: Line(P,V); or Line(P,V,'t');
117# where P is the point and V the direction vector for the line, and 119# where P is the point and V the direction vector for the line, and
118# t is the variable to use (default is 't'). 120# t is the variable to use (default is 't').
119# 121#
120# Ex: Line([1,-3],[2,1]) produces Vector("1+2t","-3+t"). 122# 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"). 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).
122# 127#
123 128
124=cut 129=cut
125 130
126sub Line { 131sub Line {
130 die "Dimensions of point and vector don't match" unless \$#p == \$#v; 135 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)} 136 foreach my \$i (0..\$#p) {push(@coords,(\$p[\$i]+\$v[\$i]*\$t)->reduce)}
132 return Vector(@coords); 137 return Vector(@coords);
133} 138}
134 139