diff --git a/Matplot2D3D/README.md b/Matplot2D3D/README.md index 3d5a990..ba8a59c 100644 --- a/Matplot2D3D/README.md +++ b/Matplot2D3D/README.md @@ -10,3 +10,4 @@ ![ Heart ](images/Heart.png) ![ Normal Distribution ](images/Normal%20Distribution.png) ![ Prime Shape ](images/Prime%20Number%20Pattern.png) + ![ 3D Rose ](images/rose.png) diff --git a/Matplot2D3D/Rose in 3D.ipynb b/Matplot2D3D/Rose in 3D.ipynb new file mode 100644 index 0000000..add048c --- /dev/null +++ b/Matplot2D3D/Rose in 3D.ipynb @@ -0,0 +1,170 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "2497e56d", + "metadata": { + "ExecuteTime": { + "end_time": "2025-02-08T08:19:55.565311Z", + "start_time": "2025-02-08T08:19:55.554528Z" + } + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "import plotly.graph_objects as go" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "4380965b", + "metadata": { + "ExecuteTime": { + "end_time": "2025-02-08T08:19:56.693970Z", + "start_time": "2025-02-08T08:19:56.683889Z" + } + }, + "outputs": [], + "source": [ + "def generate_rose_points(\n", + " resolution=800, \n", + " petal_width_factor=1.995653, \n", + " petal_height_factor=1.27689, \n", + " petal_falloff=8, \n", + " petals_per_cycle=3.6\n", + "):\n", + " \"\"\"Generate X, Y, Z coordinates for the 3D rose shape.\"\"\"\n", + " \n", + " # Define radial and angular values\n", + " radius_values = np.linspace(0, 1, resolution)\n", + " angle_values = np.linspace(-2, 20 * np.pi, resolution)\n", + " R, THETA = np.meshgrid(radius_values, angle_values)\n", + "\n", + " # Shape modifier to control petal curvature\n", + " petal_shape = 1 - 0.5 * ((5/4) * (1 - np.mod(petals_per_cycle * THETA, 2 * np.pi) / np.pi)**2 - 1/4)**2\n", + "\n", + " # Angle distortion to create a smooth petal falloff effect\n", + " angle_falloff = (np.pi / 2) * np.exp(-THETA / (petal_falloff * np.pi))\n", + "\n", + " # Petal thickness based on radius and height factors\n", + " petal_thickness = petal_width_factor * (R**2) * (petal_height_factor * R - 1)**2 * np.sin(angle_falloff)\n", + "\n", + " # Adjust petal shape with curvature\n", + " adjusted_radius = petal_shape * (R * np.sin(angle_falloff) + petal_thickness * np.cos(angle_falloff))\n", + " \n", + " # Convert to Cartesian coordinates\n", + " X = adjusted_radius * np.sin(THETA)\n", + " Y = adjusted_radius * np.cos(THETA)\n", + " Z = petal_shape * (R * np.cos(angle_falloff) - petal_thickness * np.sin(angle_falloff))\n", + " \n", + " return X, Y, Z\n", + "\n", + "def plot_rose(X, Y, Z):\n", + " \"\"\"Plot the 3D rose using Plotly.\"\"\"\n", + " \n", + " # Define red color gradient\n", + " color_gradient = [[0, 'rgb(255,0,0)'], [1, 'rgb(64,0,0)']] # Bright red to dark red\n", + " \n", + " # Create the 3D surface plot\n", + " fig = go.Figure(data=[go.Surface(x=X, y=Y, z=Z, colorscale=color_gradient, showscale=False)])\n", + "\n", + " # Set camera angle and labels\n", + " fig.update_layout(\n", + " title=\"3D Rose 🌹\",\n", + " scene=dict(\n", + " xaxis_title=\"Width\",\n", + " yaxis_title=\"Depth\",\n", + " zaxis_title=\"Height\",\n", + " camera=dict(eye=dict(x=-1.5, y=-1.5, z=1.5))\n", + " )\n", + " )\n", + " \n", + " fig.show()" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "02bde749", + "metadata": { + "ExecuteTime": { + "end_time": "2025-02-08T08:19:58.253396Z", + "start_time": "2025-02-08T08:19:58.187427Z" + } + }, + "outputs": [], + "source": [ + "# Generate and plot the 3D rose\n", + "X, Y, Z = generate_rose_points()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "81647308", + "metadata": { + "ExecuteTime": { + "end_time": "2025-02-08T08:06:45.511388Z", + "start_time": "2025-02-08T08:06:41.247723Z" + }, + "scrolled": false + }, + "outputs": [], + "source": [ + "plot_rose(X, Y, Z)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.5" + }, + "varInspector": { + "cols": { + "lenName": 16, + "lenType": 16, + "lenVar": 40 + }, + "kernels_config": { + "python": { + "delete_cmd_postfix": "", + "delete_cmd_prefix": "del ", + "library": "var_list.py", + "varRefreshCmd": "print(var_dic_list())" + }, + "r": { + "delete_cmd_postfix": ") ", + "delete_cmd_prefix": "rm(", + "library": "var_list.r", + "varRefreshCmd": "cat(var_dic_list()) " + } + }, + "types_to_exclude": [ + "module", + "function", + "builtin_function_or_method", + "instance", + "_Feature" + ], + "window_display": false + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/Matplot2D3D/images/rose.png b/Matplot2D3D/images/rose.png new file mode 100644 index 0000000..c7dd479 Binary files /dev/null and b/Matplot2D3D/images/rose.png differ diff --git a/README.md b/README.md index ebde138..7a3188c 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,9 @@ ## **Matplot 2D & 3D [ Link ](Matplot2D3D)** - ![ Heart ](Matplot2D3D/images/Heart.png) + ![ Heart ](Matplot2D3D/images/rose.png) * There is also: + * 3D Rose * 3D Normal distribution shape * Prime number shape * Random sine shape