The plotting function implicit3 fails to render under certain conditions. Notably, for sphere larger than a certain amount.

This renders properly :
a = 800;
ff = @(x,y,z) x.^2 + y.^2 + z.^2 - a^2;
fimplicit3(ff);
b = a*1.25;
xlim([-b b])
ylim([-b b])
zlim([-b b])
However,
a = 8000;
ff = @(x,y,z) x.^2 + y.^2 + z.^2 - a^2;
fimplicit3(ff);
b = a*1.25;
xlim([-b b])
ylim([-b b])
zlim([-b b])
does not render

1 Comment

Hello @Vladimir, I ran your code above and the surface renders as expected.
Knowing the MATLAB release you're using and some more information about what you're seeing may help.

Sign in to comment.

 Accepted Answer

The issue here is likely due to fimplicit3’s default mesh resolution not being sufficient when the plotting range becomes very large. When you set a = 8000, the region over which MATLAB samples the implicit function is huge, and the default number of sample points may be too sparse to accurately capture the surface of the sphere.
One workaround is to explicitly define the plotting region and increase the 'MeshDensity' so that more points are used in the evaluation. For example:
a = 8000;
ff = @(x,y,z) x.^2 + y.^2 + z.^2 - a^2;
b = a*1.25;
fimplicit3(ff, [-b b -b b -b b], 'MeshDensity', 100)
xlim([-b b])
ylim([-b b])
zlim([-b b])
This should provide a denser sampling of the implicit surface and render the sphere correctly.
Follow me so you can message me anytime with future MATLAB questions. If this helps, please accept the answer as well.

9 Comments

+ 1 to setting the interval in arg 2 as Jack has shown
fimplicit3(ff, [-b b])
axis equal
No need to specify [-b b -b b -b b] and no need to set the axis limits.
-----------------------------------------------------------------------------------------------------
MATLAB Version: 24.1.0.2603908 (R2024a) Update 3
MATLAB License Number: 41173195
Operating System: Microsoft Windows 10 Enterprise Version 10.0 (Build 19045)
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------------------
Using 'MeshDensity' of 200, it created the Harkonen planet above.

Sign in to comment.

More Answers (1)

I believe the problem is recreated when the axes limits are not set. In this case, the ImplicitFunctionSurface is larger than the default axes limits and since it does not update the axes limits automatically, there's nothing to render within the default axes. If this is the problem, you solved it by setting the axes limits.
a = 8000;
ff = @(x,y,z) x.^2 + y.^2 + z.^2 - a^2;
fimplicit3(ff);
It would be nice if the implicit graphics objects had an option to automatically adjust the axes limits. Many graphics objects have a property AffectAutoLimits that, when set to True, automatically adjust axes limits so that the object is within the axes. I recently wrote about this property in the Text object. However, the ImplicitFunctionSurface may be continuous along at least once axis which would make it difficult/impossible to automatically select axis limits in the continuous dimentions.

Asked:

on 7 Mar 2025

Commented:

on 11 Mar 2025

Community Treasure Hunt

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

Start Hunting!