<?xml version="1.0" encoding="windows-1252"?>
<node id="919225" title="Cartesian co-ordinate rotation around an Axis" created="2011-08-08 10:16:25" updated="2011-08-08 10:16:25">
<type id="115">
perlquestion</type>
<author id="726752">
fraizerangus</author>
<data>
<field name="doctext">
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

&lt;code&gt;

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);

}

&lt;/code&gt;

&lt;code&gt;

sub rotator {

(*xcord, *ycord, *zcord, *TotalnumberofCoords, $lineUnitvector, $Xlinecoord, $Ylinecoord, $Zlinecoord) = @_;

$angle = 9.4;
$translation = 0.4;

$coefl1 = 1-cos($angle);
$coefl2 = sin($angle);

($LUVx, $LUVy, $LUVz) = &amp;VectorBreakdown($lineUnitvector);

for (my $i = 0; $i &lt; @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]) = &amp;VectorBreakdown($f[$i]);

($sx[$i], $sy[$i], $sz[$i]) = &amp;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);

}

&lt;/code&gt;</field>
</data>
</node>
