3
$\begingroup$

I want to find the centroid of a graphics primitive after a series of rotation and translation transforms. But it seems that graphics transforms don't "evaluate". For example, FullForm[Graphics3D[Translate[Sphere[{0, 0, 0}], {1, 0, 0}]]] returns unevaluated. So DiscretizeGraphics[Graphics3D[Translate[Sphere[{0, 0, 0}], {1, 0, 0}]]] command does not work. I also tried DiscretizeGraphics[Graphics3D[GeometricTransformation[Sphere[{0, 0, 0}],TranslationTransform[{1, 0, 0}]]]], it also doesn't work. Is there a geometric transform function that explicitly transforms the coordinates of the graphics objects?

$\endgroup$
2
$\begingroup$

It is easy to miss, but in the documentation for GeometricTransformation it says

Normal[expr] if possible replaces all GeometricTransformation[Subscript[g, i],\[Ellipsis]] constructs by versions of the Subscript[g, i] in which the coordinates have explicitly been transformed.

so in this case you have

In[360]:= Normal@
 GeometricTransformation[Sphere[{0, 0, 0}], 
  TranslationTransform[{1, 0, 0}]]

Out[360]= Sphere[{1, 0, 0}, 1]

Note it isn't too difficult to find GeometricTransformation expressions that do not convert via Normal, so I guess that "if possible" comes into play there.

| improve this answer | |
$\endgroup$
  • $\begingroup$ That works for translation, but already for rotation of a cube it doesn't seem to. FullForm[Normal[ Graphics3D[ GeometricTransformation[Cuboid[{0, 0, 0}, {1, 1, 1}], RotationMatrix[Pi/4, {1, 0, 0}]]]]] $\endgroup$ – Mike R Jun 24 at 13:46
  • $\begingroup$ @MikeR - use RotationTransform instead of RotationMatrix, but it still fails. What seems to work in that case is TransformedRegion[Cuboid[{0, 0, 0}, {1, 1, 1}], RotationTransform[Pi/4, {1, 0, 0}]] $\endgroup$ – Jason B. Jun 24 at 14:18
  • $\begingroup$ Yes, that works! Also works for several sequential transforms, which is what I was looking for. $\endgroup$ – Mike R Jun 24 at 14:35
2
$\begingroup$

You could use my NormalizeGraphics function for this:

NormalizeGraphics @ Graphics3D[Translate[Sphere[{0,0,0}],{1,0,0}]] //InputForm

Graphics3D[Sphere[{1, 0, 0}, 1]]

| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.