MATLAB: drawing over the surface

I draw the function R ^ 2 by R in MATLAB as a surface plot, which I print and view from above.

surf(X, Y, data);
colormap(jet);
colobar;
view(2);

It produces (with some additional code) something like

enter image description here

although the true nature of the function (in order to understand this issue) is best observed at an angle similar to:

enter image description here

I want to build a circle on top of my original plot (seen from above). Sort of...

enter image description here

I seem to be unable to achieve this, since the superposition on the plane of the elements in the graphs makes them appear on the xy axis, which is covered by my surface. For example, a call

circle_pos = [ +1 +1; -1 -1; -1 +1; +1 -1;]
circle_rad = 0.2 * ones(4,1);
viscircles(circle_pos, circle_rad);

after my surface chart doesn't show visible circles when viewed from above. Scaling and rotation indicate that these circles were drawn on the xy plane and therefore are invisible from above.

enter image description here

, ? text , z z. , z .

+4
2

z , viscircles, ( ) .


1: .

, , , - handle. viscircles, ( handle, ).:

hg = viscircles(circle_pos, circle_rad);

Image Processing Toolbox, viscircles. , - hggroup. hggroup , handles . hggroup 4 lines ( 4 ).

hggroup - hgtransform. , hgtransform 4 ( hggroup).

, makehgtform.

:

ht = hgtransform ;      % create the transform object
set(hg,'Parent',ht) ;   % make it a "parent" of the hggroup

zc = max(max(Z)) ;  % Find by how much we want to translate the circles on the Z axis
Tz = makehgtform('translate',[0 0 zc]) ;   % create the TRANSLATION transform

set(ht,'Matrix',Tz)     % apply the transformation (translation) to the hggroup/hgtransform

, 4 . , zc ( . ).


2: DIY

, , .

, , viscircles, z .

circles_3D.m:

function hg = circles_3d( pos , rad , varargin )

% get current axes handle and hold state
ax = gca ;
holdState = get(ax,'NextPlot') ;    % save state to reinstate after function
set(ax,'NextPlot','add') ;          % equivalent of "hold off"

tt = linspace(0,2*pi) ;
hg = hggroup(ax) ;
for k = 1:numel(rad)

    c = pos(k,:) ;
    r = rad(k) ;
    x = c(1) + r.*cos(tt) ;
    y = c(2) + r.*sin(tt) ;
    z = zeros(size(x)) ;
    if numel(c)==3 ; z = z + c(3) ; end

    plot3(hg,x,y,z,varargin{:}) ;
end

set(ax,'NextPlot',holdState) ; % restore axes hold state

viscircles. varargin line ( Color, LineWidth , .

, , 4x "" , :

pc = 0.5 ;  % pole centers
pw = 0.05 ; % pole widths

% surface definition
[X,Y] = meshgrid(-5:.1:5);
R = sqrt(X.^2 + Y.^2) + eps ;
Z = sin(R)./R;
% zero surface values around the defined poles
[idxPoles] = find(abs(X)>=pc-pw & abs(X)<=pc+pw & abs(Y)>=pc-pw & abs(Y)<=pc+pw ) ;
Z(idxPoles)= 0 ;
% display
hs = surf(X,Y,Z) ; shading interp

: 3d surf

circles_3D:

zc = max(max(Z)) ;
circle_pos = [ pc pc zc ; -pc -pc zc ; -pc +pc zc ; +pc -pc zc ] ;
circle_rad = 0.2 * ones(4,1);
h = circles_3d( circle_pos , circle_rad , 'Color','r','LineWidth',2) ;

: enter image description here


, , hggroup, (). , , , .

+5

spring .

3d plot3:

figure;
peaks;
shading interp;
hold;
x = 0; y = 2; z = 10;
plot3(x, y, z, 'ro', 'MarkerSize', 24);

, : plot3 marker plot3 marker in 3d

3d:

vfTheta = linspace(0, 2*pi, 300);
figure; peaks; shading interp; hold;
x = 0; y = 2; z = 10; r = 0.2;
plot3(x + r.*cos(vfTheta), y + r.*sin(vfTheta), z .* ones(size(vfTheta)), 'r-', 'LineWidth', 2);

: 3d!

building a circle in 3d beautiful halo

+2

Source: https://habr.com/ru/post/1657843/


All Articles