{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Symbolic Coord System Notebook" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import sympy as sp\n", "\n", "from mechpy.core.symbolic.coord import (\n", " SymbolicCoordSystem,\n", " SymbolicCartesianCoordSystem,\n", " SymbolicCylindricalCoordSystem,\n", " SymbolicSphericalCoordSystem,\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Cartesian Coord System" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "SymbolicCartesianCoordSystem(origin=(0, 0, 0), basis=(x, y, z))" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "cartesian_system = SymbolicCartesianCoordSystem()\n", "display(cartesian_system)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Cylindrical Coord System" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "SymbolicCylindricalCoordSystem(origin=(0, 0, 0), basis=(r, theta, z))" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "cylindrical_system = SymbolicCylindricalCoordSystem()\n", "display(cylindrical_system)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Cartesian/Cylindrical Conversion" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "SymbolicCylindricalCoordSystem(origin=(0, 0, 0), basis=(r, theta, z))" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "SymbolicCartesianCoordSystem(origin=(0, 0, 0), basis=(r*cos(theta), r*sin(theta), z))" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "(r*cos(theta), r*sin(theta), z)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "symbolic_cylindrical_system = SymbolicCylindricalCoordSystem()\n", "display(symbolic_cylindrical_system)\n", "new_coord_system = symbolic_cylindrical_system.to_cartesian()\n", "display(new_coord_system)\n", "display(new_coord_system.basis)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "SymbolicCartesianCoordSystem(origin=(0, 0, 0), basis=(x, y, z))" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "SymbolicCylindricalCoordSystem(origin=(0, 0, 0), basis=(sqrt(x**2 + y**2), atan2(y, x), z))" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "(sqrt(x**2 + y**2), atan2(y, x), z)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "symbolic_cartesian_system = SymbolicCartesianCoordSystem()\n", "display(symbolic_cartesian_system)\n", "new_coord_system = symbolic_cartesian_system.to_cylindrical()\n", "display(new_coord_system)\n", "display(new_coord_system.basis)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(5/2, 5*sqrt(3)/2, 2)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "cylindrical_coord = (5, sp.pi/3, 2)\n", "symbolic_cylindrical_system = SymbolicCylindricalCoordSystem()\n", "cartesian_coord = symbolic_cylindrical_system.get_cartesian_coords(cylindrical_coord)\n", "display(cartesian_coord)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(1, pi/2, 1)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "cartesian_coord = (0, 1, 1)\n", "symbolic_cartesian_system = SymbolicCartesianCoordSystem()\n", "cylindrical_coord = symbolic_cartesian_system.get_cylindrical_coord(cartesian_coord)\n", "display(cylindrical_coord)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### using params" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Example 1" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "SymbolicCylindricalCoordSystem(origin=(0, 0, 0), basis=(r, theta, z))" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "(a/2, sqrt(3)*a/2, b)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "symbolic_cylindrical_system = SymbolicCylindricalCoordSystem()\n", "display(symbolic_cylindrical_system)\n", "a, b = sp.symbols(\"a b\", positive=True)\n", "cylindrical_coord = (a, sp.pi/3, b)\n", "cartesian_coord = symbolic_cylindrical_system.get_cartesian_coords(cylindrical_coord)\n", "display(cartesian_coord)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Evaluation" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(1.50000000000000, 2.59807621135332, 5.00000000000000)\n" ] } ], "source": [ "eval_coord = SymbolicCoordSystem.coord_eval(cartesian_coord, subs={a: 3, b: 5})\n", "print(eval_coord)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Example 2" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(a, pi/2, b)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "a, b = sp.symbols(\"a b\", positive=True)\n", "cartesian_coord = (0, a, b)\n", "symbolic_cartesian_system = SymbolicCartesianCoordSystem()\n", "cylindrical_coord = symbolic_cartesian_system.get_cylindrical_coord(cartesian_coord)\n", "display(cylindrical_coord)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Evaluation" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(3.00000000000000, 1.57079632679490, 5.00000000000000)\n" ] } ], "source": [ "eval_coord = SymbolicCoordSystem.coord_eval(cylindrical_coord, subs={a: 3, b: 5})\n", "print(eval_coord)" ] } ], "metadata": { "kernelspec": { "display_name": "venv", "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.10.12" } }, "nbformat": 4, "nbformat_minor": 2 }