ロドリゲスの回転公式
#回転行列 #回転 #Transform #行列
Rodrigues' rotation formula
回転軸となる3次元ベクトルと角度から位置ベクトルを射影するやつ
https://en.wikipedia.org/wiki/Axis–angle_representation
https://en.wikipedia.org/wiki/Rodrigues'_rotation_formula
https://w3e.kanazawa-it.ac.jp/math/physics/category/physical_math/linear_algebra/henkan-tex.cgi?target=/math/physics/category/physical_math/linear_algebra/rodrigues_rotation_formula.html
公式
射影される位置ベクトルを$ \bm r・回転軸となる単位ベクトルを$ \bm u・回転する角度$ \thetaとしたとき、
$ \begin{aligned} \bm r' &= \bm r \cos \theta + \bm u (\bm u \cdot \bm r) (1 - \cos \theta) + (\bm u \times \bm r) \sin \theta \\ &= \bm r \cos \theta + \{ \bm u \times (\bm u \times \bm r) + \bm r \} (1 - \cos \theta) + (\bm u \times \bm r) \sin \theta \\ &= \bm r + (\bm u \times \bm r) \sin \theta + (1 - \cos \theta) \{ \bm u \times (\bm u \times \bm r) \} \end{aligned}
2行目の$ \bm u (\bm u \cdot \bm r) = \{ \bm u \times (\bm u \times \bm r) + \bm r \}の部分は、ベクトル三重積ならびに$ \bm uが単位ベクトルであることを用いて計算しているらしい
GLSL
code:glsl
vec3 rodrigues(vec3 p, vec3 axis, float angle) {
return mix(axis * dot(axis, p), p, cos(angle)) + cross(axis, p) * sin(angle);
}
Useful Functions for Shader Live Codingにも同じコードがあるよ
Desmos
https://gyazo.com/48dafc55f12e3afec7e1e68c40774210
https://www.desmos.com/3d/v7gt07yye2
行列
3次元回転行列を出す
いわゆる Matrix3.fromAxisAngle
回転軸となる単位ベクトル$ \bm u・回転する角度$ \thetaを用いて、
$ \bf R = \begin{bmatrix} u_x^2 (1 - \cos \theta) + \cos \theta & u_x u_y (1 - \cos \theta) - u_z \sin \theta & u_x u_z (1 - \cos \theta) + u_y \sin \theta \\ u_x u_y (1 - \cos \theta) + u_z \sin \theta & u_y^2 (1 - \cos \theta) + \cos \theta & u_y u_z (1 - \cos \theta) - u_x \sin \theta \\ u_x u_z (1 - \cos \theta) - u_y \sin \theta & u_y u_z (1 - \cos \theta) + u_x \sin \theta & u_z^2 (1 - \cos \theta) + \cos \theta \end{bmatrix}
分解
$ \bf U = \begin{bmatrix} 0 & -u_z & u_y \\ u_z & 0 & -u_x \\ -u_y & u_x & 0 \end{bmatrix}とおき、
$ \bf R = \bf I + \sin \theta \ \bf U + (1 - \cos \theta) \ \bf U^2