Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/68f40a7c-717c-8000-8af6-a222789ef1d8
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===== π§© GoldenEllipseSpiralCubeSLIDER_SINE_MORPH_SAFE_XYZ_v2.py ===== <syntaxhighlight lang="python"># -''- coding: utf-8 -''- """ GoldenEllipseSpiralCubeSLIDER_SINE_MORPH_SAFE_XYZ_v2.py Fully UTF-8 safe, includes live XYZ coordinate display (4 decimal precision) and smooth sine morph inside the cube. """ import numpy as np import matplotlib.pyplot as plt from matplotlib.widgets import Button from mpl_toolkits.mplot3d.art3d import Poly3DCollection class GoldenEllipseSpiralCube: def __init__(self): # --- Figure layout --- self.fig = plt.figure(figsize=(16, 10)) self.ax = self.fig.add_subplot(121, projection='3d') self.ax_info = self.fig.add_subplot(122) self.ax_info.axis('off') # --- Constants --- self.phi = (1 + np.sqrt(5)) / 2 # Golden ratio self.pyramid_angle = 51.84 # Great Pyramid slope angle (degrees) # --- Cube geometry --- self.vertices = np.array([ [-1, -1, -1], [1, -1, -1], [1, 1, -1], [-1, 1, -1], [-1, -1, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1] ]) self.faces = [ [0, 1, 2, 3], [4, 5, 6, 7], [0, 1, 5, 4], [2, 3, 7, 6], [0, 3, 7, 4], [1, 2, 6, 5] ] # --- Colors --- self.face_colors = [ [1, 0, 0, 0.05], [0, 1, 0, 0.05], [0, 0, 1, 0.05], [1, 1, 0, 0.05], [1, 0, 1, 0.05], [0, 1, 1, 0.05] ] # --- Geometry --- self.spiral_points = self.create_circle_projection_spiral() self.sine_points = self.create_sine_projection() self.morph_t = 0.0 # Morph progress [0-1] # --- View --- self.elev = 30 self.azim = 45 self.dragging = False self.prev_mouse = None # --- Build --- self.create_buttons() self.setup_plot() self.setup_info_panel() self.create_xyz_display() self.connect_events() # =============================================================== # GEOMETRY CREATION # =============================================================== def create_circle_projection_spiral(self): """3D spiral inside cube (perfect circle projection)""" t = np.linspace(0, 2 * np.pi, 200) x = np.cos(t) y = np.sin(t) z = -1 + (t / (2 '' np.pi)) '' 2 return np.column_stack((x, y, z)) def create_sine_projection(self): """Sine wave inside cube aligned with the spiral path""" t = np.linspace(0, 2 * np.pi, 200) x = np.cos(t) y = np.sin(t) '' np.sin(3 '' t) # morphable sine variation z = -1 + (t / (2 '' np.pi)) '' 2 return np.column_stack((x, y, z)) def interpolate_points(self): """Morph between spiral and sine""" return (1 - self.morph_t) '' self.spiral_points + self.morph_t '' self.sine_points # =============================================================== # DISPLAY SETUP # =============================================================== def create_buttons(self): """Bottom control buttons""" self.ax_reset = plt.axes([0.25, 0.02, 0.12, 0.04]) self.ax_morph = plt.axes([0.39, 0.02, 0.12, 0.04]) self.ax_pyramid = plt.axes([0.53, 0.02, 0.15, 0.04]) self.ax_xyz = plt.axes([0.70, 0.02, 0.15, 0.04]) self.button_reset = Button(self.ax_reset, 'Default View') self.button_morph = Button(self.ax_morph, 'Toggle Sine Morph') self.button_pyramid = Button(self.ax_pyramid, 'Pyramid Angle View') self.button_xyz = Button(self.ax_xyz, 'Toggle XYZ Window') self.button_reset.on_clicked(self.reset_view) self.button_morph.on_clicked(self.toggle_sine_morph) self.button_pyramid.on_clicked(self.reset_to_pyramid_view) self.button_xyz.on_clicked(self.toggle_xyz_display) def setup_plot(self): """Initial 3D plot""" self.ax.clear() # Draw cube for i, face in enumerate(self.faces): poly = Poly3DCollection([self.vertices[face]], alpha=0.05) poly.set_facecolor(self.face_colors[i]) poly.set_edgecolor('gray') poly.set_linewidth(0.5) self.ax.add_collection3d(poly) # Draw spiral/sine points = self.interpolate_points() self.ax.plot3D(points[:, 0], points[:, 1], points[:, 2], color='black', linewidth=3) self.ax.set_xlim([-1.5, 1.5]) self.ax.set_ylim([-1.5, 1.5]) self.ax.set_zlim([-1.5, 1.5]) self.ax.set_xlabel('X Axis', fontweight='bold') self.ax.set_ylabel('Y Axis', fontweight='bold') self.ax.set_zlabel('Z Axis', fontweight='bold') self.ax.view_init(elev=self.elev, azim=self.azim) self.ax.set_title('Golden Ellipse Spiral Cube', fontsize=14, fontweight='bold') self.fig.canvas.draw_idle() def setup_info_panel(self): """Right-hand legend""" self.ax_info.clear() self.ax_info.axis('off') text = ( "LEGEND:\n" "Black line: Spiral/Sine Morph\n" "Cube: Transparent structure\n\n" "BUTTONS:\n" "Default View - Reset camera\n" "Toggle Sine Morph - Morph spiral to sine\n" "Pyramid Angle View - Set view to 51.84Β°\n" "Toggle XYZ Window - Show/Hide live coordinates" ) self.ax_info.text(0.05, 0.95, text, transform=self.ax_info.transAxes, fontsize=9, verticalalignment='top', fontfamily='monospace', bbox=dict(boxstyle="round,pad=1", facecolor='lightblue', alpha=0.8, edgecolor='darkblue')) self.fig.canvas.draw_idle() # =============================================================== # XYZ DISPLAY # =============================================================== def create_xyz_display(self): """Small window with XYZ coordinates""" self.ax_text = self.fig.add_axes([0.02, 0.8, 0.2, 0.15]) self.ax_text.axis('off') self.text_box = self.ax_text.text(0, 1, "X: +0.0000\nY: +0.0000\nZ: +0.0000", fontfamily='monospace', fontsize=10, verticalalignment='top', bbox=dict(boxstyle="round,pad=0.3", facecolor='white', alpha=0.8)) self.xyz_visible = True def toggle_xyz_display(self, event=None): """Show/hide XYZ window""" self.xyz_visible = not self.xyz_visible self.ax_text.set_visible(self.xyz_visible) self.fig.canvas.draw_idle() def update_xyz_display(self, point): """Update coordinates in real time""" if not self.xyz_visible: return x, y, z = point self.text_box.set_text(f"X: {x:+.4f}\nY: {y:+.4f}\nZ: {z:+.4f}") self.fig.canvas.draw_idle() # =============================================================== # EVENTS # =============================================================== def connect_events(self): self.fig.canvas.mpl_connect('button_press_event', self.on_press) self.fig.canvas.mpl_connect('button_release_event', self.on_release) self.fig.canvas.mpl_connect('motion_notify_event', self.on_motion) self.fig.canvas.mpl_connect('scroll_event', self.on_scroll) def on_press(self, event): if event.inaxes == self.ax: self.dragging = True self.prev_mouse = (event.x, event.y) def on_release(self, event): self.dragging = False self.prev_mouse = None def on_motion(self, event): if not self.dragging or event.inaxes != self.ax or self.prev_mouse is None: return dx = event.x - self.prev_mouse[0] dy = event.y - self.prev_mouse[1] self.azim += dx * 0.5 self.elev -= dy * 0.5 self.elev = np.clip(self.elev, -90, 90) self.ax.view_init(elev=self.elev, azim=self.azim) self.fig.canvas.draw_idle() self.prev_mouse = (event.x, event.y) def on_scroll(self, event): if event.inaxes == self.ax: scale = 1.1 if event.step > 0 else 0.9 self.ax.set_xlim(np.array(self.ax.get_xlim()) * scale) self.ax.set_ylim(np.array(self.ax.get_ylim()) * scale) self.ax.set_zlim(np.array(self.ax.get_zlim()) * scale) self.fig.canvas.draw_idle() # =============================================================== # VIEW CONTROLS # =============================================================== def reset_view(self, event=None): self.elev = 30 self.azim = 45 self.setup_plot() def reset_to_pyramid_view(self, event=None): self.elev = self.pyramid_angle self.azim = 45 self.setup_plot() def toggle_sine_morph(self, event=None): """Smoothly morph between spiral and sine""" target = 1.0 if self.morph_t < 0.5 else 0.0 steps = 30 for i in range(steps + 1): self.morph_t = self.morph_t + (target - self.morph_t) * 0.1 self.setup_plot() self.update_xyz_display(self.interpolate_points()[-1]) plt.pause(0.03) self.morph_t = target self.setup_plot() self.update_xyz_display(self.interpolate_points()[-1]) # =============================================================== def show(self): """Display""" print("Golden Ellipse Spiral Cube - with sine morph and XYZ display") plt.show() === =============================================================== === === RUN === === =============================================================== === if __name__ == "__main__": cube = GoldenEllipseSpiralCube() cube.show() </syntaxhighlight>
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)