1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.geometry.examples.tutorials.bsp;
18
19 import java.io.File;
20 import java.util.Arrays;
21
22 import org.apache.commons.geometry.core.partitioning.bsp.RegionCutRule;
23 import org.apache.commons.geometry.core.precision.DoublePrecisionContext;
24 import org.apache.commons.geometry.core.precision.EpsilonDoublePrecisionContext;
25 import org.apache.commons.geometry.euclidean.twod.Bounds2D;
26 import org.apache.commons.geometry.euclidean.twod.Lines;
27 import org.apache.commons.geometry.euclidean.twod.RegionBSPTree2D;
28 import org.apache.commons.geometry.euclidean.twod.Vector2D;
29 import org.apache.commons.geometry.euclidean.twod.path.LinePath;
30
31
32
33
34 public final class HexagonStructuralCut {
35
36
37 private HexagonStructuralCut() {}
38
39
40
41
42
43 public static void main(String[] args) {
44 File outputFolder = new File(args.length > 0 ? args[0] : ".");
45 BSPTreeSVGWriter svgWriter = new BSPTreeSVGWriter(Bounds2D.from(Vector2D.of(-8, -8), Vector2D.of(8, 8)));
46
47 DoublePrecisionContext precision = new EpsilonDoublePrecisionContext(1e-6);
48
49 RegionBSPTree2D tree = RegionBSPTree2D.empty();
50
51 tree.insert(Lines.fromPointAndDirection(Vector2D.ZERO, Vector2D.Unit.PLUS_X, precision).span(),
52 RegionCutRule.INHERIT);
53
54 svgWriter.write(tree, new File(outputFolder, "hex-struct-0.svg"));
55
56 LinePath path = LinePath.fromVertexLoop(Arrays.asList(
57 Vector2D.of(-4, 0),
58 Vector2D.of(-2, -3),
59 Vector2D.of(2, -3),
60 Vector2D.of(4, 0),
61 Vector2D.of(2, 3),
62 Vector2D.of(-2, 3)
63 ), precision);
64 tree.insert(path);
65
66 svgWriter.write(tree, new File(outputFolder, "hex-struct-1.svg"));
67 }
68 }