The scene functions provide utilities to change a particular scene (represented by a SimState object) in a variety of ways, including adding a thruster, adding revolute or fixed joints, or adding shapes.
Creating a Scene
To create a scene, you can use the following code block
static_sim_params = StaticSimParams()
sim_params = SimParams()
engine = PhysicsEngine(static_sim_params)
# Create scene
sim_state = create_empty_sim(static_sim_params, floor_offset=0.0)
Editing a Scene
While you can edit a scene manually by changing the parameters, we recommend using the functions provided in jax2d.scene to edit a state.
Environment Size
Note, if the environment state has the maximum number of a certain entity type (e.g. polygons) and you try to add another one, it will result in a no-op.
add_circle_to_scene
add_circle_to_scene(sim_state, static_sim_params, position, radius, rotation=0.0, velocity=jnp.zeros(2), angular_velocity=0.0, density=1.0, friction=1.0, restitution=0.0, fixated=False)
Adds a circle to the scene, with the properties specified by the given parameters.
| Parameters: |
|
|---|
| Returns: |
|
|---|
add_fixed_joint_to_scene
add_fixed_joint_to_scene(sim_state, static_sim_params, a_index, b_index, a_relative_pos, b_relative_pos)
Adds a fixed joint to a scene, where a fixed joint does not allow the relative rotation between the two objects to change.
| Parameters: |
|
|---|
| Returns: |
|
|---|
add_polygon_to_scene
add_polygon_to_scene(sim_state, static_sim_params, position, vertices, n_vertices, rotation=0.0, velocity=jnp.zeros(2), angular_velocity=0.0, density=1.0, friction=1.0, restitution=0.0, fixated=False)
Adds a polygon to the scene.
| Parameters: |
|
|---|
| Returns: |
|
|---|
add_rectangle_to_scene
add_rectangle_to_scene(sim_state, static_sim_params, position, dimensions, rotation=0.0, velocity=jnp.zeros(2), angular_velocity=0.0, density=1.0, friction=1.0, restitution=0.0, fixated=False)
Adds a rectangle to the scene.
| Parameters: |
|
|---|
| Returns: |
|
|---|
add_revolute_joint_to_scene
add_revolute_joint_to_scene(sim_state, static_sim_params, a_index, b_index, a_relative_pos, b_relative_pos, motor_on=False, motor_speed=1.0, motor_power=1.0, has_joint_limits=False, min_rotation=-np.pi, max_rotation=np.pi)
Adds a revolute joint to the scene, connecting the two shapes given by a_index and b_index.
| Parameters: |
|
|---|
| Returns: |
|
|---|
add_thruster_to_scene
add_thruster_to_scene(sim_state, object_index, relative_position, rotation, power=1.0)
Adds a thruster to the object specified by object_index.
| Parameters: |
|
|---|
| Returns: |
|
|---|