Make a cylinder with an elliptical base or translate an area
Afficher commentaires plus anciens
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.
Réponses (1)
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:
- ‘fill3’: https://www.mathworks.com/help/releases/R2024b/matlab/ref/fill3.html
- ‘surf’: https://www.mathworks.com/help/releases/R2024b/matlab/ref/surf.html
Hopefully, this helps resolve the issue. If the problem persists, feel free to share more details.
2 commentaires
Abhishek
le 8 Juin 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');
Catégories
En savoir plus sur Polar Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!