Nov-05-2022, 04:18 PM
I need help in animating a Rhombic dodecahedron. I want to enlarge and to shrink the midpoints (center points) with FuncAnimation from Matplotlib. I wanted to use the δ for this (make smaller/bigger) and for this an animation. But just don't know how. I successfully created a 3d Rhombic dodecahedron but now I'm stuck... .
This is the code:
I tried to animate it with older code which I used to animate a 2d graph but I couldn't really figure it out because I'm new to this stuff.
This is the old 2d animation code for the graph which I tried to reuse with some adjustments:
The imports are:
Could someone help with code examples/working 3d animations for the midpoints of the 3d "Rhombic dodecahedron"? I'm stuck for some hours now... .
(I tried to reuse the old code for a 2d graph animation, then I tried some adjustments to it to make it 3d and fitting for the "Rhombic dodecahedron" but I couldn't really get it to work at all. English is not my native language and I'm beginner with python so it would be nice if you could be considerate about it.)
This is the code:
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 |
% matplotlib notebook fig = plt.figure() ax = Axes3D(fig) δ = symbols( 'δ' ) δ = 0.3 points = [ ( 0.5 , 0.5 , 0.5 ), ( 0.5 , 0.5 , - 0.5 ), ( 0.5 , - 0.5 , 0.5 ), ( 0.5 , - 0.5 , - 0.5 ), ( - 0.5 , 0.5 , 0.5 ), ( - 0.5 , 0.5 , - 0.5 ), ( - 0.5 , - 0.5 , 0.5 ), ( - 0.5 , - 0.5 , - 0.5 ), ( 0 , 0 ,( 0.5 + δ)), ( 0 , 0 , - ( 0.5 + δ)), ( 0 ,( 0.5 + δ), 0 ), ( 0 , - ( 0.5 + δ), 0 ), (( 0.5 + δ), 0 , 0 ), ( - ( 0.5 + δ), 0 , 0 ) ] surfaces = [ [points[ 0 ], points[ 1 ], points[ 12 ]], #front [points[ 1 ], points[ 3 ], points[ 12 ]], [points[ 3 ], points[ 2 ], points[ 12 ]], [points[ 2 ], points[ 0 ], points[ 12 ]], [points[ 6 ], points[ 4 ], points[ 13 ]], #behind [points[ 4 ], points[ 5 ], points[ 13 ]], [points[ 5 ], points[ 7 ], points[ 13 ]], [points[ 7 ], points[ 6 ], points[ 13 ]], [points[ 6 ], points[ 4 ], points[ 8 ]], #top [points[ 4 ], points[ 0 ], points[ 8 ]], [points[ 0 ], points[ 2 ], points[ 8 ]], [points[ 2 ], points[ 6 ], points[ 8 ]], [points[ 3 ], points[ 1 ], points[ 9 ]], #below [points[ 1 ], points[ 5 ], points[ 9 ]], [points[ 5 ], points[ 7 ], points[ 9 ]], [points[ 7 ], points[ 3 ], points[ 9 ]], [points[ 0 ], points[ 4 ], points[ 10 ]], #right [points[ 4 ], points[ 5 ], points[ 10 ]], [points[ 5 ], points[ 1 ], points[ 10 ]], [points[ 1 ], points[ 0 ], points[ 10 ]], [points[ 2 ], points[ 6 ], points[ 11 ]], #left [points[ 6 ], points[ 7 ], points[ 11 ]], [points[ 7 ], points[ 3 ], points[ 11 ]], [points[ 3 ], points[ 2 ], points[ 11 ]] ] ax.set_xlim3d( - 1 , 1 ) ax.set_ylim3d( - 1 , 1 ) ax.set_zlim3d( - 1 , 1 ) ax.add_collection3d(Poly3DCollection(surfaces, edgecolors = "k" )) fig.show() |
This is the old 2d animation code for the graph which I tried to reuse with some adjustments:
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 |
fig, ax = plt.subplots() xdata, ydata = [], [] ln, = plt.plot([], [], '-' ) xdata = np.linspace( 1 , 5 , 2000 ) def afunc(frame): result = [] for i in xdata: result.append(np.sin( 3 * i + frame)) return result def init(): ax.set_xlim( 1 , 5 ) ax.set_ylim( - 1 , 1 ) ax.spines[ 'left' ].set_position( 'center' ) ax.spines[ 'bottom' ].set_position( 'center' ) ax.spines[ 'right' ].set_color( 'none' ) ax.spines[ 'top' ].set_color( 'none' ) return ln def update(frame): ydata = afunc(frame) ln.set_data(xdata, ydata) return ln step = 100 frames = np.arange( 0 , 1001 , step) ani = FuncAnimation(fig, update, frames,init_func = init, interval = 30 ) plt.show() |
1 2 3 4 5 6 7 8 9 |
from mpmath import * from sympy import * from sympy.interactive import printing import matplotlib.pyplot as plt import numpy as np from matplotlib.animation import FuncAnimation from sympy.plotting import plot3d from mpl_toolkits.mplot3d import Axes3D from mpl_toolkits.mplot3d.art3d import Poly3DCollection |
(I tried to reuse the old code for a 2d graph animation, then I tried some adjustments to it to make it 3d and fitting for the "Rhombic dodecahedron" but I couldn't really get it to work at all. English is not my native language and I'm beginner with python so it would be nice if you could be considerate about it.)