Python Forum
Animate the midpoints of a 3d “Rhombic dodecahedron”
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Animate the midpoints of a 3d “Rhombic dodecahedron”
#1
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:

%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()
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:

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() 
The imports are:

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
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.)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python animate live plotting fetching data from Mysql Table dhirajm 6 3,653 Apr-24-2020, 05:07 PM
Last Post: dhirajm
  Animate graph nodes inside a function adamG 0 2,956 Sep-23-2019, 11:18 AM
Last Post: adamG

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020