How can I plot multiple squares?

조회 수: 6 (최근 30일)
Christyn Phillippi
Christyn Phillippi 2014년 3월 27일
편집: Joseph Cheng 2014년 3월 28일
I need plot, basically what is shown above, and for the life of me I cannot figure out what to do this with. I have a circle of radius 2, and I am creating a mesh of the interior, by using squares. I check each corner of the square to see if it is contained or not, and if I need to make it smaller I do and continue from there.
My problem is, what functions could I use for this? I need to (at the end) display something similar to this:
Although, I need to convert all of the squares into triangles, and that is a whole other issue.
How would I go about storing the coordinates and graphing them? I'm extremely new to MATLAB, but I have spent about 4 hours looking for something to work, and I honestly am at a loss.
  댓글 수: 3
Christyn Phillippi
Christyn Phillippi 2014년 3월 27일
So the circle is centered at (0,0) with radius 2. I'm creating a square that encloses the circle with points (-2, -2), (-2, 2), (2, 2) and (2, -2). Basically if the square meets certain criteria (if 1-3, but not 4) of the corners are in the circle, I divide it into 4 equal parts. And then continue from there.
I think I want to use a tree, storing the location at each node, and then at the end I can plot all of the leaf nodes... but still not 100% how I would actually plot them..
Joseph Cheng
Joseph Cheng 2014년 3월 27일
I think i see, Before i was thinking you started with a base square unit that just fit within the circle. Then pack the next largest square you can and go smaller and smaller. Will get back with an method if i come up with one.

댓글을 달려면 로그인하십시오.

채택된 답변

Joseph Cheng
Joseph Cheng 2014년 3월 27일
편집: Joseph Cheng 2014년 3월 27일
something like this? I won't supply this code but you'll have to define an X array and Y array containing the points of the first square. Only need to do 1/4 of it as you can mirror the points in the slice across the axes. then you perform your check for points. If there is a point that (x^2+y^2)^.5>2 then you need insert 4 more squares to your points based on the current square and get rid of the current too big square. then keep looping till you reach some minimum square area.
No need for any fancy tree a simple array for X values for four corner and same for Y will do just fine.
To plot a circle you can use
rectangle('position',[0-R,0-R,R*2,R*2],...
'curvature',[1,1],'linestyle','-','edgecolor','k');
then use hold on, and plot
plot([X(iter,:) X(iter,1)],[Y(iter,:) Y(iter,1)],'r');
Note the extra X and Y in my plot. Only did that to close off my square during the plot.
  댓글 수: 2
Christyn Phillippi
Christyn Phillippi 2014년 3월 28일
This is basically exactly what I need to do.
Hard part for me now is trying to learn exactly how to do this in MATLAB xD the syntax is very new to me.
Thank you!
Joseph Cheng
Joseph Cheng 2014년 3월 28일
편집: Joseph Cheng 2014년 3월 28일
One suggestion that got me started to do this would be draw on a piece of paper a 1/4 circle (like the upper right portion of a circle (0 to 90 degrees)) then draw the 2nd square (side length 1). divide the square into 4 parts. Figure out how the corners of the each of the 4 smaller squares can be defined by the 4 corners of the larger square.
this type of relationship will be used over and over again.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by