2

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

ubpdqn
  • 60,617
  • 3
  • 59
  • 148
Danny
  • 201
  • 1
  • 6

2 Answers2

3

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}]

Mathematica graphics

Jason B.
  • 68,381
  • 3
  • 139
  • 286
2
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]]

enter image description here

Sumit
  • 15,912
  • 2
  • 31
  • 73