Pytorch3d: Should +Y correspond to left in PyTorch3D's coordinate system?

Created on 3 Apr 2021  Â·  3Comments  Â·  Source: facebookresearch/pytorch3d

I have been reading the PyTorch3D transforms documentation and I have one question about the geometric conventions.

Specifically, there is one example that I am still confused about: on the Wikipedia Rotation matrix article, towards the bottom of the "Basic Rotations" section, there is an example of a positive 90° yaw rotation, about the Z axis.

The example from Wikipedia is right-handed, with positive rotation angles corresponding to CCW rotations. As far as I understand, this matches the conventions from PyTorch3D.

In the example, applying this rotation to a vector pointing along the X axis, i.e., ([1, 0, 0]) rotates it so it aligns with Y, i.e., ([0, 1, 0]). One can easily visualize how this transform would work---looking down at, say, a table, a vector pointing forward is simply rotated by 90° to point left. And since Y = left, this corresponds to [0, 1, 0].

However, a similar transform (which I may, however, have a mistake in) yields [0, -1, 0] in PyTorch3D.

This would indicate that the rotation about the Z axis corresponds to a rotation of the coordinate frame itself, and not a rotation of the points upon which the Transform3d acts. However, if one transforms the above point using Transform3d().translate(10, 10, 10), then one gets [11, 10, 10], indicating that the translation part translates the point itself, and not the coordinate system, since translating the coordinate system by that amount would make the point's coordinates negative.

My question is therefore: Is this expected behavior on the part of the Transform3d object?

Steps to reproduce this behavior (rotation part)

from pytorch3d.transforms import Transform3d, euler_angles_to_matrix
import torch
import math
yaw90 = euler_angles_to_matrix(torch.tensor([0.0, 0.0, math.pi / 2]), "XYZ")
unit_x_vec = torch.tensor([1.0, 0.0, 0.0])
transform = Transform3d().rotate(yaw90)
transform.transform_points(unit_x_vec.view(1, 3))

Interactive session results:

>>> from pytorch3d.transforms import Transform3d, euler_angles_to_matrix
>>> import torch
>>> import math
>>> yaw90 = euler_angles_to_matrix(torch.tensor([0.0, 0.0, math.pi / 2]), "XYZ")
>>> yaw90
tensor([[-4.3711e-08, -1.0000e+00,  0.0000e+00],
        [ 1.0000e+00, -4.3711e-08,  0.0000e+00],
        [ 0.0000e+00,  0.0000e+00,  1.0000e+00]])
>>> unit_x_vec = torch.tensor([1.0, 0.0, 0.0])
>>> transform = Transform3d().rotate(yaw90)
>>> transform
<pytorch3d.transforms.transform3d.Transform3d object at 0x7f45a2f15760>
>>> transform.get_matrix()
tensor([[[-4.3711e-08, -1.0000e+00,  0.0000e+00,  0.0000e+00],
         [ 1.0000e+00, -4.3711e-08,  0.0000e+00,  0.0000e+00],
         [ 0.0000e+00,  0.0000e+00,  1.0000e+00,  0.0000e+00],
         [ 0.0000e+00,  0.0000e+00,  0.0000e+00,  1.0000e+00]]])
>>> transform.transform_points(unit_x_vec.view(1, 3))
tensor([[-4.3711e-08, -1.0000e+00,  0.0000e+00]])
question

All 3 comments

@AndreiBarsan If I understand correctly you were trying to apply a 90 degree CCW rotation about the Z axis to a vector pointing along the +X axis?

From the wikipedia article:

each of these basic vector rotations appears counterclockwise when the axis about which they occur points toward the observer, the coordinate system is right-handed, and the angle θ is positive.

In PyTorch3D the coordinate system is right handed, however the +X axis points left, the +Y is up and +Z into the screen (i.e. away from the observer). In that case a +90 CCW about the Z axis of a vector in the direction [1, 0, 0] would give [0, -1, 0] which is what you observed.

This makes perfect sense, thank you for clarifying @nikhilaravi! My brain had "overfit" to the forward-left-up conventions from ROS. 😅

Do you think people would find it helpful if I sent over a PR clarifying this convention in transform3d.py?

Sure you can add that to transforms3d.py. We explain the coordinate system in this doc but it could be useful to have it documented in transforms as well.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ruslanvasylev picture ruslanvasylev  Â·  3Comments

TheshowN picture TheshowN  Â·  3Comments

florianHofherr picture florianHofherr  Â·  3Comments

shersoni610 picture shersoni610  Â·  3Comments

farhanrw picture farhanrw  Â·  3Comments