Why does clipping fail to work with MATLAB 3-D plots in MATLAB R2014a and earlier?

1 view (last 30 days)
Clipping does not seem to work with 3-D plots. The plot will go outside the axes even when I have clipping 'on'.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 3 Sep 2015
The clipping facility in MATLAB is intended primarily for 2-D plots. Therefore, when you have a 3-D plot, it is handled as if it is a 2-D plot.
As a possible workaround you can try the following:
Suppose the equation of the slicing plane is A*x + B*y+ C*z = D for scalar A,B,C,D, then the boolean expression
 
d = find(A*x + B*y + C*z > D)
will produce an index vector into the x,y,z matrices (all assumed to be the same size).
The following subsequent commands
 
n = NaN;
x(d) = n(ones(size(d)));
y(d) = n(ones(size(d)));
z(d) = n(ones(size(d)));
will produce x,y,z matrices with NaN's on one side of the plane. Plotting the data will produce the desired plot.
Here is an example:
 
A = .1; B = -1; C = .3; D = .9; n = NaN; N = 200;
[x,y,z] = sphere(N);
d = find(A*x + B*y + C*z > D);
x(d) = n(ones(size(d)));
y(d) = n(ones(size(d)));
z(d) = n(ones(size(d)));
surf(x,y,z,'edgecolor','none')
hold on
[x,y,z] = sphere(N); x = x*.5; y = y*.5; z = z*.5;
d = find(A*x + B*y + C*z > D);
x(d) = n(ones(size(d)));
y(d) = n(ones(size(d)));
z(d) = n(ones(size(d)));
surf(x,y,z,'edgecolor','none')
hold off
Note that starting with MATLAB R2014b clipping of 3D plots is fully supported: "The Clipping property clips plotted objects to the six sides of the axes box defined by the axis limits." Please refer to http://www.mathworks.com/help/releases/R2014b/matlab/release-notes.html
 

More Answers (0)

Categories

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

Products


Release

No release entered yet.

Community Treasure Hunt

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

Start Hunting!