Skip to content

Instantly share code, notes, and snippets.

@odwdinc
Created January 6, 2019 22:57
Show Gist options
  • Save odwdinc/32a687d180fd024f75b2ee054dc6260c to your computer and use it in GitHub Desktop.
Save odwdinc/32a687d180fd024f75b2ee054dc6260c to your computer and use it in GitHub Desktop.
from pyrr import Quaternion, Matrix33, Matrix44, Vector4,Vector3
import numpy as np
from numpy.linalg import inv
point = [Vector3([172.62,63.11,-4.02]),
Vector3([239.76,-14.55,-5.61]),
Vector3([166.59,-80.36,-5.33])]
orientation = Quaternion()
translation = Vector3()
scale = Vector3([0.99,0.99,1.])
# translate along X by 1
translation += [100.66,-6.03,-4.11]
# rotate about X by 0.5*
rotation = Quaternion.from_x_rotation(-0.0174533)
orientation = rotation * orientation
# rotate about Y by 0.5*
rotation = Quaternion.from_y_rotation(-0.0021816616)
orientation = rotation * orientation
# rotate about Z by 0.5*
rotation = Quaternion.from_z_rotation(0.802851)
orientation = rotation * orientation
# create a matrix
matrix = Matrix44.identity()
# apply our translation
matrix = matrix * Matrix44.from_translation(translation)
# apply our orientation
# we can multiply matricies and quaternions directly!
matrix = matrix * orientation
# apply our scale
matrix = matrix * Matrix44.from_scale(scale)
matrix = inv(matrix)
print(matrix)
# transform our point by the matrix
# vectors are transformable by matrices and quaternions directly
for pt in point:
out = matrix * pt
out = [int(val) for val in out]
print(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment