In [1]:
from openglider.vector import transformation as trans
import numpy as np
from importlib import reload
reload(trans)
import matplotlib.pyplot as plt

In [4]:
rot = trans.Rotation(angle=np.pi/16)
move = trans.Translation(np.array([0, 0.1, 0]))
scale = trans.Scale(1.1)
reflect = trans.Reflection(np.array([1, 0, 0]))

combined = rot.dot(move)

In [5]:
vec4 = np.array([[0,0,0,1], [1,0,0,1], [1,1,0,1], [0,1,0,1], [0,0,0,1]])
vec3 = vec4.T[:-1].T
vec2 = vec3.T[:-1].T

In [7]:
combined.apply(vec2).T.T


Out[7]:
array([[ 0.        ,  0.1       ],
       [ 0.98078528,  0.29509032],
       [ 0.78569496,  1.2758756 ],
       [-0.19509032,  1.08078528],
       [ 0.        ,  0.1       ]])

In [8]:
combined.apply(vec3).T[:2].T


Out[8]:
array([[ 0.        ,  0.1       ],
       [ 0.98078528,  0.29509032],
       [ 0.78569496,  1.2758756 ],
       [-0.19509032,  1.08078528],
       [ 0.        ,  0.1       ]])

In [9]:
combined.apply(vec4).T[:2].T


Out[9]:
array([[ 0.        ,  0.1       ],
       [ 0.98078528,  0.29509032],
       [ 0.78569496,  1.2758756 ],
       [-0.19509032,  1.08078528],
       [ 0.        ,  0.1       ]])

In [10]:
plt.figure(figsize=(10, 10))
plt.plot(*vec2.T[:2])
plt.plot(*scale.apply(vec2).T[:2])
plt.plot(*scale.dot(rot).apply(vec2).T[:2])
plt.plot(*scale.dot(rot.dot(move)).apply(vec2).T[:2])
plt.plot(*scale.dot(rot.dot(move.dot(reflect))).apply(vec2).T[:2])
plt.show()



In [13]:
combined(np.array([1,2,3]))


Out[13]:
array([ 0.59060464,  2.25666088,  3.        ])

In [14]:
np.zeros((10,3))


Out[14]:
array([[ 0.,  0.,  0.],
       [ 0.,  0.,  0.],
       [ 0.,  0.,  0.],
       [ 0.,  0.,  0.],
       [ 0.,  0.,  0.],
       [ 0.,  0.,  0.],
       [ 0.,  0.,  0.],
       [ 0.,  0.,  0.],
       [ 0.,  0.,  0.],
       [ 0.,  0.,  0.]])

In [ ]: