Hi Monks
I'm writing a Perl program to rotate some Cartesian co-ordinates around an axis (acting as a pivot) but the new cartesian co-ordinates are way out, (* is dot product and x cross product). Its broken down into 2 subroutines, can anyone give any pointers or tell me where I'm going wrong please?!
many thanks in advance
x
sub Axis {
#2 sets of cartesian XYZ co-ordinates on the axis
($Xl1, $Yl1, $Zl1, $Xl2, $Yl2, $Zl2) = @_;
$Axx = $Xl1 - $Xl2;
$Axy = $Yl1 - $Yl2;
$Axz = $Zl1 - $Zl2;
$Vform = V($Axx,$Axy,$Axz);
$eq = sqrt($Axx**2 + $Axy**2 + $Axz**2);
$Unitvector = 1/$eq * $Vform;
return($Vform, $Unitvector);
}
sub rotator {
(*xcord, *ycord, *zcord, *TotalnumberofCoords, $lineUnitvector, $Xline
+coord, $Ylinecoord, $Zlinecoord) = @_;
$angle = 9.4;
$translation = 0.4;
$coefl1 = 1-cos($angle);
$coefl2 = sin($angle);
($LUVx, $LUVy, $LUVz) = &VectorBreakdown($lineUnitvector);
for (my $i = 0; $i < @TotalnumberofCoords; $i++) {
$Xco[$i] = $xcord[$i] - $Xlinecoord;
$Yco[$i] = $ycord[$i] - $Ylinecoord;
$Zco[$i] = $zcord[$i] - $Zlinecoord;
$Vector[$i] = V($Xco[$i], $Yco[$i], $Zco[$i]);
$scal[$i] = $lineUnitvector * $Vector[$i];
$f[$i] = $scal[$i] * ($lineUnitvector - $Vector[$i]);
$f[$i] = $coefl1 * $f[$i];
$s[$i] = $lineUnitvector x $Vector[$i];
$s[$i] = $coefl2 * $s[$i];
($fx[$i], $fy[$i], $fz[$i]) = &VectorBreakdown($f[$i]);
($sx[$i], $sy[$i], $sz[$i]) = &VectorBreakdown($s[$i]);
$xo[$i] = $xcord[$i] + $fx[$i] + $sx[$i] + ($transl * $LUVx);
$yo[$i] = $ycord[$i] + $fy[$i] + $sy[$i] + ($transl * $LUVy);
$zo[$i] = $zcord[$i] + $fz[$i] + $sz[$i] + ($transl * $LUVz);
$xo[$i] = sprintf("%.3f", $xo[$i]);
$yo[$i] = sprintf("%.3f", $yo[$i]);
$zo[$i] = sprintf("%.3f", $zo[$i]);
}
return(\@xo, \@yo, \@zo);
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|