what would be the best recommendation in order to move the 6 blue balls around the 3D field a) with a pygtk and threading matplot for the plot window? (menue in pygtk where the new position is given manually and the balls would move after a "Click Go") b) or something else? It seems that matplot is slow: 4s after starting the attached python script, the plot windows open and everything appear. Moving later manually the window (rotation) is very slow too (it is mandatory, I have access to that manual rotation function of the plot window in order to observe the position of the balls in the 3D field). Perhaps another library or programm should be used? For the reason 6 additional balls (light grey) must be added, it will become probably slow. The 3D rendering dont has to be good (just a bit non transparent 3D). Any recommendation is welcome before I go too far in that pygtk and matplotlib direction. The programm is for hobby sport and will help beginners to know where to have their position in a field and how to move (3D.. NOT 2D)
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import matplotlib.axes as axs
import numpy as np
import math
from pylab import figure
# parameter in m
#swimminpool_width
s_w = 10
#swimmingpool_length
s_l = 18
#swimmingpool_depth
s_d = 4
#exchange lane width
el_w = 3
# ball radius
b_r = 0.53 / (2 * math.pi)
if __name__ == '__main__':
# basket at the swimmingpool bottom in the middle
x_basket1 = s_w / 2
y_basket1 = 0.24
# basket at the swimmingpool bottom in the middle
x_basket2 = s_w / 2
y_basket2 = s_l - 0.24
#
fig = plt.figure()
ax1 = fig.add_subplot (111,projection='3d')
# field
xG = [0,10,10,0,0, 0,10,10,10,10,10, 0, 0,0, 0,10]
yG = [0, 0, 0,0,0,18,18, 0, 0,18,18,18,18,0,18,18]
zG = [0, 0, 4,4,0, 0, 0, 0, 4, 4, 0, 0, 4,4, 4, 4]
ax1.plot_wireframe (xG,yG,zG,colors= (0,0,1,1)) # blue line game area
# exchange area
xW = [10,13,13,10,10,10,13,13,13,13,13,10,10,10,10,13]
yW = [0, 0, 0, 0, 0,18,18, 0, 0,18,18,18,18, 0,18,18]
zW = [0, 0, 4, 4, 0, 0, 0, 0, 4, 4, 0, 0, 4, 4, 4, 4]
ax1.plot_wireframe (xW,yW,zW,colors= (0,1,1,1)) # light blue line exchange area
#
ax1.set_xlabel('Wide')
ax1.set_ylabel('Length')
ax1.set_zlabel('Depth')
#
# Make data for sphere 80cm radius = player1
# pos Player 1
Pos_xP1 = 1
Pos_yP1 = 1
Pos_zP1 = 4
u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
xP1 = Pos_xP1+ 0.4 * np.outer(np.cos(u), np.sin(v))
yP1 = Pos_yP1+ 0.4 * np.outer(np.sin(u), np.sin(v))
zP1 = Pos_zP1+ 0.4 * np.outer(np.ones(np.size(u)), np.cos(v))
# Plot the surface
ax1.plot_surface(xP1, yP1, zP1,color= (0,0,1,1))
#mark it
i=1
ax1.text(Pos_xP1, Pos_yP1, Pos_zP1, '%s' % (str(i)), size=20,color='k')
#
# Make data for sphere 80cm radius = player2
# pos Player 2 (use later lists)?
Pos_xP2 = 2.5
Pos_yP2 = 1
Pos_zP2 = 4
u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
xP2 = Pos_xP2+ 0.4 * np.outer(np.cos(u), np.sin(v))
yP2 = Pos_yP2+ 0.4 * np.outer(np.sin(u), np.sin(v))
zP2 = Pos_zP2+ 0.4 * np.outer(np.ones(np.size(u)), np.cos(v))
# Plot the surface
ax1.plot_surface(xP2, yP2, zP2,color= (0,0,1,1))
#mark it
i=2
ax1.text(Pos_xP2, Pos_yP2, Pos_zP2, '%s' % (str(i)), size=20,color='k')
#
# Make data for sphere 80cm radius = player3
# pos Player 3
Pos_xP3 = 4
Pos_yP3 = 1
Pos_zP3 = 4
u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
xP3 = Pos_xP3+ 0.4 * np.outer(np.cos(u), np.sin(v))
yP3 = Pos_yP3+ 0.4 * np.outer(np.sin(u), np.sin(v))
zP3 = Pos_zP3+ 0.4 * np.outer(np.ones(np.size(u)), np.cos(v))
# Plot the surface
ax1.plot_surface(xP3, yP3, zP3,color= (0,0,1,1))
#mark it
i=3
ax1.text(Pos_xP3, Pos_yP3, Pos_zP3, '%s' % (str(i)), size=20,color='k')
#
# Make data for sphere 80cm radius = player4
# pos Player 4
Pos_xP4 = 5.5
Pos_yP4 = 1
Pos_zP4 = 4
u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
xP4 = Pos_xP4+ 0.4 * np.outer(np.cos(u), np.sin(v))
yP4 = Pos_yP4+ 0.4 * np.outer(np.sin(u), np.sin(v))
zP4 = Pos_zP4+ 0.4 * np.outer(np.ones(np.size(u)), np.cos(v))
# Plot the surface
ax1.plot_surface(xP4, yP4, zP4,color= (0,0,1,1))
#mark it
i=4
ax1.text(Pos_xP4, Pos_yP4, Pos_zP4, '%s' % (str(i)), size=20,color='k')
#
# Make data for sphere 80cm radius = player5
# pos Player 5
Pos_xP5 = 7
Pos_yP5 = 1
Pos_zP5 = 4
u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
xP5 = Pos_xP5+ 0.4 * np.outer(np.cos(u), np.sin(v))
yP5 = Pos_yP5+ 0.4 * np.outer(np.sin(u), np.sin(v))
zP5 = Pos_zP5+ 0.4 * np.outer(np.ones(np.size(u)), np.cos(v))
# Plot the surface
ax1.plot_surface(xP5, yP5, zP5,color= (0,0,1,1))
#mark it
i=5
ax1.text(Pos_xP5, Pos_yP5, Pos_zP5, '%s' % (str(i)), size=20,color='k')
#
# Make data for sphere 80cm radius = player6
# pos Player 6
Pos_xP6 = 8.5
Pos_yP6 = 1
Pos_zP6 = 4
u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
xP6 = Pos_xP6+ 0.4 * np.outer(np.cos(u), np.sin(v))
yP6 = Pos_yP6+ 0.4 * np.outer(np.sin(u), np.sin(v))
zP6 = Pos_zP6+ 0.4 * np.outer(np.ones(np.size(u)), np.cos(v))
# Plot the surface
ax1.plot_surface(xP6, yP6, zP6,color= (0,0,1,1))
#mark it
i=6
ax1.text(Pos_xP6, Pos_yP6, Pos_zP6, '%s' % (str(i)), size=20,color='k')
#
#
# Make data for sphere ball
posx_ball = 5
posy_ball = 9
posz_ball = b_r
u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
x_ball = posx_ball + b_r * np.outer(np.cos(u), np.sin(v))
y_ball = posy_ball + b_r * np.outer(np.sin(u), np.sin(v))
z_ball = posz_ball + b_r * np.outer(np.ones(np.size(u)), np.cos(v))
# Plot the surface
ax1.plot_surface(x_ball, y_ball, z_ball, color=(1, 0, 0, 1))
#
#use a factor for having y = x in factor
ax1.set_aspect(aspect=0.222)
#
# define the basket1
t = np.linspace(0, np.pi * 2, 16)
#bottom
ax1.plot(x_basket1+0.24*np.cos(t), y_basket1+0.24*np.sin(t), 0, linewidth=1, color='black')
ax1.plot(x_basket1+0.16*np.cos(t), y_basket1+0.16*np.sin(t), 0, linewidth=1, color='black')
#top
ax1.plot(x_basket1+0.24*np.cos(t), y_basket1+0.24*np.sin(t), 0.45, linewidth=1, color='black')
# side bars
A=0
while A < 16:
xBar = [x_basket1+ 0.16 * math.sin(A*22.5*np.pi/180),x_basket1+ 0.24 * math.sin(A*22.5*np.pi/180)]
yBar = [y_basket1+ 0.16 * math.cos(A*22.5*np.pi/180),y_basket1+ 0.24 * math.cos(A*22.5*np.pi/180)]
zBar = [0,0.45]
ax1.plot(xBar,yBar,zBar,color='black')
A = A+1
# define the basket2
t = np.linspace(0, np.pi * 2, 16)
# bottom
ax1.plot(x_basket2 + 0.24 * np.cos(t), y_basket2 + 0.24 * np.sin(t), 0, linewidth=1, color='black')
ax1.plot(x_basket2 + 0.16 * np.cos(t), y_basket2 + 0.16 * np.sin(t), 0, linewidth=1, color='black')
# top
ax1.plot(x_basket2 + 0.24 * np.cos(t), y_basket2 + 0.24 * np.sin(t), 0.45, linewidth=1, color='black')
# side bars
A = 0
while A < 16:
xBar = [x_basket2 + 0.16 * math.sin(A * 22.5 * np.pi / 180),x_basket2 + 0.24 * math.sin(A * 22.5 * np.pi / 180)]
yBar = [y_basket2 + 0.16 * math.cos(A * 22.5 * np.pi / 180),y_basket2 + 0.24 * math.cos(A * 22.5 * np.pi / 180)]
zBar = [0, 0.45]
ax1.plot(xBar, yBar, zBar, color='black')
A = A + 1
#
plt.show()