mlx3d.transforms¶
mlx3d.transforms
¶
Transform3d
¶
A batched rigid/affine 3D transform: x -> R @ x + t.
Stores a rotation/scale-shear block rot (..., 3, 3) and a translation
trans (..., 3). Transforms compose, invert, and apply to points and
normals, and are fully differentiable (handy for pose optimization).
Build one with the constructors :meth:from_rot_trans, :meth:translate,
:meth:rotate, :meth:scale, or compose with :meth:compose / @.
Source code in src/mlx3d/transforms/se3.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
compose(other)
¶
Return the transform that applies self first, then other.
Source code in src/mlx3d/transforms/se3.py
183 184 185 186 187 | |
transform_points(points)
¶
Apply to points (..., 3): R @ x + t (row-vector form, broadcasts).
Source code in src/mlx3d/transforms/se3.py
198 199 200 | |
transform_normals(normals)
¶
Apply to normals with the inverse transform (ignores translation).
Source code in src/mlx3d/transforms/se3.py
202 203 204 | |
get_matrix()
¶
Return the homogeneous (..., 4, 4) matrix form.
Source code in src/mlx3d/transforms/se3.py
206 207 208 209 210 | |
axis_angle_to_matrix(axis_angle)
¶
Convert axis-angle vectors (..., 3) to rotation matrices (..., 3, 3).
Source code in src/mlx3d/transforms/rotations.py
121 122 123 | |
axis_angle_to_quaternion(axis_angle)
¶
Convert axis-angle vectors (..., 3) to quaternions (..., 4).
Source code in src/mlx3d/transforms/rotations.py
92 93 94 95 96 97 98 99 100 101 102 | |
euler_angles_to_matrix(euler_angles, convention='XYZ')
¶
Convert Euler angles (..., 3) (radians) to rotation matrices (..., 3, 3).
convention is a 3-letter string of axes, e.g. "XYZ" applies
R = R_X(a0) @ R_Y(a1) @ R_Z(a2).
Source code in src/mlx3d/transforms/rotations.py
145 146 147 148 149 150 151 152 153 154 | |
matrix_to_axis_angle(matrix)
¶
Convert rotation matrices (..., 3, 3) to axis-angle vectors (..., 3).
Source code in src/mlx3d/transforms/rotations.py
126 127 128 | |
matrix_to_quaternion(matrix)
¶
Convert rotation matrices (..., 3, 3) to quaternions (..., 4) in (w, x, y, z) order.
Uses the numerically stable branch selection of Shepperd's method.
Source code in src/mlx3d/transforms/rotations.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
matrix_to_rotation_6d(matrix)
¶
Convert rotation matrices (..., 3, 3) to the 6D representation (..., 6).
Source code in src/mlx3d/transforms/rotations.py
171 172 173 | |
quaternion_apply(quaternion, point)
¶
Rotate points (..., 3) by unit quaternions (..., 4).
Source code in src/mlx3d/transforms/rotations.py
196 197 198 199 200 201 | |
quaternion_invert(quaternion)
¶
Inverse of unit quaternions: the conjugate.
Source code in src/mlx3d/transforms/rotations.py
191 192 193 | |
quaternion_multiply(a, b)
¶
Hamilton product of two quaternion arrays (..., 4).
Source code in src/mlx3d/transforms/rotations.py
176 177 178 179 180 181 182 183 184 185 186 187 188 | |
quaternion_to_axis_angle(quaternions)
¶
Convert quaternions (..., 4) to axis-angle vectors (..., 3).
Source code in src/mlx3d/transforms/rotations.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
quaternion_to_matrix(quaternions)
¶
Convert quaternions (..., 4) in (w, x, y, z) order to rotation matrices (..., 3, 3).
Source code in src/mlx3d/transforms/rotations.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
random_quaternions(n, key=None)
¶
Sample n uniform random unit quaternions, shape (n, 4).
Source code in src/mlx3d/transforms/rotations.py
204 205 206 207 208 209 210 | |
random_rotations(n, key=None)
¶
Sample n uniform random rotation matrices, shape (n, 3, 3).
Source code in src/mlx3d/transforms/rotations.py
213 214 215 | |
rotation_6d_to_matrix(d6)
¶
Convert 6D rotation representation (..., 6) to matrices via Gram-Schmidt.
Reference: Zhou et al., "On the Continuity of Rotation Representations in Neural Networks" (CVPR 2019).
Source code in src/mlx3d/transforms/rotations.py
157 158 159 160 161 162 163 164 165 166 167 168 | |
standardize_quaternion(quaternions)
¶
Flip quaternions so the real part is non-negative.
Source code in src/mlx3d/transforms/rotations.py
87 88 89 | |
hat(v)
¶
Map (..., 3) vectors to skew-symmetric matrices (..., 3, 3).
Source code in src/mlx3d/transforms/se3.py
28 29 30 31 32 33 34 35 | |
se3_exp_map(xi)
¶
Exponential map from twists (..., 6) = [v(3), omega(3)] to transforms.
omega is the rotation part and v the translation part of the twist
(PyTorch3D ordering). Returns a :class:Transform3d.
Source code in src/mlx3d/transforms/se3.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
se3_log_map(transform)
¶
Inverse of :func:se3_exp_map: twists (..., 6) = [v, omega] from a transform.
Source code in src/mlx3d/transforms/se3.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
so3_exp_map(omega)
¶
Rotation matrices (..., 3, 3) from axis-angle vectors (..., 3) (Rodrigues).
Source code in src/mlx3d/transforms/se3.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
so3_log_map(r)
¶
Axis-angle vectors (..., 3) from rotation matrices (..., 3, 3).
This is the inverse of :func:so3_exp_map. It delegates to the quaternion
based conversion, which stays accurate near theta = pi where the naive
theta / (2 sin theta) form is singular.
Source code in src/mlx3d/transforms/se3.py
75 76 77 78 79 80 81 82 83 84 | |
vee(m)
¶
Inverse of :func:hat: extract (..., 3) from a skew matrix (..., 3, 3).
Source code in src/mlx3d/transforms/se3.py
38 39 40 | |