.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/joints/plot_wheel_joint.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorials_joints_plot_wheel_joint.py: Wheel Joint =========================== Create a car with two wheel and wheel joints Uses: * :class:`b2d.WheelJointDef` * :class:`b2d.WheelJoint` .. GENERATED FROM PYTHON SOURCE LINES 14-18 Imports ------------------------ pyb2d is imported as `b2d` .. GENERATED FROM PYTHON SOURCE LINES 18-22 .. code-block:: default import b2d import numpy as np .. GENERATED FROM PYTHON SOURCE LINES 23-25 These imports are only needed for plotting. `b2d.plot` requires OpenCV to be installed! .. GENERATED FROM PYTHON SOURCE LINES 25-30 .. code-block:: default import b2d.plot import matplotlib.pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 31-32 The world and ground body .. GENERATED FROM PYTHON SOURCE LINES 32-48 .. code-block:: default world = b2d.world(gravity=(0, -10)) edge = world.create_static_body( position=(0, 0), fixtures=b2d.fixture_def(shape=b2d.edge_shape([(-20, 0), (5, 0)])) ) # random slope x = np.linspace(5, 50, 10) y = np.random.rand(10) * 4 - 2 y[0] = 0 xy = np.stack([x, y]).T xy = np.flip(xy, axis=0) edge = world.create_static_body( position=(0, 0), fixtures=b2d.fixture_def(shape=b2d.chain_shape(xy, prev_vertex=(10, 0))), ) .. GENERATED FROM PYTHON SOURCE LINES 49-50 create car .. GENERATED FROM PYTHON SOURCE LINES 50-81 .. code-block:: default left_wheel = world.create_dynamic_body( position=(-3, 2), fixtures=b2d.fixture_def(shape=b2d.circle_shape(radius=2), density=1), ) right_wheel = world.create_dynamic_body( position=(3, 2), fixtures=b2d.fixture_def(shape=b2d.circle_shape(radius=2), density=1), ) chasis = world.create_dynamic_body( position=(0, 2), fixtures=b2d.fixture_def(shape=b2d.polygon_shape(box=[3, 0.5]), density=1), ) wheel_joint_def = dict( stiffness=10, enable_motor=True, motor_speed=-100, max_motor_torque=100, collide_connected=False, enable_limit=True, lower_translation=-0.4, upper_translation=0.4, local_axis_a=(0, 1), ) world.create_wheel_joint(chasis, left_wheel, local_anchor_a=(-3, 0), **wheel_joint_def) world.create_wheel_joint(chasis, right_wheel, local_anchor_a=(3, 0), **wheel_joint_def) fig, ax, ani = b2d.plot.animate_world(world, world_margin=(10, 10), t=5) ani plt.show() .. container:: sphx-glr-animation .. raw:: html
.. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/.local/lib/python3.10/site-packages/b2d/plot.py:128: UserWarning: You passed in an explicit save_count=121 which is being ignored in favor of frames=121. ani = animation.FuncAnimation( .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 32.587 seconds) .. _sphx_glr_download_tutorials_joints_plot_wheel_joint.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_wheel_joint.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_wheel_joint.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_