Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Doing rigid body rotations in Perl

by mwah (Hermit)
on Oct 03, 2007 at 19:46 UTC ( [id://642485]=perlquestion: print w/replies, xml ) Need Help??

mwah has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

lately I stumbled over my old c++ code
for fast rigid body rotations using
a rotational matrix formalism /1,2/.
Because I needed a snippet to be ready
fast, I rewrote the stuff in plain Perl
without doing a deep investigation into
CPAN first.

After having completed the task, I
started to lookaround there but couldn't
find anything appropriate which does
somehow what I needed.

Simple example - say we have a 3D rigid body
template consisting of 5 coordinates (+ labels):
my @tmpl = ( [0,0,0, 'A'], [1,0,0, 'B'], [2,0,0, 'B'], [3,0,0, 'B'], [4,0,0, 'B'], [5,0,0, 'A'] );
Say we need to construct an ensemble
of copies of rigid bodies by applying random
translations and rotations around ar-
bitary axes on the template,
like (pseudocode):
... my $axis = [ 0, 0, 1 ]; # may be arbitary axis, always normalized my @ensemble; for my $id (0 .. 999) { my $angle = deg2rad(rand(360)); # rotate around arbitary # axis by .. degrees # make rotation matrix my $m = setrotmatrix($angle, $axis); # make new rigid body instance from template my $p = deepcopy_body( \@tmpl ); # apply rotation (matrix x vector) to rigid body rotate_body( $p, $m ); # apply some translation by a displacemnent vector translate_body( $p, [$dx, $dy, $dz)] ); # store the new body coordinates push @ensemble, $p; } ...
The above code should make my intention clear
before I start to work out a module + XS
matrix operations, which modules should I
have considered before?

Regards & thanks

mwa



/1/ - Ha,C. and Radcliffe,C.W. (1978) Kinematics
       and Mechanism Design. Wiley, New York, 45.
/2/ - http://peds.oxfordjournals.org/cgi/reprint/16/10/717

Replies are listed 'Best First'.
Re: Doing rigid body rotations in Perl
by moklevat (Priest) on Oct 03, 2007 at 20:03 UTC
    Hi mwah,

    What I think you want is PDL. You can certainly do arbitrary matrix manipulation with it, and it is quite fast and memory efficient for most tasks I have encountered.

Re: Doing rigid body rotations in Perl
by zentara (Archbishop) on Oct 04, 2007 at 13:49 UTC
    If you want a little head start into PDL's 3d visualization tool, look at PDL 3d image cube Of course this is mouse controlled rotation, I havn't tried automatic matrix rotations, but that would be cool.

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://642485]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-25 17:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found