1
$\begingroup$

How can I plot a hexagon inside this cylinder so that it is always in the same direction as the cylinder, no matter what the orientation is? In addition, the hexagon must always be the same size as the cylinder.

For example, start at the origin (10,9,8) and go to (1,2,3)?

Graphics3D [{Cylinder [{{10, 9, 8}, {1, 2, 3}}, 0.5]}

I tried this:

Table [Show [Graphics3D [Cylinder [{{0., 0., 0}, {0., 0., l}}, 1]], PolyhedronData [{"Prism", 6}]], {l, 0.1 , 3, 0.1}]
$\endgroup$

2 Answers 2

1
$\begingroup$
{v1, v2} = {{10, 9, 8}, {1, 2, 3}};
r = .5;
n = 6;
reg = Cylinder[{v1, v2}, r];
{e1, e2} = Most@Normal@Orthogonalize[HodgeDual[v2 - v1]];
pts = Table[
   v1 + r*Cos[2 k*π/n]*e1 + r*Sin[2 k*π/n]*e2, {k, 1, n}];
tranpts = TranslationTransform[v2 - v1] /@ pts;
top = Polygon[pts];
bottom = Polygon[tranpts];
surfaces = 
  MapThread[
   Polygon@*Join, {Partition[pts, 2, 1, 1], 
    Reverse[Partition[tranpts, 2, 1, 1], {2}]}];
Graphics3D[{{Cyan, top, bottom}, 
  Riffle[ColorData["Atoms"] /@ Range[n], surfaces]}, Boxed -> False]

enter image description here

$\endgroup$
1
$\begingroup$

You can use the Method option to get an n-gonal prism inscribed in a clylinder in two ways:

  1. Use the Method suboption "CylinderPoints" -> n, or
  2. Use Tube instead of Cylinder with the Method suboption "TubePoints" -> n
Row[{Graphics3D[{ Opacity[.5, Blue],Cylinder[{{10, 9, 8}, {1, 2, 3}}, 2]}, 
    ImageSize -> 300],
  Graphics3D[{Opacity[.5, Red], Cylinder[{{10, 9, 8}, {1, 2, 3}}, 2]},
    Method -> {"CylinderPoints" -> 6}, ImageSize -> 300],
  Graphics3D[{ CapForm["Butt"], Opacity[.5, Green], Tube[{{10, 9, 8}, {1, 2, 3}}, 2]},
    Method -> {"TubePoints" -> 6}, ImageSize -> 300]}]

enter image description here

With the second method we can have cylinders and inscribed prisms in the same graphics (We cannot do this with the first method since the option "CylinderPoints" -> n applies to all Cylinder objects):

Graphics3D[{ Opacity[.4, Blue],
  Cylinder[{{10, 9, 8}, {1, 2, 3}}, 2], 
  CapForm["Butt"], Opacity[.5, Red],
  Tube[{{10, 9, 8}, {1, 2, 3}}, 2]},
  Method -> {"TubePoints" -> 4}, ImageSize -> Large]

enter image description here

$\endgroup$

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.