# Split Rectangle

![](/files/-LfzzPxMrFXc3zIs2Y7j)

{% file src="/files/-LfzzUVYPtnbW0eY3ZGq" %}

```d
rctg1 = Rectangle.ByWidthLength(10,10);
//Number of Lines
cnt;
//Minimum Area of Polygon
min;
//Maximum Area of Polygon
max;
//Max attempts
atm = 500;

[Imperative]
{
	surf1 = rctg1.Patch();
	lins1 = [];
	c = 0;
	t = [];
	sed = 0;
	test1 = true;
	sed = sed + 1;
	while(test1 && sed<atm)
	{
		lins1 = lins(rctg1,cnt,sed);
		surf1 = spl(rctg1,lins1);
		for (s in surf1)
		{
			if (s.Area<min || s.Area>max)
			{
				t[c] = true;
				c = c + 1;
			}
			else
			{
				t[c] = false;
				c = c + 1;
			}
		}
		sed = sed + 1;
		test1 = List.Contains(t,true);
	}
	return surf1;
};

//Functions
def lins(rec,cnt,sed)
{
	edgs1 = rec.Explode();
	parm1 = List.TakeItems(List.Shuffle(0.1..1..#(Math.Random(sed)*50)),cnt/2);
	parm2 = List.TakeItems(List.Shuffle(0.1..1..#(Math.Random(sed+1)*50)),cnt/2);
	parm3 = List.TakeItems(List.Shuffle(0.1..1..#(Math.Random(sed+2)*50)),cnt/2);
	parm4 = List.TakeItems(List.Shuffle(0.1..1..#(Math.Random(sed+3)*50)),cnt/2);
	pnts1 = edgs1[0].PointAtParameter(parm1);
	pnts2 = edgs1[1].PointAtParameter(parm2);
	pnts3 = edgs1[2].PointAtParameter(parm3);
	pnts4 = edgs1[3].PointAtParameter(parm4);
	lins1 = List.TakeItems(List.Flatten(Line.ByStartPointEndPoint([pnts1,pnts2],[pnts3,pnts4]),-1),cnt);
	return lins1;
};


def spl(rect,lines:var[]..[])
{
//Cutting Tool
tool = Solid.ByUnion(List.Flatten([rect,lines],-1).Extrude(Vector.ZAxis()).Thicken(0.4));

//Divisions
divisions = List.Clean(PolyCurve.ByJoinedCurves(rect.Patch().Split(tool).PerimeterCurves()),false).Offset(0.2,false).Patch();
return divisions;
};
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitbook.testingwaters.in/geometry-1/split-rectangle.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
