-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStruts.py
89 lines (75 loc) · 2.37 KB
/
Struts.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import math
from matplotlib import pyplot as plt
DEBUG=False
class Struts():
def __init__(self, point_att, point_sat):
self._pt_att = point_att
self._pt_sat = point_sat
self._tilt = 0
self.max_force = 0.0
self.min_len = 210.0
self.max_len = 510.0
def set_force(self, force):
self.max_force = float(force)
def tilt(self, angle):
self._tilt = angle
def get_att(self):
point = self._pt_att
hypotenuse = math.sqrt(point[0] ** 2 + point[1] ** 2)
adjancent = point[0]
opposite = point[1]
cos = adjancent / hypotenuse
sin = opposite / hypotenuse
tilt = -math.pi * self._tilt / 180.0
new_point = [None, None]
new_point[0] = hypotenuse * (cos * math.cos(tilt) + sin * math.sin(tilt))
new_point[1] = hypotenuse * (sin * math.cos(tilt) - cos * math.sin(tilt))
return new_point
def distance_to_point(self):
pt_att = self.get_att()
x1, y1 = pt_att
x2, y2 = self._pt_sat
A = (y1 - y2)
B = (x2 - x1)
C = (y2*x1 - y1*x2)
return math.fabs(C) / math.sqrt(A ** 2 + B ** 2) / 1000.0
def distance_extend(self):
pt_att = self.get_att()
x1, y1 = pt_att
x2, y2 = self._pt_sat
return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
def compute_force(self):
"""
Assum constant force
"""
dist = self.distance_extend()
if dist < self.min_len:
print "Can not shorter than: ", self.min_len
return -1
if dist > self.max_len:
if DEBUG:
print "Length exceed"
return self.max_force
return self.max_force
def t2f(self, torque):
"""
Torque to Force
"""
return torque / float(self.distance_to_point())
def f2t(self, force):
return force * float(self.distance_to_point())
if __name__ == "__main__":
struts = Struts([200,-400], [30,-420])
angles = range(180)
forces = []
torques = []
p1 = []
p2 = []
for angle in angles:
struts.tilt(angle)
p = struts.get_att()
p1.append(p[0])
p2.append(p[1])
forces.append(struts.t2f(307))
plt.plot(p1, p2)
plt.show()