View Full Version : Easiest way to rotate point in 3d using trig

Schlogenburg

09-23-2000, 04:33 PM

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.

edotorpedo

09-24-2000, 01:11 AM

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

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.