View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  /*
19   * This is not the original file distributed by the Apache Software Foundation
20   * It has been modified by the Hipparchus project
21   */
22  package org.hipparchus.geometry.spherical.twod;
23  
24  import org.hipparchus.geometry.euclidean.threed.Rotation;
25  import org.hipparchus.geometry.euclidean.threed.Vector3D;
26  import org.hipparchus.geometry.partitioning.RegionFactory;
27  import org.hipparchus.geometry.partitioning.Side;
28  import org.hipparchus.geometry.partitioning.SubHyperplane.SplitSubHyperplane;
29  import org.hipparchus.geometry.spherical.oned.ArcsSet;
30  import org.hipparchus.geometry.spherical.oned.Sphere1D;
31  import org.hipparchus.util.MathUtils;
32  import org.junit.Assert;
33  import org.junit.Test;
34  
35  public class SubCircleTest {
36  
37      @Test
38      public void testFullCircle() {
39          Circle circle = new Circle(Vector3D.PLUS_K, 1.0e-10);
40          SubCircle set = circle.wholeHyperplane();
41          Assert.assertEquals(MathUtils.TWO_PI, set.getSize(), 1.0e-10);
42          Assert.assertTrue(circle == set.getHyperplane());
43          Assert.assertTrue(circle != set.copySelf().getHyperplane());
44      }
45  
46      @Test
47      public void testSide() {
48  
49          Circle xzPlane = new Circle(Vector3D.PLUS_J, 1.0e-10);
50  
51          SubCircle sc1 = create(Vector3D.PLUS_K, Vector3D.PLUS_I, Vector3D.PLUS_J, 1.0e-10, 1.0, 3.0, 5.0, 6.0);
52          Assert.assertEquals(Side.BOTH, sc1.split(xzPlane).getSide());
53  
54          SubCircle sc2 = create(Vector3D.PLUS_K, Vector3D.PLUS_I, Vector3D.PLUS_J, 1.0e-10, 1.0, 3.0);
55          Assert.assertEquals(Side.MINUS, sc2.split(xzPlane).getSide());
56  
57          SubCircle sc3 = create(Vector3D.PLUS_K, Vector3D.PLUS_I, Vector3D.PLUS_J, 1.0e-10, 5.0, 6.0);
58          Assert.assertEquals(Side.PLUS, sc3.split(xzPlane).getSide());
59  
60          SubCircle sc4 = create(Vector3D.PLUS_J, Vector3D.PLUS_K, Vector3D.PLUS_I, 1.0e-10, 5.0, 6.0);
61          Assert.assertEquals(Side.HYPER, sc4.split(xzPlane).getSide());
62  
63          SubCircle sc5 = create(Vector3D.MINUS_J, Vector3D.PLUS_I, Vector3D.PLUS_K, 1.0e-10, 5.0, 6.0);
64          Assert.assertEquals(Side.HYPER, sc5.split(xzPlane).getSide());
65  
66      }
67  
68      @Test
69      public void testSPlit() {
70  
71          Circle xzPlane = new Circle(Vector3D.PLUS_J, 1.0e-10);
72  
73          SubCircle sc1 = create(Vector3D.PLUS_K, Vector3D.PLUS_I, Vector3D.PLUS_J, 1.0e-10, 1.0, 3.0, 5.0, 6.0);
74          SplitSubHyperplane<Sphere2D> split1 = sc1.split(xzPlane);
75          ArcsSet plus1  = (ArcsSet) ((SubCircle) split1.getPlus()).getRemainingRegion();
76          ArcsSet minus1 = (ArcsSet) ((SubCircle) split1.getMinus()).getRemainingRegion();
77          Assert.assertEquals(1, plus1.asList().size());
78          Assert.assertEquals(5.0, plus1.asList().get(0).getInf(), 1.0e-10);
79          Assert.assertEquals(6.0, plus1.asList().get(0).getSup(), 1.0e-10);
80          Assert.assertEquals(1, minus1.asList().size());
81          Assert.assertEquals(1.0, minus1.asList().get(0).getInf(), 1.0e-10);
82          Assert.assertEquals(3.0, minus1.asList().get(0).getSup(), 1.0e-10);
83  
84          SubCircle sc2 = create(Vector3D.PLUS_K, Vector3D.PLUS_I, Vector3D.PLUS_J, 1.0e-10, 1.0, 3.0);
85          SplitSubHyperplane<Sphere2D> split2 = sc2.split(xzPlane);
86          Assert.assertNull(split2.getPlus());
87          ArcsSet minus2 = (ArcsSet) ((SubCircle) split2.getMinus()).getRemainingRegion();
88          Assert.assertEquals(1, minus2.asList().size());
89          Assert.assertEquals(1.0, minus2.asList().get(0).getInf(), 1.0e-10);
90          Assert.assertEquals(3.0, minus2.asList().get(0).getSup(), 1.0e-10);
91  
92          SubCircle sc3 = create(Vector3D.PLUS_K, Vector3D.PLUS_I, Vector3D.PLUS_J, 1.0e-10, 5.0, 6.0);
93          SplitSubHyperplane<Sphere2D> split3 = sc3.split(xzPlane);
94          ArcsSet plus3  = (ArcsSet) ((SubCircle) split3.getPlus()).getRemainingRegion();
95          Assert.assertEquals(1, plus3.asList().size());
96          Assert.assertEquals(5.0, plus3.asList().get(0).getInf(), 1.0e-10);
97          Assert.assertEquals(6.0, plus3.asList().get(0).getSup(), 1.0e-10);
98          Assert.assertNull(split3.getMinus());
99  
100         SubCircle sc4 = create(Vector3D.PLUS_J, Vector3D.PLUS_K, Vector3D.PLUS_I, 1.0e-10, 5.0, 6.0);
101         SplitSubHyperplane<Sphere2D> split4 = sc4.split(xzPlane);
102         Assert.assertEquals(Side.HYPER, sc4.split(xzPlane).getSide());
103         Assert.assertNull(split4.getPlus());
104         Assert.assertNull(split4.getMinus());
105 
106         SubCircle sc5 = create(Vector3D.MINUS_J, Vector3D.PLUS_I, Vector3D.PLUS_K, 1.0e-10, 5.0, 6.0);
107         SplitSubHyperplane<Sphere2D> split5 = sc5.split(xzPlane);
108         Assert.assertEquals(Side.HYPER, sc5.split(xzPlane).getSide());
109         Assert.assertNull(split5.getPlus());
110         Assert.assertNull(split5.getMinus());
111 
112     }
113 
114     @Test
115     public void testSideSplitConsistency() {
116 
117         double tolerance = 1.0e-6;
118         Circle hyperplane = new Circle(new Vector3D(9.738804529764676E-5, -0.6772824575010357, -0.7357230887208355),
119                                        tolerance);
120         SubCircle sub = new SubCircle(new Circle(new Vector3D(2.1793884139073498E-4, 0.9790647032675541, -0.20354915700704285),
121                                                  tolerance),
122                                       new ArcsSet(4.7121441684170700, 4.7125386635004760, tolerance));
123         SplitSubHyperplane<Sphere2D> split = sub.split(hyperplane);
124         Assert.assertNotNull(split.getMinus());
125         Assert.assertNull(split.getPlus());
126         Assert.assertEquals(Side.MINUS, sub.split(hyperplane).getSide());
127 
128     }
129 
130     private SubCircle create(Vector3D pole, Vector3D x, Vector3D y,
131                              double tolerance, double ... limits) {
132         RegionFactory<Sphere1D> factory = new RegionFactory<Sphere1D>();
133         Circle circle = new Circle(pole, tolerance);
134         Circle phased =
135                 (Circle) Circle.getTransform(new Rotation(circle.getXAxis(), circle.getYAxis(), x, y)).apply(circle);
136         ArcsSet set = (ArcsSet) factory.getComplement(new ArcsSet(tolerance));
137         for (int i = 0; i < limits.length; i += 2) {
138             set = (ArcsSet) factory.union(set, new ArcsSet(limits[i], limits[i + 1], tolerance));
139         }
140         return new SubCircle(phased, set);
141     }
142 
143 }