Message Boards Message Boards

0
|
2988 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Transformation matrix to align cylinder with cube?

Posted 3 years ago

I have a cube whose center is at the origin and want to draw a line from one corner to the opposite corner of the cube.

s = 1;
c = Cylinder[{{-s, s, s}, {s, -s, -s}}, holeRadius];
b = PolyhedronData["Cube", "ImplicitRegion"];

rd = RegionDifference[b, c];
output = RegionPlot3D[rd, PlotPoints -> 42]

This code works fine, but when I try to rotate the cylinder {{0,0,0}, {1,0,0}} about the origin using 45,45,45 it doesn't line up with the corner of the cube. Why?

POSTED BY: Brian OBrien
2 Replies
Posted 3 years ago

I'm sorry.. i actually didn't write the question well enough. And your response is perfect... i naively assumed that rotating 0, 45,45 would do the trick but it doesn't. I seem to remember that the order of rotation is important... i.e. rotating an object about x then y then z is not the same as rotating an object about y, x and z. I was having trouble believing that the angles from the origin to the corner were all the same. In the end, this should also be the way I get a cube to stand on one of its corners. Thank you very much.

Brian.

PS. Is the a vertex normal or face normal method one can call on an object?

POSTED BY: Brian OBrien
Posted 3 years ago

Combinations of 0 and 90 degrees will position the cylinder along the cube diagonals:

s = 1;
holeRadius = 0.18;
c = Cylinder[{{-s, s, s}, {s, -s, -s}}, holeRadius];


Manipulate[
    Graphics3D[{
        Rotate[         
             Rotate[
               Rotate[c, x Degree, {1, 0, 0}],
               y Degree, {0, 1, 0}
           ],
             z Degree, {0, 0, 1}
           ],
        Opacity@0.5,
        Cube[1.7]
    }, Boxed -> False],
    {x, {0, 90}}, {y, {0, 90}}, {z, {0, 90}},
    SaveDefinitions -> True
 ]

EDIT :

Sorry Brian, I misunderstood. Did not read your question close enough.

To rotate a Cylinder[{{0, 0, 0},{1, 0, 0}} so it points to a cube corner:

  • Keep X angle at zero. A rotation around cylinder axis will not change orientation.
  • Let Y angle be either + or - 35.2644. Which is plus or minus $\sin ^{-1}\left(\frac{1}{\sqrt{3}}\right)$
  • Alternate Z angle between -135, -45, 45, 135

    Manipulate[
        Graphics3D[{
            Rotate[
                 Rotate[
                   Cylinder[{{0, 0, 0}, {1, 0, 0}}, 0.1],
                   y Degree, {0, 1, 0}
               ],
                 z Degree, {0, 0, 1}
               ],
            Opacity@0.5,
            Cube[]
        }, Boxed -> False, PlotRange -> 1.5],
        {y, {-35.2644, 35.2644}},
        {{z, 45}, {-135, -45, 45, 135}}
     ]
    
POSTED BY: Hans Milton
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract