Skip to main content

3D coordinate-frame transforms with numpy arrays bound to frames.

Project description

coordframe

3D coordinate-frame transforms with numpy arrays bound to frames.

Overview

Two headline abstractions for scripted 3D visualization and motion-capture analysis:

  • CoordFrame — a coordinate frame defined by an origin and three unit vectors (or a 4×4 transformation matrix). Frames are first-class objects with named axes; transforms can be applied to a frame or within a frame.
  • PointCloud — a numpy array of 3D points bound to a CoordFrame. Lets you reason about "joint positions in the femur frame" or "marker positions in the camera frame" directly, without manually tracking which transform applies to which point set.

The package also exports a Quat quaternion class and a small collection of helpers (transform, m4, v4, apply_matrix, normal2tfmat, twisttf, scaletf, norm_vec).

Why coordframe?

Existing 3D-transform libraries (transforms3d, pytransform3d, scipy.spatial.transform, pyquaternion) operate primarily on rotations and translations as standalone objects. coordframe's distinguishing move is to make the frame a first-class object with named axes, and to bind numpy point arrays to frames so you can express transform operations in the language of the application ("transform these markers in the camera frame") rather than the language of the math ("multiply this rotation matrix by these vectors").

This is the abstraction that powers bpn (the parent project, which uses it for Blender-scripted scientific visualization) and the motion-capture analysis pipelines built on top.

Install

pip install coordframe

Quick start

import numpy as np
import coordframe as cf

# World frame
world = cf.CoordFrame()

# A custom frame
femur = cf.CoordFrame(
    i=[1, 0, 0], j=[0, 1, 0], k=[0, 0, 1], origin=[0.1, 0.2, 0.3]
)

# Bind 3 marker positions to the femur frame
markers = cf.PointCloud(
    [[0, 0, 0], [0.05, 0, 0], [0, 0.05, 0]], frame=femur
)

# Express the markers in world coordinates
world_markers = markers.in_world()

# Rotate the femur frame 30 degrees around its k axis using a quaternion
q = cf.Quat([0, 0, 1], np.pi / 6, frame=femur)
femur_rotated = q * femur

History

Originally developed inside bpn (https://github.com/praneethnamburi/blender-ScriptViz) as bpn.trf. Graduated to a standalone package so consumers (motion- capture analysis pipelines, robotics tooling, generic scientific- Python users) can use it without installing Blender.

License

Distributed under the MIT License. See LICENSE for details.

Acknowledgments

This package was developed as part of the ImmersionToolbox initiative at the MIT.nano Immersion Lab. Thanks to NCSOFT for supporting this initiative.

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

coordframe-1.0.1.tar.gz (25.2 kB view details)

Uploaded Source

Built Distribution

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

coordframe-1.0.1-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file coordframe-1.0.1.tar.gz.

File metadata

  • Download URL: coordframe-1.0.1.tar.gz
  • Upload date:
  • Size: 25.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for coordframe-1.0.1.tar.gz
Algorithm Hash digest
SHA256 f4740af75ceec69c8081b9b07a8483584b9d803ac27d7ea9b04d1b2b9161fceb
MD5 49cb7d0d0040a8c73b5c7d0625a18c1d
BLAKE2b-256 d744c3af34d775282a6933865ed250d67c53fed0c3af6855e268dd6c0b906bf1

See more details on using hashes here.

File details

Details for the file coordframe-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: coordframe-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for coordframe-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ccab3148a70fdb3a80002b787592bc74843127e0cd24d9d5b3ac0b94a2621402
MD5 41bc1e8b33ab3c3e264958c8d2171568
BLAKE2b-256 d63612a86063724390a68fc6d20033162f2f53c1025ab90ab7672937c05bcec4

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