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!
== gpt-5-t-mini == === User: stay inside the cube === stay inside the cube === Assistant: Nice β I updated the script so the Toggle Sine Projection now shows a smooth 3D transition that begins where the spiralβ¦ === Nice β I updated the script so the Toggle Sine Projection now shows a smooth 3D transition that begins where the spiral reaches the top of the cube (z = 1) and then "unfolds" into a sine-like wave inside the cube (x in [-1,1], y oscillating, z falling gently toward 0). The curve stays entirely inside the cube bounds. Copy the code below into a file named GoldenEllipseSpiralCube_SINE_3D_SAFE.py and run: <syntaxhighlight>py GoldenEllipseSpiralCube_SINE_3D_SAFE.py </syntaxhighlight> No fancy characters, fully ASCII-safe. <syntaxhighlight lang="python"># -''- coding: utf-8 -''- """ Golden Ellipse Spiral Cube Visualization (with 3D Sine Transition) Safe ASCII-only version. Toggle shows a smooth 3D sine that starts where the spiral meets the top of the cube and unfolds inside the cube volume. """ import numpy as np import matplotlib.pyplot as plt from matplotlib.widgets import Button, Slider 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") # Constants self.phi = (1 + np.sqrt(5)) / 2 self.pyramid_angle = 51.84 # 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] ] 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] ] # Create geometry self.spiral_points = self.create_circle_projection_spiral() self.circle_projection = self.create_circle_projection() self.golden_ellipse_points = self.create_golden_ellipse_projection() # View state self.elev = 30 self.azim = 45 self.dragging = False self.prev_mouse = None # Sine transition state # create the 3D transition curve but do not display until toggled self.sine_transition_points = self.create_sine_transition() self.sine_visible = False self.sine_line = None # UI self.create_buttons() self.create_slider() self.setup_plot() self.setup_info_panel() self.connect_events() # Geometry generators -------------------------------------- def create_circle_projection_spiral(self): t = np.linspace(0, 2 * np.pi, 400) x = np.cos(t) y = np.sin(t) z = -1.0 + (t / (2 '' np.pi)) '' 2.0 return np.column_stack((x, y, z)) def create_circle_projection(self): s = self.spiral_points return np.column_stack((s[:, 0], s[:, 1], np.ones_like(s[:, 2]))) def create_golden_ellipse_projection(self): t = np.linspace(0, 2 * np.pi, 200) major = 1.0 minor = major / self.phi x = major * np.cos(t) y = minor * np.sin(t) z = np.ones_like(x) return np.column_stack((x, y, z)) def calculate_perspective_ellipse(self, view_angle): t = np.linspace(0, 2 * np.pi, 200) minor = np.cos(np.radians(view_angle)) x = np.cos(t) y = minor * np.sin(t) z = np.ones_like(x) return np.column_stack((x, y, z)) def create_sine_transition(self): """ Create a 3D curve that starts at the spiral's top point (z ~= 1), then smoothly transitions into a sine-like wave that stays inside the cube. The curve is inside cube bounds: x,y,z in [-1,1]. """ # find the spiral point at the top (z close to 1). This will be the start. # spiral points run z from -1 to +1; take the last few points for a smooth join spiral = self.spiral_points # find index of the point with max z (should be near end) idx = np.argmax(spiral[:, 2]) start_block = spiral[max(0, idx - 6): idx + 1] # few points to smoothly join # Transition part parameters N = 450 # number of points for the transition wave u = np.linspace(0.0, 1.0, N) # Start x,y,z are the last spiral point values start_pt = spiral[idx] start_x, start_y, start_z = float(start_pt[0]), float(start_pt[1]), float(start_pt[2]) # Target x range: move from the start x toward -1 then sweep across to +1 # We'll make a two-segment path for nicer shape: first move inward in x, then sweep across # Segment A: from start_x to -0.2 (bringing it toward cube interior) # Segment B: from -0.2 to +1.0 (a sine sweep across) Na = int(N * 0.35) Nb = N - Na ua = np.linspace(0.0, 1.0, Na) ub = np.linspace(0.0, 1.0, Nb) # Segment A: gentle inward move with small oscillation x_a = start_x + ( -0.2 - start_x ) * ua y_a = start_y '' (1 - 0.6 '' ua) + 0.15 '' np.sin(4.0 '' np.pi * ua) # small taper and wiggle z_a = start_z - 0.4 * ua # drop a bit from top toward interior # Segment B: main sine sweep across internal x range x_b = -0.2 + (1.0 + 0.2) * ub # from -0.2 to +1.0 # amplitude tapers slightly toward the end to keep inside cube amp = 0.5 '' (1 - 0.5 '' ub) y_b = amp '' np.sin(4.0 '' np.pi '' ub + np.pi '' 0.5) # phase shift so it connects smoothly z_b = (start_z - 0.4) - ( (start_z - 0.4) - 0.0 ) '' ub '' 0.9 # drop toward z=0 # Combine segments x = np.concatenate((x_a, x_b)) y = np.concatenate((y_a, y_b)) z = np.concatenate((z_a, z_b)) # Ensure values clamp inside [-1,1] x = np.clip(x, -1.0, 1.0) y = np.clip(y, -1.0, 1.0) z = np.clip(z, -1.0, 1.0) # Prepend the small final portion of the spiral to make the join seamless pts = np.vstack((start_block, np.column_stack((x, y, z)))) return pts # UI -------------------------------------------------------- def create_buttons(self): self.ax_reset = plt.axes([0.18, 0.02, 0.12, 0.04]) self.ax_golden = plt.axes([0.31, 0.02, 0.15, 0.04]) self.ax_pyramid = plt.axes([0.47, 0.02, 0.15, 0.04]) self.ax_sine = plt.axes([0.63, 0.02, 0.20, 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_sine = Button(self.ax_sine, "Toggle Sine Transition") 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) self.button_sine.on_clicked(self.toggle_sine_transition) def create_slider(self): ax_slider = plt.axes([0.3, 0.08, 0.45, 0.03]) self.slider_elev = Slider(ax_slider, "Elevation (deg)", 0, 90, valinit=self.elev, valstep=0.5) self.slider_elev.on_changed(self.update_elevation) def update_elevation(self, val): self.elev = self.slider_elev.val self.ax.view_init(elev=self.elev, azim=self.azim) # remove previous dashed perspective ellipse for line in self.ax.lines[:]: if line.get_linestyle() == "--": line.remove() p = self.calculate_perspective_ellipse(self.elev) self.ax.plot3D(p[:, 0], p[:, 1], p[:, 2], color="red", lw=2, ls="--", alpha=0.8) self.fig.canvas.draw_idle() # Plot setup ------------------------------------------------ def setup_plot(self): self.ax.clear() # reset sine display state when rebuilding full plot self.sine_line = None self.sine_visible = False # draw cube faces for i, face in enumerate(self.faces): poly = Poly3DCollection([self.vertices[face]], alpha=0.03) poly.set_facecolor(self.face_colors[i]) poly.set_edgecolor("gray") self.ax.add_collection3d(poly) # draw shapes s = self.spiral_points c = self.circle_projection g = self.golden_ellipse_points p = self.calculate_perspective_ellipse(self.elev) self.ax.plot3D(s[:, 0], s[:, 1], s[:, 2], color="black", lw=2.8) self.ax.plot3D(c[:, 0], c[:, 1], c[:, 2], color="blue", lw=3) self.ax.plot3D(g[:, 0], g[:, 1], g[:, 2], color="gold", lw=4) self.ax.plot3D(p[:, 0], p[:, 1], p[:, 2], color="red", lw=2, ls="--", alpha=0.8) 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") self.ax.set_ylabel("Y Axis") self.ax.set_zlabel("Z Axis") 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") pyramid_minor = np.cos(np.radians(self.pyramid_angle)) pyramid_ratio = 1.0 / pyramid_minor info = ( "VISUAL ELEMENTS:\n\n" "Black: Spiral inside cube\n" "Blue: Circle (front projection)\n" "Gold: Golden Ellipse (phi=1.618)\n" "Red dashed: Perspective ellipse\n" "Orange: Sine transition (toggle)\n\n" f"Golden Ratio phi = {self.phi:.6f}\n" f"Pyramid Angle = {self.pyramid_angle} degrees\n" f"Pyramid ratio = {pyramid_ratio:.6f}\n\n" "Controls:\n" "Drag to rotate\n" "Scroll to zoom\n" "Buttons for preset views\n" "Slider for elevation" ) self.ax_info.text(0.05, 0.95, info, transform=self.ax_info.transAxes, fontsize=9, va="top", fontfamily="monospace", bbox=dict(boxstyle="round,pad=1", facecolor="lightblue", alpha=0.8, edgecolor="darkblue")) self.fig.canvas.draw_idle() # Interaction ----------------------------------------------- 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: return dx, dy = event.x - self.prev_mouse[0], 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) # keep slider synced if user rotates manually try: self.slider_elev.set_val(self.elev) except Exception: pass self.fig.canvas.draw_idle() self.prev_mouse = (event.x, event.y) def on_scroll(self, event): if event.inaxes != self.ax: return 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 = 1.1 if event.step > 0 else 0.9 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() # Toggle the 3D sine transition ---------------------------- def toggle_sine_transition(self, event=None): if self.sine_visible: if self.sine_line: self.sine_line.remove() self.sine_line = None self.sine_visible = False else: pts = self.sine_transition_points # plot as a thick orange line self.sine_line, = self.ax.plot3D(pts[:, 0], pts[:, 1], pts[:, 2], color="orange", linewidth=3.0, alpha=0.95) self.sine_visible = True self.fig.canvas.draw_idle() # View presets ---------------------------------------------- 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 Spiral Cube (with 3D Sine Transition)") print("Controls: rotate, zoom, slider for elevation, toggle sine transition") plt.show() if __name__ == "__main__": cube = GoldenEllipseSpiralCube() cube.show() </syntaxhighlight> If you want further tweaks, I can: * animate the transition (morph the spiral into the sine path over a short time), or * make the sine ribbon thicker or semi-transparent, or * change frequency/amplitude to better match the spiral visually. Which one shall I add next?
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)