{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "id": "WMYGesN_u0od" }, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from mpl_toolkits.mplot3d import Axes3D\n", "\n", "# Constants and functions\n", "r = 0.5 # Radius of the circle\n", "x0 = np.array([1, 1]) # Initial point\n", "\n", "def Y(l):\n", " return np.array([np.cos(l), np.sin(l)])\n", "\n", "# Curves x(s,l)\n", "def x(s, l):\n", " return x0 + r * np.sin(s) * Y(l)\n", "\n", "# Cone function\n", "# This function correctly now calculates a point on the cone based on s, l and t.\n", "def cone(s, l, t):\n", " x_sl = x(s, l)\n", " return np.array([np.cos(t) * x_sl[0], np.sin(t) * x_sl[1], t])\n", "\n", "# Parametric plot of the folded cone (corrected version)\n", "fig = plt.figure()\n", "ax = fig.add_subplot(111, projection='3d')\n", "\n", "# Creating the meshgrid properly using numpy\n", "s = np.linspace(0, np.pi/2, 50) # s (parameter along the arc)\n", "l = np.linspace(0, 2*np.pi, 50) # l (parameter around the circle)\n", "t = np.linspace(0, 1, 50) # t (parameter along the cone height)\n", "\n", "# Using NumPy's broadcasting to compute the cone points - This avoids loops and is efficient.\n", "S, T = np.meshgrid(s, t)\n", "L = np.tile(l, (len(t), 1)).T # This creates a repeated array of l for each t value.\n", "\n", "# Now we evaluate the cone function on the grid points.\n", "# We need to 'vectorize' our cone function for it to work on arrays.\n", "cone_pts = np.vectorize(cone, signature='(),(),()->(n)')(S, L, T)\n", "\n", "# We extract X, Y, Z coordinates for plotting\n", "X = cone_pts[..., 0]\n", "Y = cone_pts[..., 1]\n", "Z = cone_pts[..., 2]\n", "\n", "# Plot the surface. The surface is defined by the X, Y, Z arrays.\n", "ax.plot_surface(X, Y, Z, alpha=0.8, cmap='viridis')\n", "\n", "# Combining the plot with a base circle at the bottom.\n", "# We use the first row of X, Y since it corresponds to the base circle (t=0).\n", "ax.plot(X[0], Y[0], np.zeros_like(X[0]), color='red', linewidth=2)\n", "\n", "# Hide axes for better visibility\n", "plt.axis('off')\n", "\n", "# Show the plot\n", "plt.show()" ] } ] }