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.Vector3D;
25  import org.hipparchus.geometry.partitioning.AbstractSubHyperplane;
26  import org.hipparchus.geometry.partitioning.Region;
27  import org.hipparchus.geometry.spherical.oned.Arc;
28  import org.hipparchus.geometry.spherical.oned.ArcsSet;
29  import org.hipparchus.geometry.spherical.oned.LimitAngle;
30  import org.hipparchus.geometry.spherical.oned.S1Point;
31  import org.hipparchus.geometry.spherical.oned.Sphere1D;
32  import org.hipparchus.geometry.spherical.oned.SubLimitAngle;
33  import org.hipparchus.util.FastMath;
34  
35  /** This class represents a sub-hyperplane for {@link Circle}.
36   */
37  public class SubCircle
38      extends AbstractSubHyperplane<Sphere2D, S2Point, Circle, SubCircle, Sphere1D, S1Point, LimitAngle, SubLimitAngle> {
39  
40      /** Simple constructor.
41       * @param hyperplane underlying hyperplane
42       * @param remainingRegion remaining region of the hyperplane
43       */
44      public SubCircle(final Circle hyperplane,
45                       final Region<Sphere1D, S1Point, LimitAngle, SubLimitAngle> remainingRegion) {
46          super(hyperplane, remainingRegion);
47      }
48  
49      /** {@inheritDoc} */
50      @Override
51      protected SubCircle buildNew(final Circle hyperplane, final Region<Sphere1D, S1Point, LimitAngle, SubLimitAngle> remainingRegion) {
52          return new SubCircle(hyperplane, remainingRegion);
53      }
54  
55      /** {@inheritDoc} */
56      @Override
57      public S2Point getInteriorPoint() {
58          return isEmpty() ? null : getHyperplane().toSpace(getRemainingRegion().getInteriorPoint());
59      }
60  
61      /** {@inheritDoc} */
62      @Override
63      public SplitSubHyperplane<Sphere2D, S2Point, Circle, SubCircle> split(final Circle hyperplane) {
64  
65          final double angle = Vector3D.angle(getHyperplane().getPole(), hyperplane.getPole());
66  
67          if (angle < getHyperplane().getTolerance() || angle > FastMath.PI - getHyperplane().getTolerance()) {
68              // the two circles are aligned or opposite
69              return new SplitSubHyperplane<>(null, null);
70          } else {
71              // the two circles intersect each other
72              final Arc    arc          = getHyperplane().getInsideArc(hyperplane);
73              final ArcsSet.Split split = ((ArcsSet) getRemainingRegion()).split(arc);
74              final ArcsSet plus        = split.getPlus();
75              final ArcsSet minus       = split.getMinus();
76              return new SplitSubHyperplane<>(plus  == null ? null : new SubCircle(getHyperplane().copySelf(), plus),
77                                              minus == null ? null : new SubCircle(getHyperplane().copySelf(), minus));
78          }
79  
80      }
81  
82  }