Skip to main content

Libary for creating spatial space hierarchies

Project description

spatial-transform

Libary for creating spatial space hierarchies, like game engines and renderes would do, to have diffrent rotations, scale and positions which also rely on their parent transformation.

This package is created for my master thesis and aims about integrety but not performance. For the most of the calculations the package PyGLM is used.

Install

pip install spatial-transform

Features

  • Space properties in local and world space
    • Position
    • Rotation (Quaternion & Euler)
    • Scale
    • Space 4x4 matrix
    • Axes direction (Forward, Up, Right)
  • Hierarchical
    • Transforms can have a parent and children
    • World space depends on the parent
    • Transforms can be easily attached / detachatched
  • Python
    • Every method is documented in code with docstrings
    • Every method has type hinting
  • Includes a static class for euler angle conversions.

Notes

This libary works with the same space as openGL and GLM, which is:

  • right handed
  • Y+ is up
  • Z- is forward
  • Positive rotation is counter clockwise

Euler angles can be set with methods on the transform. SetEuler() and GetEuler() support any instrinic or extrinsic rotation order. Angles are degrees for the Transform class but radians for the Euler class.

Examples

Create and attach transforms

from SpatialTransform import Transform as T

# create and attach
root = T('Hips', position=(0,2,0)).attach(
    T('LeftLegUpper', position=(+.2, 0, 0)).lookAtLocal((0,-1,0)).attach(
        T('LeftLegLower', position=(0, 0, -1)).attach(
            T('LeftLegFoot', position=(0, 0, -1)).lookAtLocal((-1,0,0)))),
    T('RightLegUpper', position=(-.2, 0, 0)).lookAtLocal((0,-1,0)).attach(
        T('RightLegLower', position=(0, 0, -1)).attach(
            T('RightLegFoot', position=(0, 0, -1)).lookAtLocal((-1,0,0)))))

# print info about created structure
root.printTree()

print('\nWorld space positions:')
for item, index, depth in root.layout():
    print(f'{item.pointToWorld((0,0,0))} {item.Name}')

# Hips
# +- LeftLegUpper
# |  +- LeftLegLower
# |     +- LeftLegFoot
# +- RightLegUpper
#    +- RightLegLower
#       +- RightLegFoot

# World space positions:
# vec3(            0,            2,            0 ) Hips
# vec3(          0.2,            2,            0 ) LeftLegUpper
# vec3(          0.2,            1,            0 ) LeftLegLower
# vec3(          0.2,            0,            0 ) LeftLegFoot
# vec3(         -0.2,            2,            0 ) RightLegUpper
# vec3(         -0.2,            1,            0 ) RightLegLower
# vec3(         -0.2,            0,            0 ) RightLegFoot

Change properties

# gets a transform in the hierarchy
foot = root.filter('LeftLegFoot', isEqual=True)[0]

# basic property changes
foot.Position = (0.5, 0, 0)
foot.Rotation = (1, 0, 0, 0) # quaternion
foot.Scale = (2, 1, .5)

# use methods for changes
foot.lookAtWorld((-5, 0, 0))
foot.applyRotation()
foot.setEuler((0, -90, 25))
foot.clearParent(keepPosition=True, keepRotation=True)

# transform spatial data
foot.pointToWorld((1,1,1)) # converts a point from local to world space
foot.pointToLocal((1,1,1)) # inverse of pointToWorld

foot.directionToWorld((0,0,1)) # converts a direction from local to world space
foot.directionToLocal((0,0,1)) # inverse of pointToWorld

Euler angles conversions

from SpatialTransform import Euler

# rotations are in radians here
matrix = Euler.toMatFrom((1, 2, .5), 'YZX', True)
quaternion = Euler.toQuatFrom((1, 2, .5), 'YZX', True)

angles1 = Euler.fromMatTo(matrix, 'XYZ', False)
angles2 = Euler.fromQuatTo(quaternion, 'XYZ', False)

print(angles1 - angles2) # this will be zero, because its the same angle

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

spatial_transform-1.0.8.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

spatial_transform-1.0.8-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file spatial_transform-1.0.8.tar.gz.

File metadata

  • Download URL: spatial_transform-1.0.8.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for spatial_transform-1.0.8.tar.gz
Algorithm Hash digest
SHA256 06520b51c53d28f4ad7030f9091252fd6e2167dcbf863ad2b32c12813406218a
MD5 f5ca6d53291020c0cc340513505d1431
BLAKE2b-256 83f2a3df405229db09e70fdb34da50028c099d36d14fa262676d3c5c39f82e6a

See more details on using hashes here.

File details

Details for the file spatial_transform-1.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for spatial_transform-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 3c2ed0968220af1f47b796b1e2c64c9c32699ac5c985a474d455ef66d1170d9c
MD5 8da8a90f65b1b7e4786ba68f9cb56e18
BLAKE2b-256 1e7a05651766ebf40e0019ce2d99abaf7ae20b54b13860123b69610e8f3d4868

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