Commit a5b5e8be authored by Leon Schlegel's avatar Leon Schlegel
Browse files

Merge branch 'GUI2' of https://collaborating.tuhh.de/czr0500/maxey-riley into GUI2

parents 718f22c3 ff7ce85d
......@@ -156,11 +156,11 @@ class my_GUI(object):
def InitCanvas(self):
self.fig = plt.Figure(figsize=(10,10), dpi=100)
self.fig = plt.Figure(figsize=(7,7), dpi=100)
self.ax = self.fig.add_subplot()
self.fig.tight_layout(pad = 0)
self.fig.subplots_adjust(left=0.03, bottom=0.07, right=0.98, top=0.97, wspace=0, hspace=0)
self.fig.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=None)
self.canvas = FigureCanvasTkAgg(self.fig, master = self.root)
self.myCanvas = self.canvas.get_tk_widget()
......@@ -173,13 +173,30 @@ class my_GUI(object):
def canvasToPos(self, x, y):
xPos = self.x_left + (self.x_right-self.x_left)/self.CanvasWidth*x
yPos = self.y_down + (self.y_up-self.y_down)/self.CanvasHeight*(self.CanvasHeight-y)
#x = 45, y = 65 is the upper left corner of the plot
x1 = 45
y1 = 65
#x = 835, y = 815 is the lower right corner
x2 = 835
y2 = 815
# xPos = self.x_left + (self.x_right-self.x_left)/self.CanvasWidth*x
# yPos = self.y_down + (self.y_up-self.y_down)/self.CanvasHeight*(self.CanvasHeight-y)
xPos = self.x_left + (self.x_right-self.x_left)/(x2-x1)*(x-x1)
yPos = self.y_down + (self.y_up-self.y_down)/(y2-y1)*(y2-y)
return xPos, yPos
def PosToCanvas(self, xPos, yPos):
x = self.CanvasWidth/(self.x_right-self.x_left)*(xPos-self.x_left)
y = self.CanvasHeight - self.CanvasHeight/(self.y_up-self.y_down)*(yPos-self.y_down)
#x = 45, y = 65 is the upper left corner of the plot
x1 = 45
y1 = 65
#x = 835, y = 815 is the lower right corner
x2 = 835
y2 = 815
# x = self.CanvasWidth/(self.x_right-self.x_left)*(xPos-self.x_left)
# y = self.CanvasHeight - self.CanvasHeight/(self.y_up-self.y_down)*(yPos-self.y_down)
x = x1+(x2-x1)/(self.x_right-self.x_left)*(xPos-self.x_left)
y = y2 - (y2-y1)/(self.y_up-self.y_down)*(yPos-self.y_down)
return x,y
def click(self, event):
......@@ -200,10 +217,7 @@ class my_GUI(object):
taxis = np.linspace(self.t, min(self.t+tmax, self.tend), nt)
dt = taxis[1] - taxis[0]
if Case_v[Case_elem] == Case_v[2]:
u0, v0 = 0.0015, 0.0015
else:
u0, v0 = vel.get_velocity(x0, y0, self.t)
u0, v0 = vel.get_velocity(x0, y0, self.t)
IMEX_particle = maxey_riley_imex(1, np.array([x0, y0]),
np.array([u0, v0]), self.vel,
......@@ -243,9 +257,12 @@ class my_GUI(object):
else:
particle.update()
x1, y1 = self.PosToCanvas(particle.pos_vec[tt-1][0],particle.pos_vec[tt-1][1])
x2, y2 = self.PosToCanvas(particle.pos_vec[tt][0],particle.pos_vec[tt][1])
self.myCanvas.create_line(x1, y1, x2, y2, width = 5, tags = "traj", fill = "red")
x1, y1 = particle.pos_vec[tt-1][0],particle.pos_vec[tt-1][1]
x2, y2 = particle.pos_vec[tt][0],particle.pos_vec[tt][1]
x1C, y1C = self.PosToCanvas(x1,y1)
x2C, y2C = self.PosToCanvas(x2,y2)
if (x1 < self.x_right) and (x1 > self.x_left) and (x2 < self.x_right) and (x2 > self.x_left) and (y1 < self.y_up) and (y1 > self.y_down) and (y2 < self.y_up) and (y2 > self.y_down):
self.myCanvas.create_line(x1C, y1C, x2C, y2C, width = 5, tags = "traj", fill = "red")
# x1, y1 = particle.pos_vec[tt-1][0], particle.pos_vec[tt-1][1]
# x2, y2 = particle.pos_vec[tt][0], particle.pos_vec[tt][1]
# self.ax.plot([x1, x2], [y1, y2], 'g-')
......@@ -258,8 +275,8 @@ class my_GUI(object):
self.root.after(int((particle.dt-timeDiff)*1000), self.updateParticle, particle, tt+1, nt)
def move(self, event):
x0 ,y0 = self.canvasToPos(event.x,event.y)
x0 ,y0 = (event.x,event.y)
self.xPosLabel.config(text = "x: "+"{0:.2f}".format(x0))
self.yPosLabel.config(text = "y: "+"{0:.2f}".format(y0))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment