Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize a SE3/SO3 instance using the numpy array #112

Closed
ningmimg opened this issue Dec 26, 2023 · 2 comments
Closed

Initialize a SE3/SO3 instance using the numpy array #112

ningmimg opened this issue Dec 26, 2023 · 2 comments

Comments

@ningmimg
Copy link

ningmimg commented Dec 26, 2023

When I try to initialize a SE3 instance with a 4X4 numpy array, it doesn't seem to work,(maybe I don't have enough skills ?)

instead I tried to create an instance of SO3 using a 3X3 rotation matrix, and I was pretty sure the numpy array A I gave was a rotation matrix (normalized). and
A @ A.T = array([[ 1.00000000e+00, -2.77555756e-17, 0.00000000e+00], [-2.77555756e-17, 1.00000000e+00, 0.00000000e+00], [ 0.00000000e+00, 0.00000000e+00, 1.00000005e+00]])
but the code always report error to me that
`ValueError Traceback (most recent call last)
Cell In[119], line 7
4 # # u,_,v = np.linalg.svd(a)
5 # a1 = np.dot(u,v)
6 from spatialmath import SO3
----> 7 SO3(a)
8 # # a.dtype
9 # # a1.T@a1
10 # a.T@a

File c:\pythonproject2\venv1\lib\site-packages\spatialmath\pose3d.py:104, in SO3.init(self, arg, check)
101 self.data = [smb.t2r(x) for x in arg.data]
103 elif not super().arghandler(arg, check=check):
--> 104 raise ValueError("bad argument to constructor")
when I change the value of A to A1 = np.asarray([[ 0.00000000000001, -1., 0.],
[ 1., 0., 0.],
[ 0., 0., 1.]])`
the SO3 instance is created successfully.
hence, I suspect the root of the problem may be a matter of precision , But there is no proper way to solve it

@jcao-bdai
Copy link
Collaborator

jcao-bdai commented Jan 3, 2024

Hi @ningmimg , thank you for bringing up this issue.

Firstly, creating SE3 from numpy array should work (but see below):

>>> from spatialmath import SE3
>>> import numpy as np
>>> x = np.eye(4, 4)
>>> x
array([[1., 0., 0., 0.],
       [0., 1., 0., 0.],
       [0., 0., 1., 0.],
       [0., 0., 0., 1.]])
>>> y = SE3(x)
>>> y
SE3(array([[1., 0., 0., 0.],
           [0., 1., 0., 0.],
           [0., 0., 1., 0.],
           [0., 0., 0., 1.]]))
>>> y.t
array([0., 0., 0.])
>>> y.R
array([[1., 0., 0.],
       [0., 1., 0.],
       [0., 0., 1.]])

However, given the second part of your description, I suspect you found it not working for the same reason as how it did not work in the SO3 example.

I see you've provided "A @ A.T" above, could you please also give me the value of A itself (the one that you used to produce that error for SO3)? Or, if you are willing to share, a few lines of actual code that you were having problem with?

@jcao-bdai
Copy link
Collaborator

Closing the issue as we haven't got any response from the reporter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants