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$
1

2 Answers 2

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.

$\endgroup$
6
  • $\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
    Commented Jun 24, 2020 at 13:46
  • 1
    $\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.
    Commented Jun 24, 2020 at 14:18
  • $\begingroup$ Yes, that works! Also works for several sequential transforms, which is what I was looking for. $\endgroup$
    – Mike R
    Commented Jun 24, 2020 at 14:35
  • $\begingroup$ TransformedRegion is better for me than GeometricTransformation, but unfortunately the following code inexplicably doesn't do anything: TransformedRegion[ Parallelepiped[{1.0, 0.0, 0.0}, {{-1., 1., 0.}, {0., 0., 1.0}, {0., 0., 1.}}], RotationTransform[0, {1, 1, 1}]]. Any idea why? $\endgroup$
    – Liam Baker
    Commented Oct 3, 2023 at 13:35
  • $\begingroup$ @LiamBaker your Parallelepiped has two identical vectors, is that valid? It works in Graphics3D but all region functionality rejects it. $\endgroup$
    – Jason B.
    Commented Oct 3, 2023 at 18:52
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]]

$\endgroup$

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