taichi
taichi copied to clipboard
[gui] Add some built-in APIs for building transformation matrix
Related issue = #5513
Usage
# Get translation matrix
translate_vec = ti.Vector([1., 2., 3.])
translate_mat = ti.Matrix.translate(translate_vec[0], translate_vec[1], translate_vec[2])
# Get scale matrix
scale_vec = ti.Vector([1., 2., 3.])
scale_mat = ti.Matrix.scale(scale_vec[0], scale_vec[1], scale_vec[2])
# Get rotation matrix
angleZ = 1.046
angleX = 0.52
angleY = -0.785
rotation_mat = ti.Matrix.rotation4d(angleX, angleY, angleZ)
# or call as blew, which is the same restult with rotation4d
# rotation_mat = ti.Matrix.eulerAngleYXZ(angleZ, angleX, angleY)
# Then build a transformation matrix
trans_mat = translate_mat @ rotation_mat @ scale_mat
# Additional
# usage of rotate_by_vector
identity = ti.Matrix.identity(ti.f32, 4)
Angle = math.pi * 0.5
X = ti.Vector([1.0, 0.0, 0.0])
Y = ti.Vector([0.0, 1.0, 0.0, 1.0])
Y1 = ti.Matrix.rotate_by_vector(identity, Angle, X) @ Y
# Here Y1 is the same with Y2
Y2 = ti.Matrix.eulerAngleX(Angle) @ Y
Mainly new built-in APIs Details please refer to the notes of each API
- Translation
- ti.Matrix.translate(dx, dy, dz)
- Scale
- ti.Matrix.scale(sx, sy, sz)
- Rotation
- ti.Matrix.eulerAngleX(angleX)
- ti.Matrix.eulerAngleY(angleY)
- ti.Matrix.eulerAngleZ(angleZ)
- ti.Matrix.eulerAngleXY(angleX, angleY)
- ti.Matrix.eulerAngleYX(angleY, angleX)
- ti.Matrix.eulerAngleXZ(angleX, angleZ)
- ti.Matrix.eulerAngleZX(angleZ, angleX)
- ti.Matrix.eulerAngleYZ(angleY, angleZ)
- ti.Matrix.eulerAngleZY(angleZ, angleY)
- ti.Matrix.eulerAngleXYZ(t1, t2, t3)
- ti.Matrix.eulerAngleYXZ(yaw, pitch, roll)
- ti.Matrix.eulerAngleXZX(t1, t2, t3)
- ti.Matrix.eulerAngleXYX(t1, t2, t3)
- ti.Matrix.eulerAngleYXY(t1, t2, t3)
- ti.Matrix.eulerAngleYZY(t1, t2, t3)
- ti.Matrix.eulerAngleZYZ(t1, t2, t3)
- ti.Matrix.eulerAngleZXZ(t1, t2, t3)
- ti.Matrix.eulerAngleXZY(t1, t2, t3)
- ti.Matrix.eulerAngleYZX(t1, t2, t3)
- ti.Matrix.eulerAngleZYX(t1, t2, t3)
- ti.Matrix.eulerAngleZXY(t1, t2, t3)
- ti.Matrix.yawPitchRoll(yaw, pitch, roll)
- ti.Matrix.rotate_by_vector(m, angle, v)
- ti.Matrix.rotation3d(angle)
- ti.Matrix.rotation4d(angleX, angleY, angleZ)
Deploy Preview for docsite-preview ready!
Name | Link |
---|---|
Latest commit | 1d5294b22ddf680a7b88b7b619a64193a9b6dad8 |
Latest deploy log | https://app.netlify.com/sites/docsite-preview/deploys/62f4f9bfdad57b00087b3386 |
Deploy Preview | https://deploy-preview-5735--docsite-preview.netlify.app |
Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site settings.
I'm afraid we have several rotation implemented in different places now:
- https://github.com/taichi-dev/taichi/blob/master/python/taichi/lang/matrix.py#L1081
- https://github.com/taichi-dev/taichi/blob/master/python/taichi/math/mathimpl.py#L497
- https://github.com/taichi-dev/taichi/blob/master/python/taichi/math/mathimpl.py#L1081
Shall we collect them in one place?
@neozhaoliang Sorry for not noticing what we have done, I think we need to merge all those into one place. (Maybe need a meeting to talk about it)
This is great! Just wondering if we'd make these matrix operations library functions (i.e ti.math.xx) or member functions to Matrix? Any preferences @strongoier?
This is great! Just wondering if we'd make these matrix operations library functions (i.e ti.math.xx) or member functions to Matrix? Any preferences @strongoier?
I prefer making them library functions.
I'm afraid we have several rotation implemented in different places now:
- https://github.com/taichi-dev/taichi/blob/master/python/taichi/lang/matrix.py#L1081
- https://github.com/taichi-dev/taichi/blob/master/python/taichi/math/mathimpl.py#L497
- https://github.com/taichi-dev/taichi/blob/master/python/taichi/math/mathimpl.py#L1081
Shall we collect them in one place?
Agreed, then we'd suggest migration these implementations to https://github.com/taichi-dev/taichi/blob/master/python/taichi/math/mathimpl.py#L497. Thanks in advance! @Morcki
I'm afraid we have several rotation implemented in different places now:
- https://github.com/taichi-dev/taichi/blob/master/python/taichi/lang/matrix.py#L1081
- https://github.com/taichi-dev/taichi/blob/master/python/taichi/math/mathimpl.py#L497
- https://github.com/taichi-dev/taichi/blob/master/python/taichi/math/mathimpl.py#L1081
Shall we collect them in one place?
Agreed, then we'd suggest migration these implementations to https://github.com/taichi-dev/taichi/blob/master/python/taichi/math/mathimpl.py#L497. Thanks in advance! @Morcki
Ok, I will finish that. But there are still some questions suggested by rendong that if we should keep only some of the APIs listed as blew (drop others), and if the name of API should change to rotate3d_by_**, and if the name of the args should change from angle to radius. We should keep those all one unified format and give users a convenient usage.
- ti.Matrix.eulerAngleX(angleX)
- ti.Matrix.eulerAngleY(angleY)
- ti.Matrix.eulerAngleZ(angleZ)
- ti.Matrix.eulerAngleYXZ(yaw, pitch, roll)
- ti.Matrix.yawPitchRoll(yaw, pitch, roll)
- ti.Matrix.rotate_by_vector(m, angle, v)
- ti.Matrix.rotation3d(angle)
- ti.Matrix.rotation4d(angleX, angleY, angleZ)
As talked under offerline meeting, we decide to keep the APIs as below:
- Translation
- ti.math.translate(dx, dy, dz)
- Scale
- ti.math.scale(sx, sy, sz)
- Rotation
- ti.math.rot3d_by_axis(ang, axis)
- ti.math.rot3d_yaw_pitch_roll(yaw, pitch, roll)
- ti.math.rotation3d(ang_x, ang_y, ang_z)
refer to #5827