MATLAB randomly generates multiple rectangles that do not overlap

Source: Internet
Author: User

Build M file DRAW_RECTANGLE.M.

where p generates the number of rectangles

function Draw_rectangle (p) t = 1;x = rand (1) *10;y = rand (1) *10;w = rand (1) *10;h = rand (1) *10;b =[x y w h];rectangle (' Posit    Ion ', B) a{t} =b;flag =1;while flag ==1 x = rand (1) *10;    y = rand (1) *10;    w = rand (1) *10;    h = rand (1) *10;    b =[x y W h];     num = 0;          For j = 1:t if ~rectint (b,a{j}) num = num +1;         End End If num = = t on;         Rectangle (' Position ', b) t = t+1;     A{t} =b;         End If T = = P break endend% t = 1;% flag =1%% when flag ==1% for i =1:p% x = rand (1) *10;% y = rand (1) *10;% w = rand (1) *10;% h = rand (1) *10;% b =[x y w h];%% rectangle (' posit Ion ', B)% a{i} =b;% end% num = 0;% for i = 1: (p-1)% for j = (i+1):p% if Rectint (a{     I},A{J})% break% else% num = num +1;% end% end% end% % if num = = (p-1) *p/2% for i = 1:p% Rectangle (' Position ', a{i})% end% flag = 0;% end% End             

  

MATLAB randomly generates multiple rectangles that do not overlap

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.