in reply to Re: Rotate a 3D vector
in thread Rotate a 3D vector
If you only need to rotate around the Z axis then it is a simple 2D trig problem. The z co-ordinate is invariant as this is our rotational plane.
sub rotate { my ( $x,$y,$z,$angle ) = @_; $angle = deg2rad($angle); my $x_new = cos($angle)*$x - sin($angle)*$y; my $y_new = sin($angle)*$x + cos($angle)*$y; return $x_new, $y_new, $z; } sub deg2rad { return 3.14159265358979*$_[0]/180 };
Here is a nice article with a pretty applet Update Corrected error noted by johnnywang
cheers
tachyon
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Rotate a 3D vector
by true (Pilgrim) on Oct 18, 2004 at 01:33 UTC | |
Re^3: Rotate a 3D vector
by johnnywang (Priest) on Oct 18, 2004 at 02:02 UTC |
In Section
Seekers of Perl Wisdom