Easiest way to rotate point in 3d using trig

Can somebody please post a c++ code that can do this? Like so:

x=20;
y=20;
z=10;
yangle=45;
xangle=30;

// code here to rotate it

resulting in float nx, ny, nz

This would be very helpfull. Thank you.

Hi,

assuming you are rotating around the origin: you need to multiply two matrices and then with vector. Anyway, I’ll spare you this, here is the pseudocode:

x= cos(yangle)* x + sin(yangle)*sin(xangle)*y

  • sin(yangle)*cos(xangle)*z

y = 0 + cos(xangle)*y + sin(xangle)*z

z= sin(yangle)x + cos(yangle)-sin(xangle)
*y + cos(yangle)*cos(xangle)*z

I know this looks a bit odd, but it really does the trick. For more help on matrices, mail fredo@studenten.net