How to trace the perimeter of a circle using a circle of various colors. I want to change color of the tracing circle every 45 degrees with respect to the vertical axis (for a total of eight colors)
1 view (last 30 days)
Show older comments
%ask user for radius
radius= input ('please provide radius of circle= ')
%display figure figure axis([-10 10 -10 10 ]) grid on %allow user to click on the centeer of cirlce center = ginput(1);
%generatee grid theta = linspace(pi/2,2*pi+pi/2,100);
%evaluate x and y
x= radius *cos(theta)+center(1);
y = radius *sin(theta)+center(2);
%plot circle adn trace
for idx = 1 : length(x)
figure(1)
plot(center(1),center(2),'ro',x,y,'g',x(idx),y(idx),'go','linewidth',3.0)
xlabel('x')
ylabel('y')
axis([-10 10 -10 10])
grid on
pause(.1)
end
1 Comment
dpb
on 22 Feb 2015
Edited: dpb
on 22 Feb 2015
Why TMW doesn't implement some higher-level circle() and/or arc() functions instead of forcing to draw in x-y coordinates w/ handle graphics has always amazed me...
But, anyway, the line color is a line property so you'll need eight line segments, one of each color.
Or, mayhaps someone else has thought the same thing already and has submitted something on the File Exchange previously. I haven't checked...
Answers (1)
Image Analyst
on 22 Feb 2015
Trivial. Use the FAQ to draw an arc in the color you want: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_an_arc.3F
Repeat 7 more times with different colors.
0 Comments
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!