-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeometrics.py
72 lines (59 loc) · 2.17 KB
/
geometrics.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Feb 21 18:16:57 2020
@author: linux-asd
"""
import numpy as np
def Rx(roll):
""" Rotation matrix arround x (roll)
"""
# roll = np.radians(roll)
return np.matrix([[1, 0, 0, 0],
[0, np.cos(roll), -np.sin(roll), 0],
[0, np.sin(roll), np.cos(roll), 0],
[0, 0, 0, 1]])
def Ry(pitch):
""" Rotation matrix arround y (pitch)
"""
# pitch = np.radians(pitch)
return np.matrix([[ np.cos(pitch), 0, np.sin(pitch), 0],
[ 0, 1, 0, 0],
[-np.sin(pitch), 0, np.cos(pitch), 0],
[ 0, 0, 0, 1]])
def Rz(yaw):
""" Rotation matrix arround z (yaw)
"""
# yaw = np.radians(yaw)
return np.matrix([[np.cos(yaw), -np.sin(yaw), 0, 0],
[np.sin(yaw), np.cos(yaw), 0, 0],
[ 0, 0, 1, 0],
[ 0, 0, 0, 1]])
def Rxyz(roll , pitch , yaw):
if roll != 0 or pitch != 0 or yaw != 0:
R = Rx(roll)*Ry(pitch)*Rz(yaw)
return R
else:
return np.identity(4)
def RTmatrix(orientation, position):
"""compose translation and rotation"""
roll = orientation[0]
pitch = orientation[1]
yaw = orientation[2]
x0 = position[0]
y0 = position[1]
z0 = position[2]
translation = np.matrix([[1, 0, 0, x0],#Translation matrix
[0, 1, 0, y0],
[0, 0, 1, z0],
[0, 0, 0, 1]])
rotation = Rxyz(roll, pitch, yaw)#rotation matrix
return rotation*translation
def transform(coord,rotation,translation):
"""transforms a vector to a desire rotation and translation"""
vector = np.array([[coord[0]],
[coord[1]],
[coord[2]],
[ 1]])
tranformVector = RTmatrix(rotation,translation)*vector
return np.array([tranformVector[0,0], tranformVector[1,0], tranformVector[2,0]])