Split Rectangle
Split rectangle by specifying number of divisions, minimum and maximum area
splitRect.dyn
15KB
Text
1
rctg1 = Rectangle.ByWidthLength(10,10);
2
//Number of Lines
3
cnt;
4
//Minimum Area of Polygon
5
min;
6
//Maximum Area of Polygon
7
max;
8
//Max attempts
9
atm = 500;
10
11
[Imperative]
12
{
13
surf1 = rctg1.Patch();
14
lins1 = [];
15
c = 0;
16
t = [];
17
sed = 0;
18
test1 = true;
19
sed = sed + 1;
20
while(test1 && sed<atm)
21
{
22
lins1 = lins(rctg1,cnt,sed);
23
surf1 = spl(rctg1,lins1);
24
for (s in surf1)
25
{
26
if (s.Area<min || s.Area>max)
27
{
28
t[c] = true;
29
c = c + 1;
30
}
31
else
32
{
33
t[c] = false;
34
c = c + 1;
35
}
36
}
37
sed = sed + 1;
38
test1 = List.Contains(t,true);
39
}
40
return surf1;
41
};
42
43
//Functions
44
def lins(rec,cnt,sed)
45
{
46
edgs1 = rec.Explode();
47
parm1 = List.TakeItems(List.Shuffle(0.1..1..#(Math.Random(sed)*50)),cnt/2);
48
parm2 = List.TakeItems(List.Shuffle(0.1..1..#(Math.Random(sed+1)*50)),cnt/2);
49
parm3 = List.TakeItems(List.Shuffle(0.1..1..#(Math.Random(sed+2)*50)),cnt/2);
50
parm4 = List.TakeItems(List.Shuffle(0.1..1..#(Math.Random(sed+3)*50)),cnt/2);
51
pnts1 = edgs1[0].PointAtParameter(parm1);
52
pnts2 = edgs1[1].PointAtParameter(parm2);
53
pnts3 = edgs1[2].PointAtParameter(parm3);
54
pnts4 = edgs1[3].PointAtParameter(parm4);
55
lins1 = List.TakeItems(List.Flatten(Line.ByStartPointEndPoint([pnts1,pnts2],[pnts3,pnts4]),-1),cnt);
56
return lins1;
57
};
58
59
60
def spl(rect,lines:var[]..[])
61
{
62
//Cutting Tool
63
tool = Solid.ByUnion(List.Flatten([rect,lines],-1).Extrude(Vector.ZAxis()).Thicken(0.4));
64
65
//Divisions
66
divisions = List.Clean(PolyCurve.ByJoinedCurves(rect.Patch().Split(tool).PerimeterCurves()),false).Offset(0.2,false).Patch();
67
return divisions;
68
};
Copied!
Last modified 1yr ago
Copy link