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