-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransform.py
25 lines (20 loc) · 839 Bytes
/
Transform.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# coding: utf-8
import numpy as np
def rotate (points, theta):
points = np.array(points)
NewCol = np.array(np.ones((np.shape(points)[0], 1)))
points = np.append(points, NewCol, axis=1)
Rmatrix = np.matrix([[np.cos(theta), -np.sin(theta), 0],
[np.sin(theta), np.cos(theta), 0],
[0, 0, 1]])
points = np.array(np.dot(Rmatrix, points.transpose())[:-1,:].transpose())
return points
def translate (points, x, y):
points = np.array(points)
NewCol = np.array(np.ones((np.shape(points)[0], 1)))
points = np.append(points, NewCol, axis=1)
Tmatrix = np.matrix([[1, 0, x],
[0, 1, y],
[0, 0, 1]],dtype = float)
points = np.array(np.dot(Tmatrix, points.transpose())[:-1,:].transpose())
return points