{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Car Example" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib widget" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{\n", "'vehicle': {\n", " 'wheels': {\n", " 'wheel1': {\n", " 'wheel': {\n", " 'arc': \"181 (x,y) coords\",},\n", " 'cross': {\n", " 'cross1': {\n", " 'line': \"2 (x,y) coords\",},\n", " 'cross2': {\n", " 'line': \"2 (x,y) coords\",},},},\n", " 'wheel2': {\n", " 'wheel': {\n", " 'arc': \"181 (x,y) coords\",},\n", " 'cross': {\n", " 'cross1': {\n", " 'line': \"2 (x,y) coords\",},\n", " 'cross2': {\n", " 'line': \"2 (x,y) coords\",},},},},\n", " 'body': {\n", " 'under': {\n", " 'rectangle': \"5 (x,y) coords\",},\n", " 'over': {\n", " 'rectangle': \"5 (x,y) coords\",},},},\n", "'ground': {\n", " 'wall': \"4 (x,y) coords fillcolor='white' fillpattern='/'\",},}" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from pysketcher import *\n", "\n", "R = 1 # radius of wheel\n", "L = 4 # distance between wheels\n", "H = 2 # height of vehicle body\n", "w_1 = 5 # position of front wheel\n", "\n", "xmax = w_1 + 2*L + 3*R\n", "drawing_tool.set_coordinate_system(xmin=0, xmax=xmax,\n", " ymin=-1, ymax=2*R + 3*H,\n", " axis=False)\n", "\n", "wheel1 = Composition({\n", " 'wheel': Circle(center=(w_1, R), radius=R),\n", " 'cross': Composition({'cross1': Line((w_1,0), (w_1,2*R)),\n", " 'cross2': Line((w_1-R,R), (w_1+R,R))})})\n", "wheel2 = wheel1.copy()\n", "wheel2.translate((L,0))\n", "\n", "under = Rectangle(lower_left_corner=(w_1-2*R, 2*R),\n", " width=2*R + L + 2*R, height=H)\n", "over = Rectangle(lower_left_corner=(w_1, 2*R + H),\n", " width=2.5*R, height=1.25*H)\n", "\n", "wheels = Composition({'wheel1': wheel1, 'wheel2': wheel2})\n", "body = Composition({'under': under, 'over': over})\n", "\n", "vehicle = Composition({'wheels': wheels, 'body': body})\n", "ground = Wall(x=[R, xmax], y=[0, 0], thickness=-0.3*R)\n", "\n", "fig = Composition({'vehicle': vehicle, 'ground': ground})\n", "fig.draw() # send all figures to plotting backend" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "ae74d9c0c99348429e9caee48e646a0b", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "drawing_tool.mpl.gcf().canvas" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }