.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/joints/plot_weld_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_weld_joint.py: Weld Joint =========================== Create weld joints Uses: * :class:`b2d.WeldJointDef` * :class:`b2d.WeldJoint` .. 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 import math .. 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-34 The first step with Box2D is the creation of the world. The world is parametrized by a gravity vector. .. GENERATED FROM PYTHON SOURCE LINES 34-82 .. code-block:: default # the world world = b2d.world(gravity=(0, -10)) bodies = [] # create a static body as anchor b = world.create_static_body( position=(0, 4), fixtures=b2d.fixture_def(shape=b2d.polygon_shape(box=[0.3, 0.5])) ) bodies.append(b) for i in range(10): b = world.create_dynamic_body( position=(i + 1.0, 4), fixtures=b2d.fixture_def(shape=b2d.polygon_shape(box=[0.3, 0.5]), density=0.1), linear_damping=2.5, angular_damping=2.5, ) bodies.append(b) for i in range(len(bodies) - 1): a = bodies[i] b = bodies[i + 1] world.create_weld_joint( a, b, local_anchor_a=(0.5, 0.5), local_anchor_b=(-0.5, 0.5), damping=0.1, reference_angle=0, stiffness=20, ) world.create_weld_joint( a, b, local_anchor_a=(0.5, -0.5), local_anchor_b=(-0.5, -0.5), damping=0.1, reference_angle=0, stiffness=20, ) fig, ax, ani = b2d.plot.animate_world(world, world_margin=(10, 10)) 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=73 which is being ignored in favor of frames=73. ani = animation.FuncAnimation( .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 13.251 seconds) .. _sphx_glr_download_tutorials_joints_plot_weld_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_weld_joint.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_weld_joint.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_