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?
-
4$\begingroup$ Possibly a duplicate of Why doesn't Normal[] work on GeometricTransformation? $\endgroup$– Jason B.Commented Jun 24, 2020 at 17:30
2 Answers
It is easy to miss, but in the documentation for GeometricTransformation
it says
Normal[expr]
if possible replaces allGeometricTransformation[Subscript[g, i],\[Ellipsis]]
constructs by versions of theSubscript[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.
-
$\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 RCommented Jun 24, 2020 at 13:46 -
1$\begingroup$ @MikeR - use
RotationTransform
instead ofRotationMatrix
, but it still fails. What seems to work in that case isTransformedRegion[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 RCommented Jun 24, 2020 at 14:35
-
$\begingroup$
TransformedRegion
is better for me thanGeometricTransformation
, 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$ Commented Oct 3, 2023 at 13:35 -
$\begingroup$ @LiamBaker your
Parallelepiped
has two identical vectors, is that valid? It works inGraphics3D
but all region functionality rejects it. $\endgroup$– Jason B.Commented Oct 3, 2023 at 18:52
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]]