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!
=== Assistant: Perfect 👍 — here’s your UTF-8–safe, ready-to-run version of the full script. === Perfect 👍 — here’s your UTF-8–safe, ready-to-run version of the full script. It includes the encoding declaration at the top and replaces problematic degree symbols (°) with "deg" for maximum compatibility on Windows. ===== <syntaxhighlight lang="python"># -''- coding: utf-8 -''- ===== """ GoldenEllipseSpiralCubeSLIDER.py Interactive 3D visualization showing how a circle appears as a Golden Ellipse at specific elevation angles (notably near 51.84 deg — the Great Pyramid angle). Includes buttons and a real-time elevation slider. """ import numpy as np import matplotlib.pyplot as plt from matplotlib.widgets import Button, Slider from mpl_toolkits.mplot3d import Axes3D from mpl_toolkits.mplot3d.art3d import Poly3DCollection class GoldenEllipseSpiralCube: def __init__(self): 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') # Golden ratio and pyramid constants self.phi = (1 + np.sqrt(5)) / 2 self.pyramid_angle = 51.84 # Cube vertices and faces 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] ] 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 elements self.spiral_points = self.create_circle_projection_spiral() self.circle_projection = self.create_circle_projection() self.golden_ellipse_points = self.create_golden_ellipse_projection() # Rotation state self.elev = 30 self.azim = 45 self.dragging = False self.prev_mouse = None # Create interactive components self.create_buttons() self.create_slider() self.setup_plot() self.setup_info_panel() self.connect_events() def create_circle_projection_spiral(self): t = np.linspace(0, 2 * np.pi, 200) spiral_points = [] for angle in t: x = np.cos(angle) y = np.sin(angle) z = -1 + (angle / (2 '' np.pi)) '' 2 spiral_points.append([x, y, z]) return np.array(spiral_points) def create_circle_projection(self): return np.array([[x, y, 1] for x, y, z in self.spiral_points]) def create_golden_ellipse_projection(self): t = np.linspace(0, 2 * np.pi, 100) major_axis = 1.0 minor_axis = major_axis / self.phi ellipse_points = [[major_axis '' np.cos(a), minor_axis '' np.sin(a), 1.0] for a in t] return np.array(ellipse_points) def calculate_perspective_ellipse(self, view_angle): t = np.linspace(0, 2 * np.pi, 100) theta = np.radians(view_angle) minor_axis = np.cos(theta) ellipse_points = [[np.cos(a), minor_axis * np.sin(a), 1.0] for a in t] return np.array(ellipse_points) def create_buttons(self): self.ax_reset = plt.axes([0.3, 0.02, 0.12, 0.04]) self.ax_golden = plt.axes([0.43, 0.02, 0.15, 0.04]) self.ax_pyramid = plt.axes([0.59, 0.02, 0.15, 0.04]) self.button_reset = Button(self.ax_reset, 'Default View') self.button_golden = Button(self.ax_golden, 'Golden Ratio View') self.button_pyramid = Button(self.ax_pyramid, 'Pyramid Angle View') self.button_reset.on_clicked(self.reset_view) self.button_golden.on_clicked(self.reset_to_golden_view) self.button_pyramid.on_clicked(self.reset_to_pyramid_view) def create_slider(self): """Add a slider to control elevation angle interactively.""" slider_ax = plt.axes([0.3, 0.08, 0.45, 0.03]) self.slider_elev = Slider( slider_ax, 'Elevation (deg)', 0, 90, valinit=self.elev, valstep=0.5 ) self.slider_elev.on_changed(self.update_elevation) def update_elevation(self, val): """Update the perspective ellipse dynamically as slider moves.""" self.elev = self.slider_elev.val self.ax.view_init(elev=self.elev, azim=self.azim) # Remove existing red dashed ellipse (if any) for line in self.ax.lines[:]: if line.get_linestyle() == '--': line.remove() # Draw new perspective ellipse perspective_ellipse = self.calculate_perspective_ellipse(self.elev) self.ax.plot3D( perspective_ellipse[:, 0], perspective_ellipse[:, 1], perspective_ellipse[:, 2], color='red', linewidth=2, linestyle='--', alpha=0.8 ) self.fig.canvas.draw_idle() def setup_plot(self): self.ax.clear() # Draw cube for i, face in enumerate(self.faces): vertices = self.vertices[face] poly = Poly3DCollection([vertices], alpha=0.03) poly.set_facecolor(self.face_colors[i]) poly.set_edgecolor('gray') poly.set_linewidth=0.5 self.ax.add_collection3d(poly) # Spiral, circle, and golden ellipse self.ax.plot3D(*self.spiral_points.T, color='black', linewidth=3, alpha=0.8) self.ax.plot3D(*self.circle_projection.T, color='blue', linewidth=3, alpha=0.8) self.ax.plot3D(*self.golden_ellipse_points.T, color='gold', linewidth=4, alpha=0.9) # Perspective ellipse (initial red dashed) perspective_ellipse = self.calculate_perspective_ellipse(self.elev) self.ax.plot3D(*perspective_ellipse.T, color='red', linewidth=2, linestyle='--', alpha=0.8) # Major/minor axis self.ax.plot3D([-1, 1], [0, 0], [1, 1], color='green', linewidth=2) minor_axis_length = 1 / self.phi self.ax.plot3D([0, 0], [-minor_axis_length, minor_axis_length], [1, 1], color='purple', linewidth=2) # Labels self.ax.text(0.6, 0, 1.1, '1.000', color='green', fontweight='bold') self.ax.text(0.1, minor_axis_length/2, 1.1, f'{minor_axis_length:.3f}', color='purple', fontweight='bold') # Limits and style 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.set_title('Golden Ellipse Phenomenon', fontsize=14, fontweight='bold') self.ax.view_init(elev=self.elev, azim=self.azim) self.fig.canvas.draw_idle() def setup_info_panel(self): self.ax_info.clear() self.ax_info.axis('off') minor_axis_length = 1 / self.phi pyramid_minor_axis = np.cos(np.radians(self.pyramid_angle)) pyramid_ratio = 1.0 / pyramid_minor_axis legend_text = ( "VISUAL ELEMENTS EXPLANATION:\n\n" "Black: 3D Spiral\n" "Blue: Perfect Circle (front)\n" "Gold: Golden Ellipse (phi=1.618)\n" "Red dashed: Current Perspective\n" "Green: Major Axis = 1.000\n" "Purple: Minor Axis = 0.618\n\n" "GOLDEN RATIO & PYRAMID CONNECTION:\n\n" f"phi = {self.phi:.6f}\n" f"Pyramid Angle = {self.pyramid_angle} deg\n" f"Ratio ≈ {pyramid_ratio:.6f}\n\n" "At 51.84 deg: Minor Axis ≈ cos(51.84 deg)\n" "→ Matches Golden Ratio visually!\n\n" "CONTROLS:\n" "- Drag to rotate\n" "- Scroll to zoom\n" "- Use buttons for presets\n" "- Move slider to adjust elevation" ) self.ax_info.text(0.05, 0.95, legend_text, transform=self.ax_info.transAxes, fontsize=9, verticalalignment='top', fontfamily='monospace', bbox=dict(boxstyle="round,pad=1", facecolor='lightblue', alpha=0.8)) self.fig.canvas.draw_idle() 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, 0, 90) self.ax.view_init(elev=self.elev, azim=self.azim) self.slider_elev.set_val(self.elev) self.prev_mouse = (event.x, event.y) self.fig.canvas.draw_idle() def on_scroll(self, event): if event.inaxes == self.ax: xlim, ylim, zlim = self.ax.get_xlim(), self.ax.get_ylim(), self.ax.get_zlim() xc, yc, zc = np.mean(xlim), np.mean(ylim), np.mean(zlim) zoom = 0.9 if event.step > 0 else 1.1 xr, yr, zr = (xlim[1]-xlim[0])''zoom, (ylim[1]-ylim[0])''zoom, (zlim[1]-zlim[0])*zoom self.ax.set_xlim([xc-xr/2, xc+xr/2]) self.ax.set_ylim([yc-yr/2, yc+yr/2]) self.ax.set_zlim([zc-zr/2, zc+zr/2]) self.fig.canvas.draw_idle() def reset_view(self, event=None): self.elev, self.azim = 30, 45 self.slider_elev.set_val(self.elev) self.setup_plot() def reset_to_golden_view(self, event=None): self.elev, self.azim = 52, 45 self.slider_elev.set_val(self.elev) self.setup_plot() def reset_to_pyramid_view(self, event=None): self.elev, self.azim = self.pyramid_angle, 45 self.slider_elev.set_val(self.elev) self.setup_plot() def show(self): print("GOLDEN ELLIPSE & GREAT PYRAMID CONNECTION") print("=" * 50) print("At ~51.84 deg elevation → circle appears as golden ellipse (phi≈1.618)") plt.show() === Run the visualization === if __name__ == "__main__": cube = GoldenEllipseSpiralCube() cube.show() </syntaxhighlight> ===== Save the file as ===== GoldenEllipseSpiralCubeSLIDER.py Then in PowerShell or Command Prompt: <syntaxhighlight lang="bash">py GoldenEllipseSpiralCubeSLIDER.py </syntaxhighlight> Would you like me to add a smooth automatic animation that moves the slider back and forth between 0° and 60° (to visually show the ellipse transformation)?
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)