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

Printing SE3 with symbolic equations #60

Open
Jakubach opened this issue Dec 11, 2022 · 1 comment
Open

Printing SE3 with symbolic equations #60

Jakubach opened this issue Dec 11, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@Jakubach
Copy link

Jakubach commented Dec 11, 2022

Hello,
I noticed that matrices with long symbolic equations are printed very shrink.
I found my own priting method and I suggest to align them by the longest term like this:

def print_SE3(SE3_matrix : SE3):
    SE3_numpy = SE3_matrix.A
    max_item_length = SE3_numpy.astype(np.string_).dtype.itemsize
    print(np.array2string(SE3_numpy,max_line_width=np.inf,precision=3,suppress_small=True,formatter = {'all':lambda x: f"{str(x):{max_item_length}}"}))

or:

def print_SE3(SE3_matrix : SE3):
    SE3_numpy = SE3_matrix.A
    max_item_length = SE3_numpy.astype(np.string_).dtype.itemsize
    with np.printoptions(precision=3, suppress=True, linewidth = np.inf, formatter = {'all':lambda x: f"{str(x):{max_item_length}}"}):
        print(SE3_numpy)

Results without print_SE3:

  -1.0*sin(theta2)*cos(theta1) 1.0*sin(theta1) 1.0*cos(theta1)*cos(theta2) (d3 + l2)*cos(theta1)*cos(theta2)  
  -1.0*sin(theta1)*sin(theta2) -1.0*cos(theta1) 1.0*sin(theta1)*cos(theta2) (d3 + l2)*sin(theta1)*cos(theta2)  
  1.0*cos(theta2) 0            1.0*sin(theta2) l1 + (d3 + l2)*sin(theta2)  
  0            0            0            1             

Results with print_SE3:

[[-1.0*sin(theta2)*cos(theta1)      1.0*sin(theta1)                   1.0*cos(theta1)*cos(theta2)       (d3 + l2)*cos(theta1)*cos(theta2)]
 [-1.0*sin(theta1)*sin(theta2)      -1.0*cos(theta1)                  1.0*sin(theta1)*cos(theta2)       (d3 + l2)*sin(theta1)*cos(theta2)]
 [1.0*cos(theta2)                   0                                 1.0*sin(theta2)                   l1 + (d3 + l2)*sin(theta2)       ]
 [0                                 0                                 0                                 1                                ]]

I know that this function could be better so the inner columns should have less separation but I think it's good first step towards the good change.

@petercorke
Copy link
Collaborator

this is a good idea. I want the package to work well for numeric and symbolic values. I wonder what causes the big gaps between the columns? precision, suppress_small and suppress should have no effect here and there aren't really any other formatting options. It would be annoying to have to write the column layout code to fix this...

@petercorke petercorke added the enhancement New feature or request label Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants