how to make rectangle in circle?

I want to make rectangles in circle.
I know the radius, rectangle's width and length.
please let me know how to do this
thanks

3 件のコメント

Jan
Jan 2022 年 11 月 19 日
What have you tried so far?
Sierra
Sierra 2022 年 11 月 20 日
I answerd to Matt J's!
could you guys look at that?

サインインしてコメントする。

 採用された回答

Matt J
Matt J 2022 年 11 月 19 日
編集済み: Matt J 2022 年 11 月 19 日

0 投票

[X,Y]=ndgrid(-10:10);
r=arrayfun( @(x,y) nsidedpoly(4,'Center',[x,y],'Radius',1/sqrt(2)) , X(:),Y(:));
c=intersect(nsidedpoly(1000,'Radius',5), scale(r,[1,1.5]));
plot(c,'FaceColor','none')

4 件のコメント

Sierra
Sierra 2022 年 11 月 20 日
Thanks always MattJ
but i have problem using your code with my data.
could you look at this?
the circle's coordinates are [lonc latc]. (I attached the file)
and in geographic coordinates the radius is 5NM
so nm2deg(5) = 0.0833
nm2deg(5) = 0.0833
% every grid's width and length are 0.44 and 0.58
% so I calculated like this
width = 0.44/5;
length = 0.58/5;
nm5 = 0.0833;
width1 = width*nm5;
length1 = length*nm5;
using this, could you give me example code? thanks.
Matt J
Matt J 2022 年 11 月 20 日
編集済み: Matt J 2022 年 11 月 20 日
Maybe this is clearer:
width=1;
length=1.3;
circleRadius=10;
[X,Y]=ndgrid(-circleRadius:width:circleRadius+width);
r=arrayfun( @(x,y) nsidedpoly(4,'Center',[x,y],'Radius',width/sqrt(2)) , X(:),Y(:));
c=intersect(nsidedpoly(1000,'Radius',circleRadius), scale(r,[1,length/width]));
plot(c,'FaceColor','none'); axis equal
Sierra
Sierra 2022 年 11 月 20 日
Thanks again.
but My circle's origin point is not zero. so I added my circle's origin point.
width=0.0073;
length=0.0097;
circleRadius=0.0833;
[X,Y]=ndgrid(-circleRadius:width:circleRadius+width);
X(:) = X(:) + ARP_lon % origin x 126.7975
Y(:) = Y(:) + ARP_lat % origin y 37.5569
r=arrayfun( @(x,y) nsidedpoly(4,'Center',[x,y],'Radius',width/sqrt(2)) , X(:),Y(:));
c=intersect(nsidedpoly(1000,'Radius',circleRadius), scale(r,[1,length/width]));
plot(c,'FaceColor','none'); %axis equal
but it didn't work well.
could you explain more?
Matt J
Matt J 2022 年 11 月 20 日
width=1;
length=1.3;
circleRadius=10;
[X,Y]=ndgrid(-circleRadius:width:circleRadius+width);
r=arrayfun( @(x,y) nsidedpoly(4,'Center',[x,y],'Radius',width/sqrt(2)) , X(:),Y(:));
c=intersect(nsidedpoly(1000,'Radius',circleRadius), scale(r,[1,length/width]));
c=translate(c,ARP_lon,ARP_lat);
plot(c,'FaceColor','none'); axis equal

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2022 年 11 月 19 日

0 投票

See the FAQ:
Then plot it with plot and then for each x and y value you want find the end points of a line segment and use line() or plot() to draw the line from one side of the circle to the other. It's easy but if you really can't figure it out then write back.

3 件のコメント

Sierra
Sierra 2022 年 11 月 20 日
I tried this. but i found that I also have to know the grid's point inside circle.
jsut connecting the first point and end point is doesn't work for me.
But thanks for your answering.
I uploaded new comment for clarification to Matt J's answer.
Image Analyst
Image Analyst 2022 年 11 月 20 日
You do not ned to know the crossing/intersection coordinates of the vertical and horizontal lines inside the circle. All you need to know for the horizontal lines is the y value and the two points on the circle closest to that y value. Similar for the lines in the other direction. But it looks like @Matt J suggested a different approach and you accepted that so I won't proceed with my approach.
Sierra
Sierra 2022 年 11 月 20 日
Thanks for your answer!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

質問済み:

2022 年 11 月 19 日

コメント済み:

2022 年 11 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by