2
$\begingroup$

I'm new to Mathematica, and I'm trying to figure out how to visualise a rotated cuboid as an output of its rotation matrix and original dimensions using Graphics3D. I am aware this is quite a rudimentary question, but I somehow cannot figure it out despite hours of trying out codes :(

So, simplistically, I have a cuboid, and I apply a rotation transformation function on it, so I write my code as such:

OriginalCuboid = {{x1,y1,z1},{x2,y2,z2}}
RotationMatrixforCuboid = RotationTransform[θ,{1,0,0},{0,0,0}]
RotatedCuboid = RotationMatrixforCuboid[OriginalCuboid]

Mathematica gives an output of "RotatedCuboid" in the form of a Parallelepiped, like so:

Parallelepiped[{point,vector1,vector2,vector3}]

I'm already a little confused because shouldn't it be returning the expression for a cuboid? But sure, I'll take it. So now I want to visualise this using Graphics3D. But for some reason, when using this syntax:

Manipulate[Graphics3D[Opacity[0.5, Red], EdgeForm[Black],{*Insert shape here*}, Axes->True, AxesLabel->{"X", "Y", "Z"}, PlotRange->{{-20,20},{-20,20},{-20,20}}],{{θ,0, "θ rotation"},0,360,1}]

there was an error when I tried to plug "RotatedCuboid" into {Insert shape here} of the code above. There's also an error when I tried to give the Parallelepiped output expression a placeholder name, like such:

RotatedParallelepiped=*whatever, the output of the parallelepiped expression, was*

This is the error:

Coordinate {*whatever my coordinate is* should be a triple of numbers or a Scaled form.

It's driving me insane because the only thing working for me right now is manually copying and pasting the output expression for the Parallelepiped. However, I have multiple Parallelepiped in my actual code, and their expressions are extremely long and inefficient.

Could a kind soul please help me out? Feel free to ask any follow-up questions to clarify if there's anything I'm not clear about. Thank you in advance!

$\endgroup$
2
  • $\begingroup$ RotationMatrix is Mathematica's function so it can not be used as a variable (you cannot assign any value to it). What RotationMatrixforCuboid is? I do not see any definition of it in your code. $\endgroup$ Commented Jan 22 at 20:46
  • $\begingroup$ @azerbajdzan It seems like I have left part of the code out; apologises! I have edited the first line to correctly reflect what I meant $\endgroup$ Commented Jan 23 at 0:52

1 Answer 1

1
$\begingroup$

Is this what you want? The rotation vector is fixed in this code. But can easily make it variable as well.

enter image description here

Manipulate[
 Graphics3D[
  {{Yellow, Opacity[.05], Cuboid[{-0.5, -0.5, -0.5}]},
   GeometricTransformation[Cuboid[{-0.5, -0.5, -0.5}], 
    RotationTransform[x   Degree, {1, 0, 0}]]},
  Boxed -> False,
  PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}]
 ,
 {{x, 0, "degree"}, 0, 180, 0.1, Appearance -> "Labeled"},
 TrackedSymbols :> {x}]

You can also just use Rotate function

enter image description here

Manipulate[
 Graphics3D[
  {{Yellow, Opacity[.05], Cuboid[{-0.5, -0.5, -0.5}]},
   Rotate[Cuboid[{-0.5, -0.5, -0.5}], 
    x  Degree, {0, 0, 1}, {0, 0, 0}]},
  Boxed -> False,
  PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}]
 ,
 {{x, 0, "degree"}, 0, 180, 0.1, Appearance -> "Labeled"},
 TrackedSymbols :> {x}]

how you would suggest "making the rotation vector variable as well",

One way is to make a popumenu and select the rotation vector from a list

enter image description here

Manipulate[
 Graphics3D[
  {{Yellow, Opacity[.05], Cuboid[{-0.5, -0.5, -0.5}]},
   Rotate[Cuboid[{-0.5, -0.5, -0.5}], x  Degree, w, {0, 0, 0}]},
  Boxed -> False,
  PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}]
 ,
 {{x, 0, "degree"}, 0, 180, 0.1, Appearance -> "Labeled"},
 {{w, {0, 0, 
    1}}, {{0, 0, 1} -> {0, 0, 1}, {0, 1, 0} -> {0, 1, 0}, {1, 0, 
     0} -> {1, 0, 0}, {1, 1, 0} -> {1, 1, 0}, {1, 0, 1} -> {1, 0, 1}},
   PopupMenu},
 TrackedSymbols :> {x, w}]
$\endgroup$
3
  • $\begingroup$ Hello! Thank you very much for your reply :) But I was actually asking about how to write my "Manipulate" line of code without needing to explicitly write out my Parallelepiped expression in terms of its position and 3 vectors, and instead use an expression based on the product of my rotation matrix and specific cuboid. $\endgroup$ Commented Jan 22 at 18:45
  • $\begingroup$ Also, since you brought it up, could I ask how you would suggest "making the rotation vector variable as well", if it's not too troublesome for you? This is coincidentally another problem that I am facing in my code. I have 2 cuboids, and one of them is attached to the other one at a joint. Both are able to rotate about the same axis, X. But currently I'm facing problems trying to define a variable rotation origin for the attached cuboid, as a function of the rotation angle of the first one. Thank you so much for your help! $\endgroup$ Commented Jan 22 at 18:49
  • $\begingroup$ What I'm trying out right now is to find the coordinates of the edge of the first cuboid using PolyhedronCoordinates, and then just plug those equations in for the rotation origin of my second cuboid attached to the joint of the first one. Do let me know if that's incorrect or if there's any more efficient method. Thanks! $\endgroup$ Commented Jan 22 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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