{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import numpy as np\n", "import pandas as pd\n", "from lets_plot import *\n", "\n", "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def bottle(theta, phi):\n", " x = -2/15*np.cos(theta)*(3*np.cos(phi) - \n", " 30*np.sin(theta) + \n", " 90*np.cos(theta)**4*np.sin(theta) - \n", " 60*np.cos(theta)**6*np.sin(theta) + \n", " 5*np.cos(theta)*np.cos(phi)*np.sin(theta))\n", " y = -1/15*np.sin(theta)*(3*np.cos(phi) - \n", " 3*np.cos(theta)**2*np.cos(phi) - \n", " 48*np.cos(theta)**4*np.cos(phi) + \n", " 48*np.cos(theta)**6*np.cos(phi) - 60*np.sin(theta) + \n", " 5*np.cos(theta)*np.cos(phi)*np.sin(theta) -\n", " 5*np.cos(theta)**3*np.cos(phi)*np.sin(theta)-\n", " 80*np.cos(theta)**5*np.cos(phi)*np.sin(theta)+\n", " 80*np.cos(theta)**7*np.cos(phi)*np.sin(theta))\n", " z = 2/15*(3 + 5*np.cos(theta)*np.sin(theta))*np.sin(phi)\n", " return x, y, z" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "n = 100" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "theta = np.linspace(0, np.pi, n)\n", "phi = np.linspace(0, 2*np.pi, n)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "thetas, phis = np.meshgrid(theta, phi)\n", "theta, phi = thetas.reshape(-1), phis.reshape(-1)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "x, y, z = bottle(theta, phi)\n", "X = np.vstack((x, y, z)).T" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "def rotation_matrices(theta_x, theta_y, theta_z):\n", " Rx = [[1, 0, 0],\n", " [0, np.cos(theta_x), -np.sin(theta_x)],\n", " [0, np.sin(theta_x), np.cos(theta_x)]]\n", " Ry = [[np.cos(theta_y), 0, np.sin(theta_y)], \n", " [0, 1, 0], \n", " [-np.sin(theta_y), 0, np.cos(theta_y)]]\n", " Rz = [[np.cos(theta_z), -np.sin(theta_z), 0], \n", " [np.sin(theta_z), np.cos(theta_z), 0], \n", " [0, 0, 1]]\n", " return Rx, Ry, Rz" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "Rx, Ry, Rz = rotation_matrices(np.pi/6, np.pi/6, np.pi/6)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "X_rotated = ((X.dot(Rx)).dot(Ry)).dot(Rz)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "data = pd.DataFrame(X_rotated, columns=['x', 'y', 'z'])\n", "data['cross-sectional'] = np.tile(np.arange(n), n)\n", "data['longitudinal'] = np.repeat(np.arange(n), n)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p = ggplot(data) \\\n", " + geom_path(aes(x='x', y='y', group='longitudinal'), alpha=0.5, color='gray', sampling='none')\n", "p += theme(axis_text='blank', axis_ticks='blank', axis_line='blank', axis_title='blank')\n", "p" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p += geom_path(aes(x='x', y='y', group='cross-sectional'), alpha=0.2, color='gray', sampling='none')\n", "p" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.9.5" } }, "nbformat": 4, "nbformat_minor": 2 }