SubCircle.java

  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.  * This is not the original file distributed by the Apache Software Foundation
  19.  * It has been modified by the Hipparchus project
  20.  */
  21. package org.hipparchus.geometry.spherical.twod;

  22. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  23. import org.hipparchus.geometry.partitioning.AbstractSubHyperplane;
  24. import org.hipparchus.geometry.partitioning.Region;
  25. import org.hipparchus.geometry.spherical.oned.Arc;
  26. import org.hipparchus.geometry.spherical.oned.ArcsSet;
  27. import org.hipparchus.geometry.spherical.oned.LimitAngle;
  28. import org.hipparchus.geometry.spherical.oned.S1Point;
  29. import org.hipparchus.geometry.spherical.oned.Sphere1D;
  30. import org.hipparchus.geometry.spherical.oned.SubLimitAngle;
  31. import org.hipparchus.util.FastMath;

  32. /** This class represents a sub-hyperplane for {@link Circle}.
  33.  */
  34. public class SubCircle
  35.     extends AbstractSubHyperplane<Sphere2D, S2Point, Circle, SubCircle, Sphere1D, S1Point, LimitAngle, SubLimitAngle> {

  36.     /** Simple constructor.
  37.      * @param hyperplane underlying hyperplane
  38.      * @param remainingRegion remaining region of the hyperplane
  39.      */
  40.     public SubCircle(final Circle hyperplane,
  41.                      final Region<Sphere1D, S1Point, LimitAngle, SubLimitAngle> remainingRegion) {
  42.         super(hyperplane, remainingRegion);
  43.     }

  44.     /** {@inheritDoc} */
  45.     @Override
  46.     protected SubCircle buildNew(final Circle hyperplane, final Region<Sphere1D, S1Point, LimitAngle, SubLimitAngle> remainingRegion) {
  47.         return new SubCircle(hyperplane, remainingRegion);
  48.     }

  49.     /** {@inheritDoc} */
  50.     @Override
  51.     public S2Point getInteriorPoint() {
  52.         return isEmpty() ? null : getHyperplane().toSpace(getRemainingRegion().getInteriorPoint());
  53.     }

  54.     /** {@inheritDoc} */
  55.     @Override
  56.     public SplitSubHyperplane<Sphere2D, S2Point, Circle, SubCircle> split(final Circle hyperplane) {

  57.         final double angle = Vector3D.angle(getHyperplane().getPole(), hyperplane.getPole());

  58.         if (angle < getHyperplane().getTolerance() || angle > FastMath.PI - getHyperplane().getTolerance()) {
  59.             // the two circles are aligned or opposite
  60.             return new SplitSubHyperplane<>(null, null);
  61.         } else {
  62.             // the two circles intersect each other
  63.             final Arc    arc          = getHyperplane().getInsideArc(hyperplane);
  64.             final ArcsSet.Split split = ((ArcsSet) getRemainingRegion()).split(arc);
  65.             final ArcsSet plus        = split.getPlus();
  66.             final ArcsSet minus       = split.getMinus();
  67.             return new SplitSubHyperplane<>(plus  == null ? null : new SubCircle(getHyperplane().copySelf(), plus),
  68.                                             minus == null ? null : new SubCircle(getHyperplane().copySelf(), minus));
  69.         }

  70.     }

  71. }