Printing SE3 with symbolic equations

Open
#60 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
numpy, python
Domain
tooling

Research direction

The issue identifies the SE3 printing example, SE3_matrix.A, and NumPy formatting APIs, but no source file or test. Locate the SE3 printing entry point, reproduce the symbolic-matrix example, and verify that printed columns align to the longest term without changing the shown numeric formatting.

Written by the indexing model from the issue text.

Description

enhancement

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.

Dominant language
Python
Stars
641
Forks
102
Avg merge
1d 18h
Merged PRs (30d)
4

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rai-opensource/spatialmath-python

All issues in rai-opensource/spatialmath-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.