How to use the vpython.compound function in vpython

To help you get started, we’ve selected a few vpython examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github petercorke / robotics-toolbox-python / graphics / graphics_stl.py View on Github external
vertices.append(
                vertex(
                    pos=vec(
                        float(file_line[1]),
                        float(file_line[2]),
                        float(file_line[3])
                    ),
                    normal=normal,
                    color=color.white
                )
            )
            if len(vertices) == 3:
                triangles.append(triangle(vs=vertices))
                vertices = []

    return compound(triangles)
github petercorke / robotics-toolbox-python / graphics / graphics_robot.py View on Github external
if length <= 0.0:
                raise ValueError("Joint length must be greater than 0")

            box_midpoint = vector(length / 2, 0, 0)

            # Create a box along the +x axis, with the origin (point of rotation) at (0, 0, 0)
            graphic_obj = box(
                canvas=self.__scene,
                pos=vector(box_midpoint.x, box_midpoint.y, box_midpoint.z),
                axis=x_axis_vector,
                size=vector(length, 0.1, 0.1),
                up=y_axis_vector
            )

            # Set the boxes new origin
            graphic_obj = compound([graphic_obj], origin=vector(0, 0, 0), axis=x_axis_vector, up=y_axis_vector)

            return graphic_obj
        else:
            return import_object_from_numpy_stl(structure, self.__scene)
github petercorke / robotics-toolbox-python / graphics / graphics_stl.py View on Github external
:param required_obj_origin: Required coordinates to place the origin at (0, 0, 0)
    :type required_obj_origin: class:`vpython.vector`
    :param scene: The scene in which to draw the object
    :type scene: class:`vpython.canvas`
    :return: Compound object of itself, with origin set respective to the joint
    :rtype: class:`vpython.compound`
    """
    # Move the object to put the origin at 0, 0, 0
    movement = required_obj_origin - current_obj_origin
    stl_obj.pos += movement

    # Set invisible to return an overwritten copy
    stl_obj.visible = False

    # Return a compound of itself with the origin at (0, 0, 0)
    return compound([stl_obj], origin=vector(0, 0, 0), vector=x_axis_vector, canvas=scene)
github petercorke / robotics-toolbox-python / graphics / graphics_grid.py View on Github external
# Draw a line across each y coord, along the same x-axis, from min to max z coord
            yz_lines.append(create_line(
                vector(x_origin, y_point, min_z_coord),
                vector(x_origin, y_point, max_z_coord),
                self.__scene
            ))
        for z_point in range(min_z_coord, max_z_coord + 1):
            # Draw a line across each z coord, along the same x-axis, from min to max y coord
            yz_lines.append(create_line(
                vector(x_origin, min_y_coord, z_point),
                vector(x_origin, max_y_coord, z_point),
                self.__scene
            ))

        # Compound the lines together into respective objects
        xz_plane = compound(xz_lines)
        xy_plane = compound(xy_lines)
        yz_plane = compound(yz_lines)

        # Combine all into one list
        grid = [None, None, None]
        grid[self.__xy_plane_idx] = xy_plane
        grid[self.__xz_plane_idx] = xz_plane
        grid[self.__yz_plane_idx] = yz_plane

        return grid
github petercorke / robotics-toolbox-python / graphics / graphics_grid.py View on Github external
vector(x_origin, y_point, min_z_coord),
                vector(x_origin, y_point, max_z_coord),
                self.__scene
            ))
        for z_point in range(min_z_coord, max_z_coord + 1):
            # Draw a line across each z coord, along the same x-axis, from min to max y coord
            yz_lines.append(create_line(
                vector(x_origin, min_y_coord, z_point),
                vector(x_origin, max_y_coord, z_point),
                self.__scene
            ))

        # Compound the lines together into respective objects
        xz_plane = compound(xz_lines)
        xy_plane = compound(xy_lines)
        yz_plane = compound(yz_lines)

        # Combine all into one list
        grid = [None, None, None]
        grid[self.__xy_plane_idx] = xy_plane
        grid[self.__xz_plane_idx] = xz_plane
        grid[self.__yz_plane_idx] = yz_plane

        return grid
github petercorke / robotics-toolbox-python / graphics / graphics_canvas.py View on Github external
x_axis = get_pose_x_vec(se3_pose)
    y_axis = get_pose_y_vec(se3_pose)

    # Create Basic Frame
    # Draw X Axis
    x_arrow = arrow(canvas=scene, pos=origin, axis=x_axis_vector, length=0.25, color=color.red)

    # Draw Y Axis
    y_arrow = arrow(canvas=scene, pos=origin, axis=y_axis_vector, length=0.25, color=color.green)

    # Draw Z Axis
    z_arrow = arrow(canvas=scene, pos=origin, axis=z_axis_vector, length=0.25, color=color.blue)

    # Combine all to manipulate together
    # Set origin to where axis converge (instead of the middle of the resulting object bounding box)
    frame_ref = compound([x_arrow, y_arrow, z_arrow], origin=origin, canvas=scene)

    # Set frame axes
    frame_ref.axis = x_axis
    frame_ref.up = y_axis

    return frame_ref