Skip to main content

Handy classes for working with trees of 3d transformations.

Project description

transform3d

Handy classes for working with trees of 3d transformations.

Uses scipy.spatial.transform.Rotation for stable conversions between rotation representations.

install

$ pip3 install transform3d

convention

a_t_b denotes b relative to a, such that a point in frame b, p_b, is transformed to frame a by: p_a = a_t_b @ p_b (Note that @ is the matmul operator in python.) This provides easy to read series of transformations: a_t_d = a_t_b @ b_t_c @ c_t_d.

usage

import numpy as np
from transform3d import Transform, SceneNode, SceneState

# basic Transform usage
a_t_b = Transform(p=(1, 0, 0), rotvec=(0, 0, 0))
b_t_c = Transform(p=(0, 0, 1), rpy=(0, 0, np.pi / 2))
a_t_c = a_t_b @ b_t_c
c_t_a = a_t_c.inv

# transform a point from a's frame to c's frame
p_a = (1, 0, 0)
p_c = c_t_a @ p_a
# or multiple points
p_a = np.random.randn(2, 3)  # two points (x, y, z)
p_c = c_t_a @ p_a

# rotate vectors
v_a = (1, 0, 0)
v_c = c_t_a.rotate(v_a)
# or screws (6d, eg. force-torque)
s_a = (1, 0, 0, 1, 0, 0)
s_c = c_t_a.rotate(v_a)

# using SceneNode to build a tree
root = SceneNode()
a = SceneNode(parent=root)
b = SceneNode(parent=root)
c = SceneNode(parent=b)
# or:
root, a, b, c = SceneNode.n(4)
root.adopt(
    a,
    b.adopt(c)
)

# set node transforms in relation to parents
state = SceneState()
state[a] = Transform(p=(1, 0, 0), rpy=(np.pi, 0, 0))
state[b] = Transform(rotvec=(0, 90, 0), degrees=True)
state[c] = Transform(quat=(0, 0, 0, 1))

# calculate transforms between nodes
c_t_a = c.p(a, state)  # type: Transform

# solve for transforms
c_t_a_desired = Transform(p=(1, 2, 3), R=np.eye(3))
state[b] = b.solve(c, a, c_t_a_desired, state)
assert c.p(a, state).equals(c_t_a_desired)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

transform3d-0.0.3.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

transform3d-0.0.3-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file transform3d-0.0.3.tar.gz.

File metadata

  • Download URL: transform3d-0.0.3.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6

File hashes

Hashes for transform3d-0.0.3.tar.gz
Algorithm Hash digest
SHA256 5db3597ef21a6c6785dbbf47bb3cd3d64c83cb12d66f98bffd614e793f451693
MD5 db5ad62d42162c8e47b98e60bee05086
BLAKE2b-256 2a34ff7d22388e45ff577e6b83fd93db6209fc4700def49fe35bcf266c114d0b

See more details on using hashes here.

File details

Details for the file transform3d-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: transform3d-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6

File hashes

Hashes for transform3d-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b9e39f34a28369b54f087b8577017d13eeefdbbd7b1a0822d3975b36efcdfe9c
MD5 1ecaa281b106515185bd6566e1e45225
BLAKE2b-256 24adaa3e7d861aeca65c26842de0fa9f23810e1e0a33648e28afcd120577212d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page