Straight Lines inside Circles

11 views (last 30 days)
premraj
premraj on 19 Sep 2011
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

Answers (3)

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

Sign in to comment.


premraj
premraj on 20 Sep 2011
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 on 20 Sep 2011
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!