WolframLang: GraphicsComplex

By Xah Lee. Date: . Last updated: .

GraphicsComplex

GraphicsComplex is a data structure that efficiently represent a list of Graphics Primitives with shared points. e.g. typically, a list of polygons of a surface will share edges and vertexes.

syntax:

GraphicsComplex[ ListOfPoints, ListOfGraphicsPrimitives]

in ListOfGraphicsPrimitives, any argument of graphics primitives, is taken as index to ListOfPoints.

Example: Triangles Sharing Edge

(*
3 4
1 2
*)

Graphics[
GraphicsComplex[
{{0, 0}, {0, 1}, {1, 0}, {1, 1}},
{
{Red, Polygon[{1,2,3}]},
{Green, Polygon[{2,4,3}]},
{Blue, PointSize[ 0.05 ], Point[ {1,2,3,4} ]}
}
],
Frame -> True
]
wl GraphicsComplex 2024-06-06 CTNZ
wl GraphicsComplex 2024-06-06 CTNZ

Example: Square Polygons Sharing Edge

xgrid = Flatten[ Table[ {x,y}, {x,0,2}, {y,0,2}], 1 ]
(* {{0, 0}, {0, 1}, {0, 2}, {1, 0}, {1, 1}, {1, 2}, {2, 0}, {2, 1}, {2, 2}} *)

(*
7 8 9
4 5 6
1 2 3
*)

Graphics[
GraphicsComplex[
xgrid,
{
EdgeForm[ Red ],
Polygon[{1,2,5,4}],
Polygon[{2,3,6,5}],
Polygon[{4,5,8,7}],
Polygon[{5,6,9,8}]
}
],
Axes -> True
]
wl GraphicsComplex 2024-06-06 zpFt
wl GraphicsComplex 2024-06-06 zpFt

Convert GraphicsComplex to Graphics Primitives

use Normal to turn a GraphicsComplex to list of Graphics Primitives

gc = GraphicsComplex[
{{0, 0}, {0, 1}, {1, 0}, {1, 1}},
{
{Red, Polygon[{1,2,3}]},
{Green, Polygon[{2,4,3}]},
{Blue, PointSize[ 0.05 ], Point[ {1,2,3,4} ]}
}
]

Normal[ gc ]
wl GraphicsComplex 2024-06-06 CNJj
wl GraphicsComplex 2024-06-06 CNJj

WolframLang, Graphics Programing