-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathHW3-2.py
49 lines (38 loc) · 1.57 KB
/
HW3-2.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
import numpy as np
class Pose3D:
def __init__(self, rotation, translation):
self.rotation = rotation
self.translation = translation
def inv(self):
'''
Inversion of this Pose3D object
:return inverse of self
'''
# Inversion
inv_rotation = np.transpose(self.rotation)
inv_translation = -1 * np.dot(inv_rotation, self.translation)
return Pose3D(inv_rotation, inv_translation)
def __mul__(self, other):
'''
Multiplication of two Pose3D objects, e.g.:
a = Pose3D(...) # = self
b = Pose3D(...) # = other
c = a * b # = return value
:param other: Pose3D right hand side
:return product of self and other
'''
# Multiplication
mul_rotation = np.dot(self.rotation, other.rotation)
mul_translation = np.add(self.translation, np.dot(self.rotation, other.translation))
return Pose3D(mul_rotation, mul_translation)
def __str__(self):
return "rotation:\n" + str(self.rotation) + "\ntranslation:\n" + str(self.translation.transpose())
def compute_quadrotor_pose(global_marker_pose, observed_marker_pose):
'''
:param global_marker_pose: Pose3D
:param observed_marker_pose: Pose3D
:return global quadrotor pose computed from global_marker_pose and observed_marker_pose
'''
# Global quadrotor pose computation
global_quadrotor_pose = global_marker_pose * observed_marker_pose.inv()
return global_quadrotor_pose