matlab implicit function equivalent to do (high) line & isosurface

Abhorrent complete set related to the two-dimensional isosurface made on the three-dimensional space and the implicit function (line) in FIG.

2-dimensional, 3-dimensional object are the same, is to make the structure of FIG implicit function represented by the function value zero is considered surface point and displayed, and then calculates the contour (surface) area (outside the enclosed volume ) as a percentage of the area of ​​the entire space (volume).

I.2 dimensional plane contour implicit functions

Contours on the 2-dimensional plane using FIG contourffunction can be achieved. You should also have a number of other methods.

Using the function \ (z = \ cos (x ) * \ cos (y) +0.5 \)

Filling made with 1 equivalent of (high) line in FIG.

clear all;
clc;
% 给出定义域,生成网格。
x = 0:0.01:2*pi;
y = 0:0.01:2*pi;
[X, Y] = meshgrid(x, y);

% 给出隐函数表达式
Z = cos(X).*cos(Y)+0.5;

% 做等值线图
ax = figure;
[M, C] = contourf(X, Y, Z);
axis off;

C.LineWidth = 1;
C.ShowText = 'on';

The generated image is:

according to the method of binary function extremum, \ (\ FRAC {\ partial {Z} \} partial X \) , \ (\ FRAC {\ partial} Z {\ partial} Y \) is equal to 0, and \ (\ frac {\ partial ^ 2 f} {\ partial x ^ 2} \ frac {\ partial ^ 2 f} {\ partial y ^ 2} - (\ frac {\ partial ^ 2 f} {\ X partial \ partial Y}) ^ 2> 0 \) , the x, y as a function of the extreme point, when the \ (\ frac {\ partial ^ 2 f} {\ partial x ^ 2} and \ frac {\ partial ^ 2 f} {\ partial y ^ 2} is greater than 0, for the minimum value is less than 0, for the maximum value function determined maxima are (0, 0), (\) \ $ PI, \ (\ PI \) ), the function value 1.5. Minimum point are (0, \ (\ PI \) ), ( \ (\ PI \) , 0), the function value -0.5.
The image can be seen from the maximum value and the minimal value point, and the function of the period in the x, y are \ (2 \ PI \) .

2. The filling made with equivalent function value (high) line 0

Call the above modified contourfform, by the way ShowText off.

...
[M, C] = contourf(X, Y, Z, [0, 0]);
...
C.ShowText = 'off';

The image obtained as follows:

the above image is not made on the boundary contours, therefore, use maxthe function to increase the image boundary.

...
% 给出隐函数表达式
Z = max(max(cos(X).*cos(Y)+0.5, X.*(X-2*pi+0.01)), ...
    Y.*(Y-2*pi+0.01));
...

After the image is made:

why use \ (. X * (X- 2 * pi + 0.01) \) and \ (. The Y-* (the Y-PI-2 + 0.01 *) \) , because when not using 2pi make the boundary may be due to time is plotted in a similar matlab sitting right open interval drawn closed, so the X, Y reduced 0.01.

Another problem is the filling, I want to achieve internal contour filling, rather than external padding.
Search for a long time did not find a way through the colormap set the color gradient, which is always white, as shown below.

map = [0 0 0;
        1 1 1];
colormap(ax, map);

The resulting image is:

Finally found, colormap is filled between the image contours, because I only drew a \ (z = 0 \) contour, it can only be filled outside contour.
Modify the code as follows:

...
[M, C] = contourf(X, Y, Z ,[-0.5, 0]);    % 因为最小值为-0.5
axis off;
...
map = [0, 0.6, 1;
        1, 1, 1];
colormap(ax, map);

To obtain an image:

3. The external contour to give the percentage of total area

Because the discrete data is used, it is greater than the sum of all the nodes 0, i.e. all nodes and dividing by the approximate percentage of the area occupied by voids.

...
lenX = length(x);
lenY = length(y);
tot = lenX * lenY;
num_in_con = 0;
for i=1:1:lenX
    for j=1:1:lenY
        if (Z(i, j) > 0)
            num_in_con = num_in_con + 1;
        end
    end
end

per = num_in_con / tot;

The results obtained for theper=0.8160;

II. 3-dimensional isosurface implicit function

Guess you like

Origin www.cnblogs.com/AIxiaodi/p/12512425.html