end0tknr's kipple - web写経開発

太宰府天満宮の狛犬って、妙にカワイイ

二次元座標系での回転行列 振り返り

blenderのaddonである Export-Paper-Model-from-Blender において fitting_matrix()として回転行列が実装されていたので、振り返り。(メモ)

Export-Paper-Model-from-Blender の unfolder.py で実装されている fitting_matrix(v1, v2)

Export-Paper-Model-from-Blender/unfolder.py at master · addam/Export-Paper-Model-from-Blender · GitHub

def fitting_matrix(v1, v2):
    """Get a matrix that rotates v1 to the same direction as v2"""
    return (1 / v1.length_squared) * M.Matrix((
        (v1.x*v2.x + v1.y*v2.y, v1.y*v2.x - v1.x*v2.y),
        (v1.x*v2.y - v1.y*v2.x, v1.x*v2.x + v1.y*v2.y)))

回転行列振り返り

まず、回転行列とは以下

 \large{
\begin{pmatrix} x' \\\ y' \end{pmatrix} =

\begin{pmatrix} cosθ -sinθ \\\ sinθ cosθ \end{pmatrix}
\begin{pmatrix} x \\\ y \end{pmatrix}

}

上記ある cosθ、sinθ は、内積外積から導入できますが、 その内積外積の定義は以下の通りです

 \large{ a・b = |a||b|cosθ }
 \large{ a✕b = |a||b|sinθ }

or

 \large{ a✕b = ax・by - ay・bx  }

参考url