Ici, tout le code est présenté pour la [[lib:pcl|Point Cloud Library]] mais c'est aussi applicable pour OpenGL. ===Matrice de rotation pour mettre un point sur l'axe X=== Rappel : rotation autour de l'axe 0,0,0. On commence par enlever la coordonnée Y : float alpha = atan2(y, x); Eigen::AngleAxisf(-alpha, Eigen::Vector3f::UnitZ()) Puis autour de l'axe Y mais la coordonnée en X a changée. Eigen::AngleAxisf(atan2f(z, cosf(alpha)*x+sinf(alpha)*y), Eigen::Vector3f::UnitY()) Seconde solution : utiliser directement les quaternions. Eigen::Affine3f transform = Eigen::Affine3f::Identity(); Eigen::Quaternionf rotAxe; rotAxe.setFromTwoVectors(Eigen::Vector3f(rx, ry, rz), Eigen::Vector3f(1, 0, 0)); transform.prerotate(rotAxe); ===Matrice de rotation sur la base d'un vecteur unitaire=== $$R = \pmatrix{ —\mathbf u_1—\\ —\mathbf u_2—\\ —\mathbf u_3—} = \pmatrix{ {n_y\over\sqrt{n_x^2+n_y^2}} & {-n_x\over\sqrt{n_x^2+n_y^2}} & 0 \\ {n_xn_z\over\sqrt{n_x^2+n_y^2}} & {n_yn_z\over\sqrt{n_x^2+n_y^2}} & -\sqrt{n_x^2+n_y^2} \\ n_x & n_y & n_z}$$ [[https://math.stackexchange.com/questions/1956699/getting-a-transformation-matrix-from-a-normal-vector|Getting a transformation matrix from a normal vector]] {{ :doc:images:3d:matrices_-_getting_a_transformation_matrix_from_a_normal_vector_-_mathematics_stack_exchange_2019-10-23_10_36_29_.html |Archive le 06/10/2016 le 23/10/2019}} ===Fusion de plusieurs matrices de rotation / translation=== Si on souhaite regrouper plusieurs matrices de rotation et de translation dans une seule, il faut : $R = R_3 * R_2 * R_1 $