Straight Lines inside Circles

4 次查看(过去 30 天)
premraj
premraj 2011-9-19
Hi,
How to draw 10 straight lines horizontally and 10 vertically inside a circlular shape.
Please note that the lines are equally spaced.
Thanks in advance.
Prem

回答(3 个)

Walter Roberson
Walter Roberson 2011-9-19
Hint:
linspace(-Radius, Radius, 10+2)
and then throw away the first and last of those results.
  1 个评论
premraj
premraj 2011-9-20
thanks..i tried to create the grids with ur hint.But failed to draw inside the circle.

请先登录,再进行评论。


premraj
premraj 2011-9-20
I could draw the grid lines with specified X/Y line numbers.But don't know how to restrict the lines inside the circle only.
Radius =150;
xGridLineNumbers=10;
yGridLineNumbers=10;
xmin=-Radius ;
ymin=-Radius ;
xmax=Radius ;
ymax=Radius ;
color=[0 0 0]
x = linspace ( xmin, xmax, xGridLineNumbers);
y = linspace ( ymin, ymax, yGridLineNumbers);
for i = 1 : xGridLineNumbers
line ( [ x(i), x(i) ], [ ymin, ymax ],'Color', 'color');
end
for i = 1 : yGridLineNumbers
line ( [ xmin, xmax ], [ y(i), y(i) ],'Color', 'color');
end

premraj
premraj 2011-9-20
I got a simple work around!!! function is given below.
xGridLines is the no of X axis grids required.
yGridLines is the no of Y axis grids required.
Radius is the given radius of the circle.
function DrawGridLinesWithRadius(xGridLines,yGridLines,Radius )
horzSample=2*Radius/xGridLines;
vertSample=2*Radius/yGridLines;
for i = 1 : xGridLines-1 % for Horizontal lines
y=(-Radius)+(horzSample*i);
xmax=sqrt(Radius^2-(y)^2);
xmin=-xmax;
line ([ xmin, xmax ],[ y, y ],'Color',[0 0 0]);
end
for i = 1 : yGridLines-1 % for Vertical lines
x=(-Radius)+(vertSample*i);
ymax=sqrt(Radius^2-(x)^2);
ymin=-ymax;
line ([ x, x ],[ ymin, ymax ],'Color',[0 0 0]);
end
end

Community Treasure Hunt

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

Start Hunting!

Translated by