0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

`pyquaternion.Quaternion`で回転行列を指定したときに、"ValueError: Matrix must be orthogonal, i.e. its transpose should be its inverse"というエラーが発生した

Last updated at Posted at 2024-11-20

環境

  • Python 3.12.4
  • pyquaternion 0.9.9

内容

回転行列からクォータニオンを生成しようとしたら、ValueErrorが発生しました。

In [438]: np.array([[-0.9878369, -0.0169982, -0.1545619],
     ...:      ...:        [ 0.0140767, -0.9997013,  0.0199772],
     ...:      ...:        [-0.1548553,  0.0175585,  0.9877811]])
Out[438]:
array([[-0.9878369, -0.0169982, -0.1545619],
       [ 0.0140767, -0.9997013,  0.0199772],
       [-0.1548553,  0.0175585,  0.9877811]])

In [439]: from pyquaternion import Quaternion

In [440]: Quaternion(matrix=matrix)
---------------------------------------------------------------------------
ValueError: Matrix must be orthogonal, i.e. its transpose should be its inverse

回転行列は直行行列でないといけないのですが、直行行列でなかったようです。

        if not np.allclose(np.dot(R, R.conj().transpose()), np.eye(3), rtol=rtol, atol=atol):
            raise ValueError("Matrix must be orthogonal, i.e. its transpose should be its inverse")

トレランスのデフォルト値は以下の通りです。

  • atol : 絶対誤差(1e-8
  • rtol : 絶対誤差(1e-5

以下の通りatolを指定することで、クォータニオンを生成することができました。

In [442]: Quaternion(matrix=matrix, atol=1e-7)
Out[442]: Quaternion(0.007792803681116881, -0.07759405485330212, 0.009413009893299702, 0.9969101388791268)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?