forked from tbattz/bike-fit-vis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
102 lines (77 loc) · 2.57 KB
/
main.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
90
91
92
93
94
95
96
97
98
99
100
import matplotlib.pyplot as plt
import numpy as np
import math
import json
from bike import Bike
from rider import Rider
if __name__ == '__main__':
# Read bike configuration
with open('bike.json') as f:
bc = json.load(f)
print('Read bike configuration file:')
for key, val in bc.items():
print(key+":", val)
print()
# Read rider configurations
with open('rider.json') as f:
rcs = json.load(f)
print('Read rider configuration file:')
for riderName, rc in rcs.items():
print("Rider: %s" % riderName)
for key, val in rc.items():
print(key+":", val)
print()
# Create figure
fig = plt.figure(figsize=(13*1.5, 5*1.5))
ax1 = plt.subplot(121)
ax2 = plt.subplot(222)
ax3 = plt.subplot(224, sharex=ax2)
ax3.set_xlabel('Crank Angle (Deg)')
ax2.set_ylabel('Knee Angle (Deg)')
ax3.set_ylabel('Hip Angle (Deg)')
ax2.grid(axis='y', ls='--')
ax3.grid(axis='y', ls='--')
plt.tight_layout()
ax1.axis('equal')
ax1.set_xlim([-950, 1200])
ax1.set_ylim([-400, 1050])
ax1.axis('off')
plt.ion()
# Create bike
bike = Bike(bc, ax=ax1)
bike.calcBikePositions()
# Create riders
rider1 = Rider(rcs['rider1'], bike, seatColor='royalblue', riderColor='blueviolet', riderAlpha=0.5, ax=ax1)
rider2 = Rider(rcs['rider2'], bike, seatColor='lime', riderColor='darkgreen', riderAlpha=0.5, ax=ax1)
rider3 = Rider(rcs['rider3'], bike, seatColor='purple', riderColor='red', riderAlpha=0.5, ax=ax1)
rider4 = Rider(rcs['rider4'], bike, seatColor='cyan', riderColor='lime', riderAlpha=0.5, ax=ax1)
# Draw bike
bike.drawBikePositions()
# Draw Seat
rider1.drawSeat()
rider2.drawSeat()
rider3.drawSeat()
rider4.drawSeat()
# Draw pedal and feet
for crankAngleDeg in np.linspace(-2, 360*40, 360*20):
# Draw cranks
bike.calcCrankLoc(theta=-crankAngleDeg)
bike.drawCrank()
# Draw rider lower body
rider1.calcAndDrawAll(crankAngleDeg)
rider2.calcAndDrawAll(crankAngleDeg)
rider3.calcAndDrawAll(crankAngleDeg)
rider4.calcAndDrawAll(crankAngleDeg)
# Draw angle lines
rider1.drawAngleLines(ax2, ax3)
rider2.drawAngleLines(ax2, ax3)
rider3.drawAngleLines(ax2, ax3)
rider4.drawAngleLines(ax2, ax3)
# Update Axes Limits
ax2.relim()
ax2.autoscale_view()
ax3.relim()
ax3.autoscale_view()
plt.pause(0.01)
plt.axis('equal')
plt.show()