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
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.