2
$\begingroup$

If cylinder is aligned with one of the axis then scaling it in the direction of any axis is easy - producing elliptic cylinder. See image bellow - cylinder was scaled along red arrows.

Graphics3D[{{Opacity[0.5], Cylinder[], 
    Scale[Cylinder[], {2, 1, 1}],}, {Thick, Red, , 
    Arrowheads[{-0.05, 0.05}], {Scale[#, 1], Scale[#, 2]} &@
     Arrow[{{-1, 0, 1}, {1, 0, 1}}]}}];
Style[%, RenderingOptions -> {"3DRenderingMethod" -> "BSPTree"}]

enter image description here

But for arbitrary oriented cylinder I was not able to figure out how to use Scale to scale cylinder along red or blue arrows.

I can do it in a cumbersome way - first rotate the cylinder to align it with one of axis, then scale it and then rotate back to its original position but I guess it may be possible using only Scale without any rotation.

Graphics3D[{{Opacity[0.5], 
   Cylinder[{{1, 2, 1}, {2, 1, 1}}, 3/2]}, {Thick, Red, 
   Arrowheads[{-0.05, 0.05}], {Scale[#, 1], Scale[#, 2]} &@
    Arrow[{{2, 1, 1} - {1, 1, 1}*Sqrt[3]/2, {2, 1, 1} + {1, 1, 1}*
        Sqrt[3]/2}], 
   Blue, {Scale[#, 1], Scale[#, 2]} &@
    Arrow[{{1/8 (16 - 3 Sqrt[2] - 2 Sqrt[3]), 
       1/8 (8 - 3 Sqrt[2] - 2 Sqrt[3]), 
       1/4 (4 + 3 Sqrt[2] - Sqrt[3])}, {1/
        8 (16 + 3 Sqrt[2] + 2 Sqrt[3]), 
       1/8 (8 + 3 Sqrt[2] + 2 Sqrt[3]), 
       1/4 (4 - 3 Sqrt[2] + Sqrt[3])}}]}}]

enter image description here

$\endgroup$

1 Answer 1

4
$\begingroup$

Use GeometricTransformation[..., ScalingTransform[...]] instead, since ScalingTransform accepts the direction and the center point.

p1 = {1, 2, 1};
p2 = {2, 1, 1};

cyl = Cylinder[{p1, p2}, 3/2];

v[ϕ_] := RotationTransform[ϕ, p2 - p1][Cross[p1, p2]];

scaledCylinder[scale_, ϕ_] := GeometricTransformation[cyl, 
   ScalingTransform[scale, v[ϕ], Mean[{p1, p2}]]]

Graphics3D[{Opacity[.2], 
   Yellow, cyl, 
   Orange, scaledCylinder[2, 0], 
   Cyan, scaledCylinder[1.5, Pi/2]
}];

enter image description here

$\endgroup$
2
  • $\begingroup$ (+1) So is it impossible with Scale? Reading documentation of Cylinder Properties & Relations you can get an impression like if you want an elliptic cylinder just use Scale. But if it is impossible to do it with any direction of cylinder, then the documentation is misleading. $\endgroup$ Commented Oct 9 at 17:30
  • $\begingroup$ @azerbajdzan, not sure, but to me it looks like Scale only works in the along the main axes ... And the documentation just gives the very basic example :/ $\endgroup$
    – Domen
    Commented Oct 10 at 15:41

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.