Circle On 3d Axes

7 views (last 30 days)
arash
arash on 14 Nov 2014
Edited: arash on 14 Nov 2014
I am newbie in `Matlab`. I want to draw a circle on a 3d Axes and move the circle on mouse move.
I tried something like below code :
function drag_patch
figure('WindowButtonMotionFcn',@figButtonMotion);
ax = axes;
xlabel('x axis')
ylabel('y axis')
zlabel('z axis')
view(-37.5,30);
np = 2; % number of patches to create
p = zeros(1,np); % patch handles
x = cell(1,np); % shape x-values
y = cell(1,np); % shape y-values
% Create the Patches
for k = 1:np
sides = 50;
psi = 2*pi*(0.03 + (0:sides-1)/sides);
x{k} = cos(psi); % shape XData
y{k} = sin(psi); % shape YData
z{k} = sin(psi); % shape ZData
clr = sqrt(rand(1,3)); % shape Color
p(k) = patch(x{k}+5*randn,y{k}+5*randn,z{k},clr);
set(p(k),'UserData',k,'ButtonDownFcn',{@patchButtonDown,p(k)});
end
axis equal
patch_clicked = 0;
this_p = p(1);
this_k = 1;
% Function for Identifying Clicked Patch
function patchButtonDown(this,varargin)
this_p = this;
this_k = get(this,'UserData');
patch_clicked = ~patch_clicked;
end
% Function for Moving Selected Patch
function figButtonMotion(varargin)
if patch_clicked
% Get the Mouse Location
curr_pt = get(ax,'CurrentPoint');
% Change the Position of the Patch
set(this_p,'XData',x{this_k}+curr_pt(1,1),'YData',y{this_k}+curr_pt(1,2));
end
end
end
I achieved this,below image shows the result :
But i want something like this Circle:
%

Answers (0)

Community Treasure Hunt

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

Start Hunting!