Contenido principal

drawTriangles

R2026b

Draw filled triangles in RoadRunner Viewer scene graph

Since R2026b

    Description

    drawTriangles(pc,points,color) draws filled triangles, of the specified color, using the specified vertex positions points in the specified primitive collection pc in the RoadRunner Viewer scene graph. Every three consecutive vertices in points form one triangle.

    example

    Examples

    collapse all

    Use a PrimitiveCollection object and the drawTriangles function to draw triangles in the RoadRunner Viewer scene graph. This example assumes you have already added the folder containing the RoadRunner API to your MATLAB® path. For information on getting started with RoadRunner Viewer, see Get Started with RoadRunner Viewer (RoadRunner Scenario).

    Open RoadRunner Viewer and create a roadrunnerViewer object rrViewer.

    rrViewer = roadrunnerViewer;

    To create a PrimitiveCollection object, pc, use the addPrimitive function and specify the roadrunnerViewer object rrViewer.

    pc = addPrimitive(rrViewer);

    Draw two blue triangles that form a square in the RoadRunner Viewer scene graph. Use the drawTriangles function and specify the primitive collection pc, the triangle vertex positions triVerts, and the triangle color.

    triVerts = [-2 0 0; -1 0 0; -2 0 1; -1 0 0; -1 0 1; -2 0 1];
    drawTriangles(pc,triVerts,[0 0.4 1]);

    To update RoadRunner Viewer and view the changes to the primitives, use the drawnow function.

    drawnow(rrViewer)

    Input Arguments

    collapse all

    Primitive collection in which to add triangles, specified as a PrimitiveCollection object.

    Triangle vertex point positions, in world coordinates, specified as an N-by-3 matrix. N is the number of vertices, and the columns [x y z] represent the x-, y-, and z-positions of each vertex, respectively. Every three consecutive vertices form one triangle. To draw triangles, the number of vertices N must be a multiple of 3. If N is not a multiple of 3, drawTriangles does nothing.

    Triangle color, specified as a four-element vector of the form [R,G,B,A], a three-element vector of the form [R,G,B], a string scalar, or a character vector. If specified as a vector, R, G, B, and A represent the red, green, blue, and alpha values for the triangle color, respectively. If specified as a string scalar or character vector, you must use a color name, such as "blue", or a hexadecimal value, such as "#0072BD".

    This table lists the named color options, the equivalent RGBA values, and the hexadecimal color codes.

    Color NameShort NameRGBA ValueHexadecimal Color CodeAppearance
    "red""r"[1 0 0 1]"#FF0000"

    Sample of the color red

    "green""g"[0 1 0 1]"#00FF00"

    Sample of the color green

    "blue""b"[0 0 1 1]"#0000FF"

    Sample of the color blue

    "cyan" "c"[0 1 1 1]"#00FFFF"

    Sample of the color cyan

    "magenta""m"[1 0 1 1]"#FF00FF"

    Sample of the color magenta

    "yellow""y"[1 1 0 1]"#FFFF00"

    Sample of the color yellow

    "black""k"[0 0 0 1]"#000000"

    Sample of the color black

    "white""w"[1 1 1 1]"#FFFFFF"

    Sample of the color white

    Version History

    Introduced in R2026b