Rotation in $3D$ with $Z$-Coordinate

43 Views Asked by At

I have a given $3D$ vector$(x,y,z)$ and I want to perform an rotation in $x$ and in $y$ for a $3D$ program to calculate the cameras position. I already found this website : https://open.gl/transformations
Where the matrix operation is explained. But when I calculate it, my $z$ seems to be wrong...

Formels :

angleX - Rotation $X$
angleY - Rotation $Y$
$x$ - Vector $x$
$y$ - Vector $y$
$z$ - Vector $z$

z=( sin( angleX ) ⋅ y + cos( angleX ) ⋅ z ) + ( − sin( angleY ) ⋅ x + cos( angleY ) ⋅ z )

1

There are 1 best solutions below

6
On BEST ANSWER

If you apply first the rotation around $X$ you get: $$x_1=x\\y_1=\cos(angleX)y-\sin(angleX)z\\z_1=\sin(angleX)y+\cos(angleX)z$$ Then you apply rotation around $Y$ on $(x_1,y_1,z_1)$ to get: $$x_2=\cos(angleY)x_1+\sin(angleY)z_1\\y_2=y_1\\z_2=-\sin(angleY)x_1+\cos(angleY)z_1$$ By combining these equations you get $z_2=-\sin(angleY)x+\cos(angleY)[\sin(angleX)y+\cos(angleX)z]$