Make a cylinder with an elliptical base or translate an area

7 views (last 30 days)
I have to make an elliptical base cylinder. As an idea I thought of making the outer coat + the two bases with different graphics. For the base I did:
area(x,y)
for the cloak:
surf([x;x],[y;y],z)
for the upper base I don't know how to do it (is there a way to translate the area for example? or a command to do everything more simply?)
Where x and y are the point of ellips, and z is a matrix whit first row is 0 and second is 1.

Answers (1)

Abhishek
Abhishek on 29 May 2025
Edited: Abhishek on 30 May 2025
To complete the figure and plot the upper base of the elliptical cylinder, a simple way is to reuse the same 'x' and 'y' coordinates from the bottom base and just shift them upward along the z-axis. Since the bottom is at 'z = 0', one can place the top at 'z = 1' by setting all the z-values to 1.
'fill3' function can be used for this purpose. This particular function allows to draw a filled polygon in 3D space.
Let’s assume a base ellipse defined using this
x = a * cos(theta);
y = b * sin(theta);
Then the top base can be defined like this:
fill3(x, y, ones(size(x)), 'blue');
This line uses the 'fill3' function to draw a filled 3D polygon—specifically, the top elliptical base of the cylinder.
  • 'x' and 'y' are the coordinates of the ellipse in the horizontal plane.
  • 'ones(size(x))' creates a vector of ones the same size as 'x', meaning all the 'z' values are set to 1—so the entire shape lies in the horizontal plane at 'z = 1'.
  • 'blue' sets the color of the filled surface to blue
This complements the bottom base ('z = 0') and the vertical surface created with 'surf'. 'fill3' is useful here because it directly accepts the 'x', 'y', and 'z' coordinates variables and renders a filled 3D shape.
I tested this approach in MATLAB R2024b, here is the output:
For more details, please refer the following documentations:
Hopefully, this helps resolve the issue. If the problem persists, feel free to share more details.
  2 Comments
Rudraksh
Rudraksh on 1 Jun 2025
I was facing somewhat similiar issue. Thanks for helping out @Abhishek! On a side note, I would like to ask, that can fill3 also be used for the bottom base (z = 0) instead of area(x, y) to keep the code consistent?
Abhishek
Abhishek on 8 Jun 2025
Yes, you can use 'fill3' for the bottom base as well. Just set the 'z-values' to 0 like this:
fill3(x, y, zeros(size(x)), 'blue');

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!