How can I plot multiple squares?
28 views (last 30 days)
Show older comments
Christyn Phillippi
on 27 Mar 2014
Edited: Joseph Cheng
on 28 Mar 2014
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 Comments
Joseph Cheng
on 27 Mar 2014
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.
Accepted Answer
Joseph Cheng
on 27 Mar 2014
Edited: Joseph Cheng
on 27 Mar 2014
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 Comments
Joseph Cheng
on 28 Mar 2014
Edited: Joseph Cheng
on 28 Mar 2014
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.
More Answers (0)
See Also
Categories
Find more on Surface and Mesh 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!