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

Re: Rotate a 3D vector

by true (Pilgrim)
on Oct 18, 2004 at 02:59 UTC ( #400038=note: print w/replies, xml ) Need Help??


in reply to Rotate a 3D vector

Back to the trenches with me. I'm starting with a 2d space till i can wrap my head around it. The code and examples i am finding are not matching up in 3d space. Here's my closest attempt which still is wrong. Can anyone help?
# 2 points on a plane my $x = 2; my $y = 1; #yang is the y-angle 0-360 i want to rotate by my $yang = 45; #convert yang to radians $yang = 3.14159265358979*$yang/180; #rad is the radius of my sphere my $rad = sqrt($x**2 + $y**2); my $x = cos($yang)*$rad; my $y = sin($yang)*$rad; print "x=$x\ny=$y\n";
Advice appreciated.
jtrue

Replies are listed 'Best First'.
Re^2: Rotate a 3D vector
by johnnywang (Priest) on Oct 18, 2004 at 03:57 UTC
    Just a little change, the formula was not correct (as I pointed out in my previous post in this thread)
    # 2 points on a plane my $x = 2; my $y = 1; #yang is the y-angle 0-360 i want to rotate by my $yang = 45; #convert yang to radians $yang = 3.14159265358979*$yang/180; my $xnew = cos($yang)*$x - sin($yang)*y; my $ynew = sin($yang)*$x + cos($yang)*y; print "x=$xnew, y=$ynew\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://400038]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2020-11-26 21:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?