/
Vorwaertsproblem.py
163 lines (149 loc) · 7.05 KB
/
Vorwaertsproblem.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button
import vorwaerts as vw
class Vorwaertsproblem():
def __init__(self, l_e=10, l_r=3, h_m=30, h_b=90, phi_0=135, delta_phi=45, psi=90, show_legend=True):
self.l_e = l_e
self.l_r = l_r
self.h_m = h_m
self.h_b = h_b
self.phi = phi_0
self.delta_phi = delta_phi
self.psi = psi
self.show_legend = show_legend
def initUI(self):
self.fig, self.ax = plt.subplots()
self.fig.canvas.set_window_title('Numerik DGL 2 - Schattenprojektion')
self.fig.suptitle('Vorwaertsproblem')
plt.subplots_adjust(bottom=0.3)
plt.axis([0, 200, -100, 100])
plt.axis('equal')
axColor = 'lightgoldenrodyellow'
# Slider - Phi
axPhi = plt.axes([0.18, 0.2, 0.65, 0.03], axisbg=axColor)
self.sliderPhi = Slider(axPhi, 'Phi', 0, 360, valinit=self.phi, valfmt='%1d')
self.sliderPhi.on_changed(self.onUpdate)
# Slider - Delta Phi
axDeltaPhi = plt.axes([0.18, 0.15, 0.65, 0.03], axisbg=axColor)
self.sliderDeltaPhi = Slider(axDeltaPhi, 'Delta Phi', 5, 360, valinit=self.delta_phi, valfmt='%1d')
self.sliderDeltaPhi.on_changed(self.onUpdate)
# Slider - Psi
axPsi = plt.axes([0.18, 0.1, 0.65, 0.03], axisbg=axColor)
self.sliderPsi = Slider(axPsi, 'Psi', 0, 180, valinit=self.psi, valfmt='%1d')
self.sliderPsi.on_changed(self.onUpdate)
# Button - Previous
axPrev = plt.axes([0.18, 0.03, 0.1, 0.05])
self.buttonPrev = Button(axPrev, 'Previous')
self.buttonPrev.on_clicked(self.onPrevious)
# Button - Next
axNext = plt.axes([0.29, 0.03, 0.1, 0.05])
self.buttonNext = Button(axNext, 'Next')
self.buttonNext.on_clicked(self.onNext)
# Button - Reset
axReset = plt.axes([0.73, 0.03, 0.1, 0.05])
self.buttonReset = Button(axReset, 'Reset')
self.buttonReset.on_clicked(self.onReset)
self.onDraw()
def onPrevious(self, event):
self.phi -= self.delta_phi
self.phi = self.phi % 360
self.onDraw()
def onNext(self, event):
self.phi += self.delta_phi
self.phi = self.phi % 360
self.onDraw()
def onReset(self, event):
self.sliderPhi.reset()
self.sliderDeltaPhi.reset()
self.sliderPsi.reset()
self.onDraw()
def onUpdate(self, val):
self.phi = int(self.sliderPhi.val)
self.delta_phi = int(self.sliderDeltaPhi.val)
self.psi = int(self.sliderPsi.val)
self.onDraw()
self.fig.canvas.draw_idle()
def onDraw(self):
self.ax.cla() # clear the axes
self.ax.margins(x=.1, y=.1) # add margins
self.ax.autoscale(enable=False)
psi = np.radians(self.psi)
phi = np.radians(self.phi)
# Werte berechnen
h_r = vw.get_h_r(self.l_e, self.h_m, phi)
alpha = vw.get_alpha(self.l_e, phi, h_r)
beta = vw.get_beta(alpha, psi)
h = vw.get_h(psi, self.h_b, beta)
gamma = vw.get_gamma(self.l_r, h_r)
b_bottom = vw.get_b_bottom(h, beta, gamma)
b_top = vw.get_b_top(h, beta, gamma)
b = vw.get_b(h, beta, gamma)
# Abstand bis Drehteller vom Ursprung
point_phi_x, point_phi_y = self.plot_line(0, 0, np.radians(0), self.h_m, name="hm", color='k-')
self.ax.plot(self.h_m, 0, 'kx')
self.ax.text(self.h_m, -0.3, 'h_m')
# Untere Bodenlinie
point_psi_x, point_psi_y = self.plot_line(0, 0, np.radians(0), self.h_b, name="hb", color='k-')
self.ax.plot(self.h_b, 0, 'kx')
self.ax.text(self.h_b, -0.3, 'h_b')
# Drehteller
circlele = plt.Circle((point_phi_x, point_phi_y), self.l_e, color='k', linestyle='dashed', fill=False)
self.ax.add_artist(circlele)
# Winkelhalbierende
point_b_x, point_b_y = self.plot_line(0,0, alpha, h, name="h", color='g-')
# Winkelhalbierende bis Kreismittelpunkt
point_r_x, point_r_y = self.plot_line(0, 0, alpha, h_r, name="hr", color = 'b-')
# Abstand Mitte Drehteller, Mitte Zylinder
self.ax.plot((self.h_m, point_r_x), (0, point_r_y), 'y-', label='l_e')
self.ax.plot(point_r_x, point_r_y, 'kx')
self.ax.text(point_r_x, point_r_y-0.3, 'M')
# Zylinder
circler = plt.Circle((point_r_x,point_r_y), self.l_r, color='k', fill=False)
self.ax.add_artist(circler)
# x,y Koordinate der Punkt b_top und b_bottom bestimmen
b_top_x, b_top_y = self.plot_line(point_b_x, point_b_y, np.pi-psi, b_top, plot=False)
b_bottom_x, b_bottom_y = self.plot_line(point_b_x, point_b_y, 2*np.pi-psi, b_bottom, plot=False)
# Wand
if b_bottom_y > point_psi_y and b_top_y > point_psi_y: # Schatten oberhalb der Mittellinie
kathete_top_a = np.abs(b_bottom_x-point_psi_x)
kathete_top_b = np.abs(b_bottom_y-point_psi_y)
len_top = 2*np.sqrt(kathete_top_a**2+kathete_top_b**2)+b
len_bottom = 1
elif b_bottom_y < point_psi_y and b_top_y < point_psi_y: # Schatten unterhalb der Mittellinie
kathete_bottom_a = np.abs(b_top_x-point_psi_x)
kathete_bottom_b = np.abs(b_top_y-point_psi_y)
len_bottom = 2*np.sqrt(kathete_bottom_a**2+kathete_bottom_b**2)+b
len_top = 1
else: # Schatten ober- und unterhalb der Mittellinie
kathete_top_a = np.abs(b_top_x-point_psi_x)
kathete_top_b = np.abs(b_top_y-point_psi_y)
len_top = np.sqrt(kathete_top_a**2+kathete_top_b**2) + 5
kathete_bottom_a = np.abs(b_bottom_x-point_psi_x)
kathete_bottom_b = np.abs(b_bottom_y-point_psi_y)
len_bottom = np.sqrt(kathete_bottom_a**2+kathete_bottom_b**2) + 5
self.plot_line(point_psi_x, point_psi_y, np.pi-psi, len_top, color="k-") # obere Haelfte
self.plot_line(point_psi_x, point_psi_y, 2*np.pi-psi, len_bottom, color="k-") # untere Haelfte
# b an Wand
self.plot_line(b_top_x, b_top_y, 2*np.pi-psi, b, name="b", color='r-')
# Unterer Scheitel
self.ax.plot((0, b_bottom_x), (0, b_bottom_y), 'c-.')
self.ax.plot(b_bottom_x, b_bottom_y, 'kx')
# Oberer Scheitel
self.ax.plot((0, b_top_x), (0, b_top_y), 'c-.')
self.ax.plot(b_top_x, b_top_y, 'kx')
self.ax.axis('equal')
if self.show_legend:
self.ax.legend()
def plot_line(self, pointx, pointy, angle, distance, plot=True, name=None, color='-'):
x = np.cos(angle)*distance+pointx
y = np.sin(angle)*distance+pointy
if plot:
self.ax.plot((pointx,x),(pointy,y),color, label=name)
return x,y
def plot(self):
self.initUI()
plt.show()
if __name__ == '__main__':
vorwaertsproblem = Vorwaertsproblem(show_legend=False)
vorwaertsproblem.plot()