# Random rectangle

**URL:** <https://discourse.processing.org/t/random-rectangle/16000>\
**Category:** Coding Questions\
**Created:** [November 30, 2019, 10:52pm UTC](https://discourse.processing.org/t/random-rectangle/16000 "2019-11-30T22:52:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![elcougario](https://avatars.discourse-cdn.com/v4/letter/e/d26b3c/32.png) [@elcougario](https://discourse.processing.org/u/elcougario)\
**Post date:** [November 30, 2019, 10:52pm UTC](https://discourse.processing.org/t/random-rectangle/16000/1 "2019-11-30T22:52:51Z")

</div>

Hey guys. Im trying to make rectangles be inside a quad shape I’ve created. How do we do this. I would want them not to touch as well (like not overlap). I’ve though of using a Boolean or and array but I cant figure it out. Is there a way?

```auto
void setup(){
  //Space size
  size(800,800);
  background(255);
    stroke(0);
   strokeWeight(3);
  //no loop for draw
  //noLoop();
  
  //QUAD shape boundary
  
    quad(400,50,650,500,400,700,150,500);
  
}
 // Shape to build around/inside
 
 void draw(){

//for(int i=0; i<numLOOPS; i++){
  
 stroke(0);
 // A.position
 
 int x=round(random(0,width));
 int y=round(random(0,width));
 
 // B.random H/L size
 float rectH= random(20,150);
 float rectL= random(20,150);
 
 //C.Random Angle
 float rectAgl = random(PI/3);
 
   rotate(rectAgl);
   rect(x,y,rectH,rectL);
   

 

}

```

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 30, 2019, 11:33pm UTC](https://discourse.processing.org/t/random-rectangle/16000/2 "2019-11-30T23:33:49Z")

</div>

Here you can see how to do a boundary check with Polygons. If all 4 points of the rectangle lie either inside or outside, then it‘s not overlapping.

> **[How to check if a given point lies inside or outside a polygon? - GeeksforGeeks](https://www.geeksforgeeks.org/how-to-check-if-a-given-point-lies-inside-a-polygon/)**
>
> Given a polygon and a point ‘p’, find if ‘p’ lies inside the polygon or not. The points lying on the border are considered inside.… Read More »
