Function Repository Resource:

GraphicsPrimitiveQ

Source Notebook

Test if a piece of a graphic is a graphics primitive

Contributed by: Enrique Zeleny

ResourceFunction["GraphicsPrimitiveQ"][expr]

test if expr is a graphics primitive.

Details and Options

ResourceFunction["GraphicsPrimitiveQ"] works in both 2D and 3D.
GraphicsComplex and GraphicsGroup are treated like a single primitive in Graphics and Graphics3D.

Examples

Basic Examples (2) 

Test a 3D graphics object:

In[1]:=
ResourceFunction["GraphicsPrimitiveQ"][Point[{1, 2, 3}]]
Out[1]=

Select a 3D graphics object:

In[2]:=
gr = \!\(\*
Graphics3DBox[
{Opacity[0.5], SphereBox[{0, 0, 0}], 
{PointSize[0.025], Point3DBox[{0.8753842058167891, -0.4379222653395013, 0.5403023058681398}], Arrow3DBox[{{0.4546487134128409, -0.7080734182735712, 0.5403023058681398}, {0.8753842058167891, -0.4379222653395013,
         0.5403023058681398}}], Point3DBox[{0.3086854225496265, -0.48074906156715075`, 0.9610377982720879}], Arrow3DBox[{{0.4546487134128409, -0.7080734182735712, 0.5403023058681398}, {
        0.3086854225496265, -0.48074906156715075`, 0.9610377982720879}}], 
{RGBColor[1, 0, 0], Point3DBox[{0.4546487134128409, -0.7080734182735712, 0.5403023058681398}]}, 
{RGBColor[0, 0, 1], Opacity[0.25], 
TagBox[ConicHullRegion3DBox[{0.4546487134128409, -0.7080734182735712, 0.5403023058681398}, {{1.0906471188907174`, 0.7002964616297819, 0}, {-0.04627883350948789, 0.07207501279569456, 0.1333975665343253}}],
"InfinitePlane"]}}},
Axes->True,
ViewPoint->{1.3, -2.4, 2.},
ViewVertical->{0., 0., 1.}]\);

Extract and sort inner graphics primitives:

In[3]:=
Sort@Cases[gr, _?ResourceFunction["GraphicsPrimitiveQ"], \[Infinity]]
Out[3]=

Iconize points:

In[4]:=
ig = Sort@
  Cases[gr, gp_?ResourceFunction[
     "GraphicsPrimitiveQ"] :> (Iconize@gp), \[Infinity]]
Out[4]=

Look at the internal structure of graphics iconizing points:

In[5]:=
MapAt[Hold, gr /. gp_?ResourceFunction["GraphicsPrimitiveQ"] :> (Iconize@gp), 0]
Out[5]=

Recover primitives:

In[6]:=
{Arrow[{{0.4546487134128409, -0.7080734182735712, 0.5403023058681398}, {0.3086854225496265, -0.48074906156715075`, 0.9610377982720879}}], Arrow[{{0.4546487134128409, -0.7080734182735712, 0.5403023058681398}, {0.8753842058167891, -0.4379222653395013, 0.5403023058681398}}], Point[{0.3086854225496265, -0.48074906156715075`, 0.9610377982720879}], Point[{0.4546487134128409, -0.7080734182735712, 0.5403023058681398}],
  Point[{0.8753842058167891, -0.4379222653395013, 0.5403023058681398}], Sphere[{0, 0, 0}]}
Out[6]=
In[7]:=
Graphics3D[%]
Out[7]=

Possible Issues (1) 

Some types of graphics objects are not primitives:

In[8]:=
Cases[ConvexHullMesh[RandomReal[{-1, 1}, {50, 3}]], _?
  ResourceFunction["GraphicsPrimitiveQ"], \[Infinity]]
Out[8]=

Publisher

Enrique Zeleny

Version History

  • 1.0.0 – 23 September 2020

Related Resources

License Information