# Random 3D cylinders plot [duplicate]

I have seen this trivial example for circles

n = 5;
r = 0.2;
Table[pt[i] = RandomReal[{-1, 1}, 2], {i, 1, n}];
Graphics[{Table[Circle[pt[i], r], {i, n}]}, Axes -> True,
PlotRange -> {{-1, 1}, {-1, 1}}]


I would like to draw Random 3D plot of Cylinders with fix height and radius. Best Regards Danny

• Apr 26, 2016 at 9:39

It may be marked as a duplicate, but the answer to that post is more complicated because of the constraint that the cylinders do not intersect. For this question, just create one cylinder with the right length and radius and rotate and translate it randomly,

radius = .3;
length = 5;
cyl = Cylinder[{{0, 0, 0}, {0, 0, length}}, radius];
cylinder :=
cyl // Rotate[#, RandomReal[{0, 2 π}], RandomReal[1, 3]] & //
Translate[#, RandomReal[{-5, 5}, 3]] &

Graphics3D@Table[cylinder, {50}]


n = 5; r = 0.2; pt = RandomReal[{-1, 1}, {n, 2}]
Graphics3D[Cylinder[{{#[[1]], #[[2]], 0}, {#[[1]], #[[2]], 1}}, r] & /@ pt]


If you want more

n = 5; r = 0.2;
pt1 = RandomReal[{-1, 1}, {n, 3}];
pt2 = RandomReal[{-1, 1}, {n, 3}];
Graphics3D[Cylinder[{pt1[[#]], pt2[[#]]}, r] & /@ Range[n]]