2

Currently I can print out this using Graphics3d: Graph Here's the code:

a = (-5 \[Pi])/2;
b = (5 \[Pi])/2;
dx = (b - a)/50;
f[x_] := 2 Cos[x];
startpos[1, k_] := a + (k - 1) dx;
startpos[2, k_] := a + k*dx;
startpos[3, k_] := a + (2 k - 1)/2 dx;

model = Graphics3D[{Table[
Cuboid[{{a + (l - 1) dx, 0, 0}, {a + l*dx, +.01, 
   f[startpos[3, l]] + .01}}], {l, 1, 50, 1}]}];

Show[model]

I want to rotate it around the y-axis. I already tried using RevolutionPlot3d, but I'm not sure how to set it up exactly. Here's my failed attempt:

model = RevolutionPlot3D[{Table[
 Cuboid[{{a + (l - 1) dx, 0, 0}, {a + l*dx, +.01, 
    f[startpos[3, l]] + .01}}], {l, 1, 50, 1}]}, {x, a, b}, 
RevolutionAxis -> "Y", AspectRatio -> Automatic, Mesh -> None, 
BoundaryStyle -> Black, PlotStyle -> Thickness[.1]] ;
Show[model]
user217298
  • 23
  • 3

2 Answers2

2

I would switch approach to something like:

Show[
     RevolutionPlot3D[2 Cos[Floor[x, (Pi/10)]], {x, 0, 9 Pi/2 + .2}, 
                      Exclusions -> None, PlotPoints -> 100, MeshStyle -> Thick],
     RevolutionPlot3D[0, {x, 0, 9 Pi/2}, Exclusions -> None, 
                                         PlotPoints -> 50, MeshStyle -> Thick]
     ,
     ImageSize -> 800]

enter image description here

Kuba
  • 136,707
  • 13
  • 279
  • 740
1

Firstly, no need to use Show, simply remove the ; from the end of your Graphics3D expressions.

Secondly, try evaluating:

Graphics3D[
 Table[Cuboid[{{a + (l - 1) dx, 0, 0}, {a + l*dx, +.01, 
     f[startpos[3, l]] + .01}}], {l, 1, 50, 1}], 
 AxesLabel -> {x, y, z}, Axes -> True, BoxRatios -> 1, Ticks -> None, 
 AxesOrigin -> {0, 0, 0}, Boxed -> False, 
 AxesStyle -> Directive[Orange, 12]]

Orientation plot

Are you sure you want to rotate it about the y-axis? Isn't it going to be a mess?

I suspect you mean the x-axis, in which case basically you want to replace Cuboid[{{x0,0,0},{x1,y1,z1}}] -> Cylinder[{{x0,0,0},{x1,0,0}},Abs[z1]]. (And forget about RevolutionPlot3D which creates surfaces of revolution rather than revolving graphics primitives.)

model = Graphics3D[
  Table[Cylinder[{{a + (l - 1) dx, 0, 0}, {a + l*dx, 0, 0}}, 
    Abs[f[startpos[3, l]]]], {l, 1, 50}]]

Rotated plot

MikeLimaOscar
  • 3,456
  • 17
  • 29