constraints¶
- class VConstraint(**kwargs)[source]¶
Bases:
VGroupThe Manim base class for visualizing Pymunk physical constraints.
- animation_overrides = {}¶
- install(space)[source]¶
Installs physical constraints into the Pymunk physical space. This method should be overridden by subclasses to implement the following:
Create Pymunk constraint objects
Initialize the vision component
Add constraints to the physical space
Bind an updater to keep the vision synchronized.
- Parameters:
space (Space)
- class VDampedRotarySpring(a_mob, b_mob, rest_angle=0.0, stiffness=10.0, damping=1.0, arc_indicator_class=<class 'manim.mobject.geometry.arc.Arc'>, arc_indicator_config={'color': ManimColor('#FC6255'), 'radius': 0.1, 'stroke_width': 4}, connect_line_class=None, connect_line_config={'color': ManimColor('#F7D96F'), 'stroke_width': 2}, **kwargs)[source]¶
Bases:
VConstraintA rotational spring connection is created between the two rigid bodies. When the actual relative angle deviates from the target angle, the spring torque pulls it back; the damping torque dampens the oscillation.
Parameters¶
- a_mob
The first Mobject to be connected. Typically acts as the pivot point or one of the bodies under physical influence.
- b_mob
The second Mobject to be connected. It is linked to a_mob via a physical constraint such as a spring or hinge.
- rest_angle
The equilibrium angle (in radians). The target angle between the two objects when the system is at rest and no external forces are applied.
- stiffness
The spring constant (elasticity). A higher value increases the restorative force toward the rest_angle, making the spring feel “stiffer.”
- damping
The damping coefficient. Used to simulate energy dissipation (like friction or air resistance). Higher values cause oscillations to decay faster.
- arc_indicator_class
The class used to visualize the angle (defaults to Arc). If set to None, no angular arc will be rendered.
- arc_indicator_config
A dictionary defining the visual style of the arc indicator, including radius, color, and stroke_width.
- connect_line_class
The class used to draw a connecting line between the two objects (e.g., Line). Defaults to None for no visible connection.
- connect_line_config
A dictionary defining the visual style of the connecting line, such as color and stroke_width.
Examples¶
Example: VDampedRotarySpringExample ¶
from manim import * from manim_pymunk import * class VDampedRotarySpringExample(SpaceScene): def construct(self): floor = Line(LEFT * 10, RIGHT * 10).shift(DOWN*2) square_1 = Square().next_to(floor, UP) square_2 = Square().move_to(square_1.get_center() + RIGHT * 4) constraint = VDampedRotarySpring( square_1, square_2, rest_angle=PI / 4, stiffness=100, damping=1, ) self.add_static_body(floor) self.add_dynamic_body(square_1, square_2) self.add_constraints(constraint) self.wait(3)
from manim_pymunk import * class VDampedRotarySpringExample(SpaceScene): def construct(self): floor = Line(LEFT * 10, RIGHT * 10).shift(DOWN*2) square_1 = Square().next_to(floor, UP) square_2 = Square().move_to(square_1.get_center() + RIGHT * 4) constraint = VDampedRotarySpring( square_1, square_2, rest_angle=PI / 4, stiffness=100, damping=1, ) self.add_static_body(floor) self.add_dynamic_body(square_1, square_2) self.add_constraints(constraint) self.wait(3)- animation_overrides = {}¶
- background_image: Image | str | None¶
- background_stroke_color: ManimColor¶
- background_stroke_opacity: float¶
- background_stroke_width: float¶
- cap_style: CapStyleType¶
- close_new_points: bool¶
- install(space)[source]¶
Initialization of physics and visualization components
- Parameters:
space (Space)
- joint_type: LineJointType¶
- make_smooth_after_applying_functions: bool¶
- n_points_per_cubic_curve: int¶
- pre_function_handle_to_anchor_scale_factor: float¶
- shade_in_3d: bool¶
- submobjects: list[VMobject]¶
- tolerance_for_point_equality: float¶
- Parameters:
a_mob (Mobject)
b_mob (Mobject)
rest_angle (float)
stiffness (float)
damping (float)
arc_indicator_class (Arc | None)
arc_indicator_config (dict)
connect_line_class (Line | None)
connect_line_config (dict)
- class VDampedSpring(a_mob, b_mob, anchor_a_local=array([0., 0., 0.]), anchor_b_local=array([0., 0., 0.]), rest_length=1.0, stiffness=100.0, damping=10.0, mob_a_appearance=Dot, mob_b_appearance=Dot, connect_line_class=<class 'manim_pymunk.custom_mobjects.v_spring.VSpring'>, connect_line_config={'color': ManimColor('#F7D96F'), 'stroke_width': 2}, **kwargs)[source]¶
Bases:
VConstraintA damped spring connection is created between two rigid bodies. The spring applies a restorative force proportional to the displacement from its rest length, while the damping simulates energy loss to suppress oscillations.
Parameters¶
- a_mob
The first Mobject to be connected. Acts as one of the anchor points for the spring.
- b_mob
The second Mobject to be connected. Linked to a_mob via the physical spring constraint.
- anchor_a_local
The local anchor point on a_mob where the spring is attached, relative to the Mobject’s center.
- anchor_b_local
The local anchor point on b_mob where the spring is attached, relative to the Mobject’s center.
- rest_length
The equilibrium length of the spring. When the distance between anchors equals this value, the spring exerts no force.
- stiffness
The spring constant $k$ (Young’s modulus). Determines how strongly the spring pulls or pushes to return to rest_length.
- damping
The damping coefficient $c$. Used to simulate viscous friction, causing the kinetic energy of the system to dissipate over time.
- mob_a_appearance
The Mobject used to visually represent the anchor point on a_mob (e.g., a Dot).
- mob_b_appearance
The Mobject used to visually represent the anchor point on b_mob (e.g., a Dot).
- connect_line_class
The class used to visualize the spring body (defaults to VSpring). If set to None, the spring connection will be invisible.
- connect_line_config
A dictionary defining the visual style of the connect_line_class, such as color and stroke_width.
Examples¶
Example: VDampedSpringExample ¶
from manim import * from manim_pymunk import * class VDampedSpringExample(SpaceScene): def construct(self): floor = Line(LEFT * 10, RIGHT * 10).shift(DOWN*2) square_1 = Square().next_to(floor, UP) square_2 = Square().move_to(square_1.get_center() + UP * 4) constraint = VDampedSpring( square_1, square_2, rest_length=3, stiffness=100, damping=10, ) self.add_static_body(floor) self.add_dynamic_body(square_1, square_2) self.add_constraints(constraint) self.wait(3)
from manim_pymunk import * class VDampedSpringExample(SpaceScene): def construct(self): floor = Line(LEFT * 10, RIGHT * 10).shift(DOWN*2) square_1 = Square().next_to(floor, UP) square_2 = Square().move_to(square_1.get_center() + UP * 4) constraint = VDampedSpring( square_1, square_2, rest_length=3, stiffness=100, damping=10, ) self.add_static_body(floor) self.add_dynamic_body(square_1, square_2) self.add_constraints(constraint) self.wait(3)- animation_overrides = {}¶
- background_image: Image | str | None¶
- background_stroke_color: ManimColor¶
- background_stroke_opacity: float¶
- background_stroke_width: float¶
- cap_style: CapStyleType¶
- close_new_points: bool¶
- joint_type: LineJointType¶
- make_smooth_after_applying_functions: bool¶
- n_points_per_cubic_curve: int¶
- pre_function_handle_to_anchor_scale_factor: float¶
- shade_in_3d: bool¶
- submobjects: list[VMobject]¶
- tolerance_for_point_equality: float¶
- Parameters:
a_mob (Mobject)
b_mob (Mobject)
anchor_a_local (list[float, float, float])
anchor_b_local (list[float, float, float])
rest_length (float)
stiffness (float)
damping (float)
mob_a_appearance (Mobject)
mob_b_appearance (Mobject)
connect_line_class (Line | None)
connect_line_config (dict)
- class VGearJoint(a_mob, b_mob, phase=0.0, ratio=1.0, indicator_line_class=<class 'manim.mobject.geometry.line.Arrow'>, indicator_line_config={'color': ManimColor('#58C4DD'), 'stroke_width': 2}, indicator_length=0.4, **kwargs)[source]¶
Bases:
VConstraintA gear joint constrains the rotational speeds of two rigid bodies. It ensures that the two bodies rotate relative to each other at a fixed ratio, simulating the mechanical link of a gear system or a belt drive.
Parameters¶
- a_mob
The first Mobject to be connected. Typically represents the driving or reference gear.
- b_mob
The second Mobject to be connected. Its rotation is linked to a_mob based on the defined ratio.
- phase
The angular offset (in radians) between the two bodies. Adjusts the initial relative orientation alignment.
- ratio
The gear ratio. Defines how the angular velocity of b_mob relates to a_mob. For example, a ratio of 2.0 means b_mob rotates twice as fast as a_mob.
- indicator_line_class
The class used to visualize the rotational direction or connection (defaults to Arrow). If set to None, no indicator will be rendered.
- indicator_line_config
A dictionary defining the visual style of the indicator line, including color and stroke_width.
Examples¶
Example: VGearJointExample ¶
from manim import * from manim_pymunk import * class VGearJointExample(SpaceScene): def construct(self): floor = Line(LEFT * 10, RIGHT * 10).shift(DOWN * 2) static_dot1 = Dot(UP * 2) static_dot2 = Dot(UP * 2 + RIGHT * 4) square_1 = Square().move_to(static_dot1) square_2 = Square().move_to(static_dot2) constraints = [ VGearJoint( square_1, square_2, phase=0, ratio=4, ), VPinJoint(static_dot1, square_1), VPinJoint(static_dot2, square_2), ] self.add_static_body(floor, static_dot1, static_dot2) self.add_dynamic_body(square_1, angular_velocity=PI * 2) self.add_dynamic_body(square_2) self.add_shapes_filter(static_dot1, static_dot2, square_1, square_2, group=2) self.add_constraints(*constraints) self.wait(3)
from manim_pymunk import * class VGearJointExample(SpaceScene): def construct(self): floor = Line(LEFT * 10, RIGHT * 10).shift(DOWN * 2) static_dot1 = Dot(UP * 2) static_dot2 = Dot(UP * 2 + RIGHT * 4) square_1 = Square().move_to(static_dot1) square_2 = Square().move_to(static_dot2) constraints = [ VGearJoint( square_1, square_2, phase=0, ratio=4, ), VPinJoint(static_dot1, square_1), VPinJoint(static_dot2, square_2), ] self.add_static_body(floor, static_dot1, static_dot2) self.add_dynamic_body(square_1, angular_velocity=PI * 2) self.add_dynamic_body(square_2) self.add_shapes_filter(static_dot1, static_dot2, square_1, square_2, group=2) self.add_constraints(*constraints) self.wait(3)- animation_overrides = {}¶
- background_image: Image | str | None¶
- background_stroke_color: ManimColor¶
- background_stroke_opacity: float¶
- background_stroke_width: float¶
- cap_style: CapStyleType¶
- close_new_points: bool¶
- joint_type: LineJointType¶
- make_smooth_after_applying_functions: bool¶
- n_points_per_cubic_curve: int¶
- pre_function_handle_to_anchor_scale_factor: float¶
- shade_in_3d: bool¶
- submobjects: list[VMobject]¶
- tolerance_for_point_equality: float¶
- Parameters:
a_mob (Mobject)
b_mob (Mobject)
phase (float)
ratio (float)
indicator_line_class (Line | None)
indicator_line_config (dict)
indicator_length (float)
- class VGrooveJoint(a_mob, b_mob, groove_a_local=array([1., 0., 0.]), groove_b_local=array([2., 0., 0.]), anchor_b_local=array([0., 0., 0.]), groove_a_appearance=Dot, groove_b_appearance=Dot, anchor_b_appearance=Dot, groove_line_class=<class 'manim.mobject.geometry.line.Line'>, groove_line_config={'color': ManimColor('#F7D96F'), 'stroke_width': 2}, **kwargs)[source]¶
Bases:
VConstraintInitializes a Groove Joint constraint between two Mobjects.
A Groove Joint constrains a point on the second body to a line segment (the “groove”) on the first body. The groove is defined by two points relative to the first body’s center, and the anchor point is relative to the second body’s center.
Parameters¶
- a_mob
The Mobject that contains the groove (the rail/track).
- b_mob
The Mobject that contains the sliding anchor (the slider).
- groove_a_local
The start point of the groove, in a_mob’s local coordinates.
- groove_b_local
The end point of the groove, in a_mob’s local coordinates.
- anchor_b_local
The anchor point on b_mob that slides within the groove, in local coordinates.
- groove_a_appearance
Visual Mobject representing the start of the groove.
- groove_b_appearance
Visual Mobject representing the end of the groove.
- anchor_b_appearance
Visual Mobject representing the sliding anchor on the second body.
- groove_line_class
The Manim class used to draw the groove line (e.g., Line or DashedLine).
- groove_line_config
Configuration dictionary for the styling of the groove line.
Examples¶
Example: VGrooveJointExample ¶
from manim import * from manim_pymunk import * class VGrooveJointExample(SpaceScene): def construct(self): static_dot = Dot() square_1 = Square().move_to(static_dot) square_2 = Square().move_to(static_dot.get_center() + RIGHT * 4).scale(0.3) constraints = [ VGrooveJoint( square_1, square_2, groove_a_local=RIGHT * 2, groove_b_local=RIGHT * 4, ), VPinJoint(static_dot, square_1), ] self.add_static_body(static_dot) self.add_dynamic_body(square_1, angular_velocity=PI * 2) self.add_dynamic_body(square_2) self.add_shapes_filter(static_dot, square_1, square_2, group=2) self.add_constraints(*constraints) self.wait(6)
from manim_pymunk import * class VGrooveJointExample(SpaceScene): def construct(self): static_dot = Dot() square_1 = Square().move_to(static_dot) square_2 = Square().move_to(static_dot.get_center() + RIGHT * 4).scale(0.3) constraints = [ VGrooveJoint( square_1, square_2, groove_a_local=RIGHT * 2, groove_b_local=RIGHT * 4, ), VPinJoint(static_dot, square_1), ] self.add_static_body(static_dot) self.add_dynamic_body(square_1, angular_velocity=PI * 2) self.add_dynamic_body(square_2) self.add_shapes_filter(static_dot, square_1, square_2, group=2) self.add_constraints(*constraints) self.wait(6)- animation_overrides = {}¶
- background_image: Image | str | None¶
- background_stroke_color: ManimColor¶
- background_stroke_opacity: float¶
- background_stroke_width: float¶
- cap_style: CapStyleType¶
- close_new_points: bool¶
- joint_type: LineJointType¶
- make_smooth_after_applying_functions: bool¶
- n_points_per_cubic_curve: int¶
- pre_function_handle_to_anchor_scale_factor: float¶
- shade_in_3d: bool¶
- submobjects: list[VMobject]¶
- tolerance_for_point_equality: float¶
- Parameters:
a_mob (Mobject)
b_mob (Mobject)
groove_a_local (list[float, float, float])
groove_b_local (list[float, float, float])
anchor_b_local (list[float, float, float])
groove_a_appearance (Mobject)
groove_b_appearance (Mobject)
anchor_b_appearance (Mobject)
groove_line_class (Line | None)
groove_line_config (dict)
- class VPinJoint(a_mob, b_mob, anchor_a_local=array([0., 0., 0.]), anchor_b_local=array([0., 0., 0.]), distance=None, anchor_a_appearance=Dot, anchor_b_appearance=Dot, connect_line_class=None, connect_line_config={'color': ManimColor('#F7D96F'), 'stroke_width': 2}, **kwargs)[source]¶
Bases:
VConstraintA pin joint keeps a fixed distance between two anchor points on two rigid bodies. It acts like a solid, weightless rod connecting two points, allowing them to rotate freely around the anchors while maintaining the specified distance.
Parameters¶
- a_mob
The first Mobject to be connected.
- b_mob
The second Mobject to be connected.
- anchor_a_local
The local anchor point on a_mob where the pin is attached, relative to the Mobject’s center.
- anchor_b_local
The local anchor point on b_mob where the pin is attached, relative to the Mobject’s center.
- distance
The fixed distance to maintain between the two anchors. If None, it is automatically calculated as the initial distance between anchors.
- anchor_a_appearance
The Mobject used to visually represent the anchor point on a_mob (e.g., a red Dot).
- anchor_b_appearance
The Mobject used to visually represent the anchor point on b_mob (e.g., a red Dot).
- connect_line_class
The class used to draw the connecting rod (e.g., Line). Defaults to None for no visible connection.
- connect_line_config
A dictionary defining the visual style of the connecting line, such as color and stroke_width.
Examples¶
Example: VPinJointExample ¶
from manim import * from manim_pymunk import * class VPinJointExample(SpaceScene): def construct(self): static_dot = Dot(ORIGIN) square = Square().move_to(static_dot) square2 = Square().move_to(static_dot.get_center() + UP * 2).scale(0.5) constraints = [ VPinJoint(static_dot, square), VPinJoint( square, square2, anchor_a_local=square.get_corner(UR) - square.get_center(), distance=2, connect_line_class=Line, ), ] self.add_static_body(static_dot) self.add_dynamic_body(square, square2, angular_velocity=PI * 2) self.add_shapes_filter(static_dot, square, square2, group=2) self.add_constraints(*constraints) self.wait(3)
from manim_pymunk import * class VPinJointExample(SpaceScene): def construct(self): static_dot = Dot(ORIGIN) square = Square().move_to(static_dot) square2 = Square().move_to(static_dot.get_center() + UP * 2).scale(0.5) constraints = [ VPinJoint(static_dot, square), VPinJoint( square, square2, anchor_a_local=square.get_corner(UR) - square.get_center(), distance=2, connect_line_class=Line, ), ] self.add_static_body(static_dot) self.add_dynamic_body(square, square2, angular_velocity=PI * 2) self.add_shapes_filter(static_dot, square, square2, group=2) self.add_constraints(*constraints) self.wait(3)- animation_overrides = {}¶
- background_image: Image | str | None¶
- background_stroke_color: ManimColor¶
- background_stroke_opacity: float¶
- background_stroke_width: float¶
- cap_style: CapStyleType¶
- close_new_points: bool¶
- install(space)[source]¶
Installs physical constraints into the Pymunk physical space. This method should be overridden by subclasses to implement the following:
Create Pymunk constraint objects
Initialize the vision component
Add constraints to the physical space
Bind an updater to keep the vision synchronized.
- Parameters:
space (Space)
- joint_type: LineJointType¶
- make_smooth_after_applying_functions: bool¶
- n_points_per_cubic_curve: int¶
- pre_function_handle_to_anchor_scale_factor: float¶
- shade_in_3d: bool¶
- submobjects: list[VMobject]¶
- tolerance_for_point_equality: float¶
- Parameters:
a_mob (Mobject)
b_mob (Mobject)
anchor_a_local (list[float, float, float])
anchor_b_local (list[float, float, float])
distance (float | None)
anchor_a_appearance (Mobject)
anchor_b_appearance (Mobject)
connect_line_class (Line | None)
connect_line_config (dict)
- class VPivotJoint(a_mob, b_mob, pivot_world=None, anchor_a_local=array([0., 0., 0.]), anchor_b_local=array([0., 0., 0.]), anchor_a_appearance=Dot, anchor_b_appearance=Dot, pivot_appearance=Dot, connect_line_class=<class 'manim.mobject.geometry.line.Line'>, connect_line_config={'color': ManimColor('#F7D96F'), 'stroke_width': 2}, **kwargs)[source]¶
Bases:
VConstraintA pivot joint allows two rigid bodies to rotate freely around a common pivot point. The pivot point acts as an axis of rotation, ensuring that both bodies remain attached at the specified position regardless of external forces.
Please configure pivot_world or (anchor_a_loca, anchor_b_local).
Parameters¶
- a_mob
The first Mobject to be connected.
- b_mob
The second Mobject to be connected.
- pivot_world
The global coordinate position of the pivot point. If provided, anchor_a_local and anchor_b_local are calculated automatically based on this.
- anchor_a_local
The local anchor point on a_mob corresponding to the pivot, relative to the Mobject’s center.
- anchor_b_local
The local anchor point on b_mob corresponding to the pivot, relative to the Mobject’s center.
- pivot_appearance
The Mobject used to visually represent the pivot point (defaults to a white Dot with 0.05 radius).
Examples¶
Example: VPivotJointExample ¶
from manim import * from manim_pymunk import * class VPivotJointExample(SpaceScene): def construct(self): static_dot = Dot(ORIGIN) square = Square().move_to(static_dot) square2 = Square().move_to(static_dot.get_center() + UP * 2).scale(0.5) constraints = [ VPivotJoint(static_dot, square), VPivotJoint( square, square2, pivot_world= UP*3, ), ] self.add_static_body(static_dot) self.add_dynamic_body(square, square2, angular_velocity=PI * 2) self.add_shapes_filter(static_dot, square, square2, group=2) self.add_constraints(*constraints) self.wait(3)
from manim_pymunk import * class VPivotJointExample(SpaceScene): def construct(self): static_dot = Dot(ORIGIN) square = Square().move_to(static_dot) square2 = Square().move_to(static_dot.get_center() + UP * 2).scale(0.5) constraints = [ VPivotJoint(static_dot, square), VPivotJoint( square, square2, pivot_world= UP*3, ), ] self.add_static_body(static_dot) self.add_dynamic_body(square, square2, angular_velocity=PI * 2) self.add_shapes_filter(static_dot, square, square2, group=2) self.add_constraints(*constraints) self.wait(3)- animation_overrides = {}¶
- background_image: Image | str | None¶
- background_stroke_color: ManimColor¶
- background_stroke_opacity: float¶
- background_stroke_width: float¶
- cap_style: CapStyleType¶
- close_new_points: bool¶
- joint_type: LineJointType¶
- make_smooth_after_applying_functions: bool¶
- n_points_per_cubic_curve: int¶
- pre_function_handle_to_anchor_scale_factor: float¶
- shade_in_3d: bool¶
- submobjects: list[VMobject]¶
- tolerance_for_point_equality: float¶
- Parameters:
a_mob (Mobject)
b_mob (Mobject)
pivot_world (list[float, float, float])
anchor_a_local (list[float, float, float])
anchor_b_local (list[float, float, float])
anchor_a_appearance (Mobject)
anchor_b_appearance (Mobject)
pivot_appearance (Mobject)
connect_line_class (Line | None)
connect_line_config (dict)
- class VRatchetJoint(a_mob, b_mob, phase=0.0, ratchet=1.5707963267948966, indicator_line_class=<class 'manim.mobject.geometry.line.Arrow'>, indicator_line_config={'color': ManimColor('#58C4DD'), 'stroke_width': 2}, indicator_line_length=0.4, connect_line_class=None, connect_line_config={'color': ManimColor('#F7D96F'), 'stroke_width': 2}, **kwargs)[source]¶
Bases:
VConstraintInitializes a Ratchet Joint constraint between two Mobjects.
A Ratchet Joint acts like a rotary pawl, allowing relative rotation only in discrete increments and in one direction. It is perfect for simulating winding mechanisms, clockwork, or unidirectional gears.
Parameters¶
- a_mob
The first Mobject (the base or reference body).
- b_mob
The second Mobject (the body subject to the ratchet effect).
- phase
The initial angular offset of the ratchet teeth.
- ratchet
The angular distance between each “tooth” (in radians). For example, PI/2 means the joint locks at every 90-degree interval.
- indicator_line_class
The Manim class used to visualize the current rotation or ratchet direction.
- indicator_line_config
Configuration dictionary for the styling of the indicator arrow.
- indicator_line_length
The visual length of the indicator line.
- connect_line_class
The Manim class used to draw a line between the centers of the two objects. Set to None to disable.
- connect_line_config
Configuration dictionary for the styling of the connection line.
Examples¶
Example: VRatchetJointExample ¶
from manim import * from manim_pymunk import * class VRatchetJointExample(SpaceScene): def construct(self): floor = Line(LEFT * 10, RIGHT * 10).shift(DOWN * 2) static_dot1 = Dot(UP * 2) static_dot2 = Dot(UP * 2 + RIGHT * 4) square_1 = Square().move_to(static_dot1) square_2 = Square().move_to(static_dot2) constraints = [ VRatchetJoint( square_1, square_2, phase=PI / 4, ratchet=PI, ), VPinJoint(static_dot1, square_1), VPinJoint(static_dot2, square_2), ] self.add_static_body(floor, static_dot1, static_dot2) self.add_dynamic_body(square_1, angular_velocity=PI * 2) self.add_dynamic_body(square_2) self.add_shapes_filter(static_dot1, static_dot2, square_1, square_2, group=2) self.add_constraints(*constraints) self.wait(3)
from manim_pymunk import * class VRatchetJointExample(SpaceScene): def construct(self): floor = Line(LEFT * 10, RIGHT * 10).shift(DOWN * 2) static_dot1 = Dot(UP * 2) static_dot2 = Dot(UP * 2 + RIGHT * 4) square_1 = Square().move_to(static_dot1) square_2 = Square().move_to(static_dot2) constraints = [ VRatchetJoint( square_1, square_2, phase=PI / 4, ratchet=PI, ), VPinJoint(static_dot1, square_1), VPinJoint(static_dot2, square_2), ] self.add_static_body(floor, static_dot1, static_dot2) self.add_dynamic_body(square_1, angular_velocity=PI * 2) self.add_dynamic_body(square_2) self.add_shapes_filter(static_dot1, static_dot2, square_1, square_2, group=2) self.add_constraints(*constraints) self.wait(3)- animation_overrides = {}¶
- background_image: Image | str | None¶
- background_stroke_color: ManimColor¶
- background_stroke_opacity: float¶
- background_stroke_width: float¶
- cap_style: CapStyleType¶
- close_new_points: bool¶
- install(space)[source]¶
Installs physical constraints into the Pymunk physical space. This method should be overridden by subclasses to implement the following:
Create Pymunk constraint objects
Initialize the vision component
Add constraints to the physical space
Bind an updater to keep the vision synchronized.
- Parameters:
space (Space)
- joint_type: LineJointType¶
- make_smooth_after_applying_functions: bool¶
- n_points_per_cubic_curve: int¶
- pre_function_handle_to_anchor_scale_factor: float¶
- shade_in_3d: bool¶
- submobjects: list[VMobject]¶
- tolerance_for_point_equality: float¶
- Parameters:
a_mob (Mobject)
b_mob (Mobject)
phase (float)
ratchet (float)
indicator_line_class (Line | None)
indicator_line_config (dict)
connect_line_class (Line | None)
connect_line_config (dict)
- class VRotaryLimitJoint(a_mob, b_mob, min_angle=-0.7853981633974483, max_angle=0.7853981633974483, arc_indicator_class=<class 'manim.mobject.geometry.arc.Arc'>, arc_indicator_config={'color': ManimColor('#F7D96F'), 'radius': 0.5, 'stroke_width': 2}, **kwargs)[source]¶
Bases:
VConstraintInitializes a Rotary Limit Joint constraint between two Mobjects.
This joint constrains the relative rotation between two bodies to stay within a specific angular range. It acts as a physical stop when the bodies reach the minimum or maximum angle limits.
Parameters¶
- a_mob
The first Mobject (the reference body).
- b_mob
The second Mobject (the constrained body).
- min_angle
The minimum allowed relative angle (in radians).
- max_angle
The maximum allowed relative angle (in radians).
- arc_indicator_class
The Manim class used to visualize the angular limits (typically Arc). Set to None to hide the visual representation.
- arc_indicator_config
Configuration dictionary for the styling of the visual arc.
Examples¶
Example: VRotaryLimitJointExample ¶
from manim import * from manim_pymunk import * class VRotaryLimitJointExample(SpaceScene): def construct(self): static_dot = Dot(ORIGIN) square = Square().move_to(static_dot) square2 = Square().move_to(static_dot.get_center() + UP * 2).scale(0.5) constraints = [ VPinJoint(static_dot, square), VPinJoint( square, square2, anchor_a_local=square.get_corner(UR) - square.get_center(), distance=2, connect_line_class=Line, ), VRotaryLimitJoint( static_dot, square2, min_angle=-PI / 6, max_angle=PI / 6, ), ] self.add_static_body(static_dot) self.add_dynamic_body(square, square2, angular_velocity=PI * 2) self.add_shapes_filter(static_dot, square, square2, group=2) self.add_constraints(*constraints) self.wait(3)
from manim_pymunk import * class VRotaryLimitJointExample(SpaceScene): def construct(self): static_dot = Dot(ORIGIN) square = Square().move_to(static_dot) square2 = Square().move_to(static_dot.get_center() + UP * 2).scale(0.5) constraints = [ VPinJoint(static_dot, square), VPinJoint( square, square2, anchor_a_local=square.get_corner(UR) - square.get_center(), distance=2, connect_line_class=Line, ), VRotaryLimitJoint( static_dot, square2, min_angle=-PI / 6, max_angle=PI / 6, ), ] self.add_static_body(static_dot) self.add_dynamic_body(square, square2, angular_velocity=PI * 2) self.add_shapes_filter(static_dot, square, square2, group=2) self.add_constraints(*constraints) self.wait(3)- animation_overrides = {}¶
- background_image: Image | str | None¶
- background_stroke_color: ManimColor¶
- background_stroke_opacity: float¶
- background_stroke_width: float¶
- cap_style: CapStyleType¶
- close_new_points: bool¶
- install(space)[source]¶
Installs physical constraints into the Pymunk physical space. This method should be overridden by subclasses to implement the following:
Create Pymunk constraint objects
Initialize the vision component
Add constraints to the physical space
Bind an updater to keep the vision synchronized.
- Parameters:
space (Space)
- joint_type: LineJointType¶
- make_smooth_after_applying_functions: bool¶
- n_points_per_cubic_curve: int¶
- pre_function_handle_to_anchor_scale_factor: float¶
- shade_in_3d: bool¶
- submobjects: list[VMobject]¶
- tolerance_for_point_equality: float¶
- Parameters:
a_mob (Mobject)
b_mob (Mobject)
min_angle (float)
max_angle (float)
arc_indicator_class (Arc | None)
arc_indicator_config (dict)
- class VSimpleMotor(a_mob, b_mob, rate=3.141592653589793, max_torque=inf, indicator_line_class=<class 'manim.mobject.geometry.line.Arrow'>, indicator_line_config={'color': ManimColor('#FC6255'), 'stroke_width': 2}, **kwargs)[source]¶
Bases:
VConstraintInitializes a Simple Motor constraint between two Mobjects.
A Simple Motor maintains a constant relative angular velocity between two bodies. It applies the necessary torque to reach and maintain the target rotation rate, up to a defined maximum torque limit.
Parameters¶
- a_mob
The first Mobject (often the base or stator).
- b_mob
The second Mobject (often the rotor or driven part).
- rate
The target relative angular velocity in radians per second.
- max_torque
The maximum torque the motor can apply to achieve the target rate. Setting this to a finite value allows the motor to “stall” under load.
- indicator_line_class
The Manim class used to visualize the rotation (e.g., Arrow or CurvedArrow).
- indicator_line_config
Configuration dictionary for the styling of the visual indicator.
Examples¶
Example: VSimpleMotorExample ¶
from manim import * from manim_pymunk import * class VSimpleMotorExample(SpaceScene): def construct(self): static_dot = Dot(ORIGIN) square = Square().move_to(static_dot) square2 = Square().move_to(static_dot.get_center() + UP * 2).scale(0.5) constraints = [ VPinJoint(static_dot, square), VPinJoint( square, square2, anchor_a_local=square.get_corner(UR) - square.get_center(), distance=2, connect_line_class=Line, ), VSimpleMotor( static_dot, square, rate=4, max_torque=500, ), ] self.add_static_body(static_dot) self.add_dynamic_body(square, square2) self.add_shapes_filter(static_dot, square, square2, group=2) self.add_constraints(*constraints) self.wait(3)
from manim_pymunk import * class VSimpleMotorExample(SpaceScene): def construct(self): static_dot = Dot(ORIGIN) square = Square().move_to(static_dot) square2 = Square().move_to(static_dot.get_center() + UP * 2).scale(0.5) constraints = [ VPinJoint(static_dot, square), VPinJoint( square, square2, anchor_a_local=square.get_corner(UR) - square.get_center(), distance=2, connect_line_class=Line, ), VSimpleMotor( static_dot, square, rate=4, max_torque=500, ), ] self.add_static_body(static_dot) self.add_dynamic_body(square, square2) self.add_shapes_filter(static_dot, square, square2, group=2) self.add_constraints(*constraints) self.wait(3)- animation_overrides = {}¶
- background_image: Image | str | None¶
- background_stroke_color: ManimColor¶
- background_stroke_opacity: float¶
- background_stroke_width: float¶
- cap_style: CapStyleType¶
- close_new_points: bool¶
- install(space)[source]¶
Installs physical constraints into the Pymunk physical space. This method should be overridden by subclasses to implement the following:
Create Pymunk constraint objects
Initialize the vision component
Add constraints to the physical space
Bind an updater to keep the vision synchronized.
- Parameters:
space (Space)
- joint_type: LineJointType¶
- make_smooth_after_applying_functions: bool¶
- n_points_per_cubic_curve: int¶
- pre_function_handle_to_anchor_scale_factor: float¶
- shade_in_3d: bool¶
- submobjects: list[VMobject]¶
- tolerance_for_point_equality: float¶
- Parameters:
a_mob (Mobject)
b_mob (Mobject)
rate (float)
max_torque (float)
indicator_line_class (Line | None)
indicator_line_config (dict)
- class VSlideJoint(a_mob, b_mob, anchor_a_local=array([0., 0., 0.]), anchor_b_local=array([0., 0., 0.]), min_dist=0.0, max_dist=1.0, anchor_a_appearance=Dot, anchor_b_appearance=Dot, indicator_line_class=<class 'manim.mobject.geometry.line.Line'>, indicator_line_config={'color': ManimColor('#FC6255'), 'stroke_width': 2}, **kwargs)[source]¶
Bases:
VConstraintInitializes a Slide Joint constraint between two Mobjects.
A Slide Joint holds two bodies between a minimum and maximum distance. It acts like a solid link when the distance reaches the limits, but allows free movement within the specified range.
Parameters¶
- a_mob
The first Mobject to connect.
- b_mob
The second Mobject to connect.
- anchor_a_local
The anchor point on the first body, defined in local coordinates.
- anchor_b_local
The anchor point on the second body, defined in local coordinates.
- min_dist
The minimum allowed distance between the two anchor points.
- max_dist
The maximum allowed distance between the two anchor points.
- anchor_a_appearance
The visual representation (Mobject) of the first anchor point.
- anchor_b_appearance
The visual representation (Mobject) of the second anchor point.
- indicator_line_class
The Manim class used to draw the connection line (e.g., Line or DashedLine). Pass None to disable the visual indicator.
- indicator_line_config
Configuration dictionary for the styling of the indicator line.
Examples¶
Example: VSlideJointExample ¶
from manim import * from manim_pymunk import * class VSlideJointExample(SpaceScene): def construct(self): static_dot = Dot(ORIGIN) square = Square().move_to(static_dot).scale(2) square2 = Square().move_to(static_dot.get_center() + UR*3).scale(0.5) constraints = [ VPinJoint(static_dot, square), VSlideJoint( square, square2, anchor_a_local=square.get_corner(UR) - square.get_center(), min_dist=0.5, max_dist=3, ), VSimpleMotor( static_dot, square, rate=PI/4, max_torque=500, ), ] self.add_static_body(static_dot) self.add_dynamic_body(square, square2) self.add_shapes_filter(static_dot, square, square2, group=2) self.add_constraints(*constraints) self.wait(6)
from manim_pymunk import * class VSlideJointExample(SpaceScene): def construct(self): static_dot = Dot(ORIGIN) square = Square().move_to(static_dot).scale(2) square2 = Square().move_to(static_dot.get_center() + UR*3).scale(0.5) constraints = [ VPinJoint(static_dot, square), VSlideJoint( square, square2, anchor_a_local=square.get_corner(UR) - square.get_center(), min_dist=0.5, max_dist=3, ), VSimpleMotor( static_dot, square, rate=PI/4, max_torque=500, ), ] self.add_static_body(static_dot) self.add_dynamic_body(square, square2) self.add_shapes_filter(static_dot, square, square2, group=2) self.add_constraints(*constraints) self.wait(6)- animation_overrides = {}¶
- background_image: Image | str | None¶
- background_stroke_color: ManimColor¶
- background_stroke_opacity: float¶
- background_stroke_width: float¶
- cap_style: CapStyleType¶
- close_new_points: bool¶
- install(space)[source]¶
Installs physical constraints into the Pymunk physical space. This method should be overridden by subclasses to implement the following:
Create Pymunk constraint objects
Initialize the vision component
Add constraints to the physical space
Bind an updater to keep the vision synchronized.
- Parameters:
space (Space)
- joint_type: LineJointType¶
- make_smooth_after_applying_functions: bool¶
- n_points_per_cubic_curve: int¶
- pre_function_handle_to_anchor_scale_factor: float¶
- shade_in_3d: bool¶
- submobjects: list[VMobject]¶
- tolerance_for_point_equality: float¶
- Parameters:
a_mob (Mobject)
b_mob (Mobject)
anchor_a_local (list[float, float, float])
anchor_b_local (list[float, float, float])
min_dist (float)
max_dist (float)
anchor_a_appearance (Mobject)
anchor_b_appearance (Mobject)
indicator_line_class (Line | None)
indicator_line_config (dict)
Modules
|
A rotational spring connection is created between the two rigid bodies. |
|
A damped spring connection is created between two rigid bodies. |
|
A gear joint constrains the rotational speeds of two rigid bodies. |
|
Initializes a Groove Joint constraint between two Mobjects. |
|
A pin joint keeps a fixed distance between two anchor points on two rigid bodies. |
|
A pivot joint allows two rigid bodies to rotate freely around a common pivot point. |
|
Initializes a Ratchet Joint constraint between two Mobjects. |
|
Initializes a Rotary Limit Joint constraint between two Mobjects. |
|
Initializes a Simple Motor constraint between two Mobjects. |
|
Initializes a Slide Joint constraint between two Mobjects. |