1
$\begingroup$

I want to make a simulation of a rigid body with mathematica, but I want to use a Geometry3D object instead of a Graphics3D primitive.

Mainly I don't know how to rotate the 3D model, I know how to do it with graphs through for example:

GeometricTransformation[ring3,EulerMatrix[{alpha, beta, gamma}, {1, 2, 3}]]

Is there any way to rotate and translate the 3D model in such a way?

thankx in advance

$\endgroup$
3
  • 1
    $\begingroup$ Look up TransformedRegion $\endgroup$
    – Carl Woll
    Oct 24 '20 at 1:34
  • $\begingroup$ I find GeometricTransfomation following your suggestion, I think it will do it, thank you! $\endgroup$
    – Gluoncito
    Oct 24 '20 at 1:41
  • $\begingroup$ Perhaps my question 198323 could give you some ideas on how to deal with transformations. $\endgroup$
    – Tim Laska
    Oct 24 '20 at 1:41
4
$\begingroup$

You can transform a GraphicsComplex too. For example:

Manipulate[
 cow /. {GraphicsComplex[vtx_, args___] :> 
    GeometricTransformation[GraphicsComplex[vtx, args], 
     Dynamic[EulerMatrix[{α, β, γ}]]]}, \
{{α, 0}, 0, 2 Pi, Pi/32}, {{β, 0}, 0, 2 Pi, 
  Pi/32}, {{γ, 0}, 0, 2 Pi, Pi/32}, 
 Initialization :> {cow := ExampleData[{"Geometry3D", "Cow"}]}, 
 ControlPlacement -> Top]

Cow rotation

Update: Extend Response to Comment

If you look at the InputForm of the example data, you can see the GraphicsComplex

Short[InputForm[ExampleData[{"Geometry3D", "Phobos"}]], 5]
(* \!\(
TagBox[
PaneBox["\<\"Graphics3D[{EdgeForm[], \
GraphicsComplex[{{-1.3601044416427612, 9.545239448547363, \
0.0012262604432180524}, {-1.2952135801315308, 9.546309471130371, \
0.36269038915634155}, {-0.7759165167808533, 9.590052604675293, \
0.5633725523948669}, <<9405>>, {5.872391700744629, \
3.5175044536590576, 9.917975425720215}, {-11.840780258178711, \
2.7396738529205322, -4.5116286277771}}, <<2>>]}, Boxed -> False]\"\>"],
Short[#, 5]& ]\) *)

You can see that the GraphicsComplex contains a list of vertices or points and geometric entities that refer to the vertices by index.

You can use Cases to extract the GraphicsComplex by itself.

First@Cases[ExampleData[{"Geometry3D", "Phobos"}], _GraphicsComplex, 
  Infinity]

enter image description here

The geometric transform operates on the vertices only. If you want to extract the vertices and the argument separately, you can use:

With[{gc = 
   First@Cases[
     ExampleData[{"Geometry3D", "Phobos"}], _GraphicsComplex, 
     Infinity]}, 
 gc /. {GraphicsComplex[vtx_, args___] :> {vtx, args}}]

Vertex and Arguments

Here is an example of how to rotate Phobos:

phobos = ExampleData[{"Geometry3D", "Phobos"}];
With[{shape = phobos, a = 0, b = 0, c = 0}, 
 shape /. {GraphicsComplex[vtx_, args___] :> 
    GeometricTransformation[GraphicsComplex[vtx, args], 
     EulerMatrix[{a, b, c}]]}]
With[{shape = phobos, a = 10, b = 5, c = 6}, 
 shape /. {GraphicsComplex[vtx_, args___] :> 
    GeometricTransformation[GraphicsComplex[vtx, args], 
     EulerMatrix[{a, b, c}]]}]

Phobos rotation

Update: Space Shuttle Request for Alex

Manipulate[
 spaceshuttle /. {GraphicsComplex[vtx_, args___] :> 
    GeometricTransformation[GraphicsComplex[vtx, args], 
     Dynamic[EulerMatrix[{α, β, γ}]]]}, \
{{α, 0}, 0, 2 Pi, Pi/32}, {{β, 0}, 0, 2 Pi, 
  Pi/32}, {{γ, 0}, 0, 2 Pi, Pi/32}, 
 Initialization :> {spaceshuttle := 
    ExampleData[{"Geometry3D", "SpaceShuttle"}]}, 
 ControlPlacement -> Top]

Space shuttle

$\endgroup$
4
  • $\begingroup$ Good answer (+1). Could you replace image cow with "SpaceShuttle"? $\endgroup$ Oct 24 '20 at 10:54
  • 1
    $\begingroup$ @Gluoncito I put an extended response in my answer. $\endgroup$
    – Tim Laska
    Oct 24 '20 at 16:40
  • $\begingroup$ @AlexTrounev I added a Space Shuttle example. $\endgroup$
    – Tim Laska
    Oct 24 '20 at 16:49
  • $\begingroup$ @Tim Laska, I deleted my earlier comment because I realized that GraphicsComplex was the "magic" word lacking when loading the 3D model. Your detailed response was very useful, thank you very much ! $\endgroup$
    – Gluoncito
    Oct 24 '20 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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