9 import fields2cover
as f2c
11 print(
"####### Tutorial 2.1.1 Remaining Area ######");
13 total_field = f2c.Cells(f2c.Cell(f2c.LinearRing(f2c.VectorPoint([
14 f2c.Point(-2,-2), f2c.Point(6,-2), f2c.Point(6,6),
15 f2c.Point(-2,6), f2c.Point(-2,-2)]))));
16 field = f2c.Cells(f2c.Cell(f2c.LinearRing(f2c.VectorPoint([
17 f2c.Point(0,0), f2c.Point(4,0), f2c.Point(4,4),
18 f2c.Point(0,4), f2c.Point(0,0)]))));
20 rem_area = f2c.OBJ_RemArea();
21 print(
"The remaining area is ",
22 rem_area.computeCost(total_field, field),
", and with sign is ",
23 rem_area.computeCostWithMinimizingSign(total_field, field));
28 print(
"\n\n####### Tutorial 2.2.1 Field Coverage ######");
30 swath1 = f2c.Swath(f2c.LineString(f2c.VectorPoint([
31 f2c.Point(0.0, 1.0), f2c.Point(4.0, 1.0)])), width);
32 swath2 = f2c.Swath(f2c.LineString(f2c.VectorPoint([
33 f2c.Point(0.0, 3.0), f2c.Point(4.0, 3.0)])), width);
34 swath3 = f2c.Swath(f2c.LineString(f2c.VectorPoint([
35 f2c.Point(0.0, 2.0), f2c.Point(4.0, 2.0)])), width);
37 swaths1 = f2c.Swaths();
38 swaths1.push_back(swath1);
39 swaths3 = f2c.Swaths();
40 [swaths3.push_back(s)
for s
in [swath1, swath2, swath3]];
42 field_cov = f2c.OBJ_FieldCoverage();
43 print(
"The field coverage with swath1 is ",
44 field_cov.computeCost(field, swaths1),
" and with all of the swaths ",
45 field_cov.computeCost(field, swaths3));
46 print(
"The field coverage with sign for all of the swaths is ",
47 field_cov.computeCostWithMinimizingSign(field, swaths3));
49 print(
"\n####### Tutorial 2.2.2 Number of swaths ######");
50 n_swaths = f2c.OBJ_NSwath();
51 print(
"The number of swaths with swath1 is ",
52 n_swaths.computeCost(swaths1),
" and with all of the swaths ",
53 n_swaths.computeCost(field, swaths3));
55 print(
"\n####### Tutorial 2.2.3 Overlap ######");
56 overlaps = f2c.OBJ_Overlaps();
57 print(
"The field overlapping with swath1 is ",
58 overlaps.computeCost(field, swaths1),
" and with all of the swaths ",
59 overlaps.computeCost(field, swaths3));
61 print(
"\n####### Tutorial 2.2.4 Swath length ######");
62 swath_length = f2c.OBJ_SwathLength();
63 print(
"The swath length with swath1 is ",
64 swath_length.computeCost(field, swaths1),
" and with all of the swaths ",
65 swath_length.computeCost(field, swaths3));
68 print(
"\n\n####### Tutorial 2.3.1 Distance with turns ######");
69 line1 = f2c.LineString(f2c.VectorPoint([f2c.Point(0.0, 0.0), f2c.Point(0.0, 1.0)]));
70 swath1 = f2c.Swath(line1);
71 line2 = f2c.LineString(f2c.VectorPoint([f2c.Point(1.0, 1.0), f2c.Point(1.0, 0.0)]));
72 swath2 = f2c.Swath(line2);
73 swaths_path = f2c.Swaths();
74 swaths_path.push_back(swath1);
75 swaths_path.push_back(swath2);
76 robot = f2c.Robot(2.0, 3.0);
77 robot.setMinTurningRadius(0.5);
78 complete_length = f2c.OBJ_CompleteTurnPathObj_Dubins(robot);
79 print(
"The complete length is: ", complete_length.computeCost(swaths_path),
80 " =~= ", 1 + 1 + math.pi/2.0);
82 print(
"\n####### Tutorial 2.3.2 Direct distance without turns ######");
83 direct_dist = f2c.OBJ_DirectDistPathObj();
84 print(
"The aproximated length is: ", direct_dist.computeCost(swaths_path));
87 print(
"\n\n####### Tutorial 2.4.1 Path length ######");
89 path.appendSwath(swaths_path.at(0), 1);
90 path.appendSwath(swaths_path.at(1), 1);
92 path_length = f2c.OBJ_PathLength();
93 print(
"The path length is: ", path_length.computeCost(path));