Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
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); }

In reply to Cartesian co-ordinate rotation around an Axis by fraizerangus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (9)
    As of 2014-09-30 13:33 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (370 votes), past polls