Python: Transformation Matrix -



Python: Transformation Matrix -

is right way co-compute translation , rotation, or there improve way? @ moment code translates , rotates, pose problem?

code

from math import cos, sin, radians def trig(angle): r = radians(angle) homecoming cos(r), sin(r) def matrix(rotation=(0,0,0), translation=(0,0,0)): xc, xs = trig(rotation[0]) yc, ys = trig(rotation[1]) zc, zs = trig(rotation[2]) dx = translation[0] dy = translation[1] dz = translation[2] homecoming [[yc*xc, -zc*xs+zs*ys*xc, zs*xs+zc*ys*xc, dx], [yc*xs, zc*xc+zs*ys*xs, -zs*xc+zc*ys*xs, dy], [-ys, zs*yc, zc*yc, dz], [0, 0, 0, 1]] def transform(point=(0,0,0), vector=(0,0,0)): p = [0,0,0] r in range(3): p[r] += vector[r][3] c in range(3): p[r] += point[c] * vector[r][c] homecoming p if __name__ == '__main__': point = (7, 12, 8) rotation = (0, -45, 0) translation = (0, 0, 5) matrix = matrix(rotation, translation) print (transform(point, matrix))

output

root@ubuntu:~$ python rotate.py [-0.707106781186547, 12.0, 15.606601717798213]

well instead of matrizes utilize quaternions alternative. it's pretty popular, since gimbal lock problem not real issue , save less memory matrizes. nevertheless, depending on want do, might heavier in operations.

other way , right one. there many ways so, think there many right answers...

remember order of transformation processes important, changing order might yield different result.

matrix python-2.7 rotation translation

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -