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    *      http://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  package org.apache.commons.geometry.euclidean.threed.line;
    18
    19  import org.apache.commons.geometry.core.Transform;
    20  import org.apache.commons.geometry.euclidean.oned.Interval;
    21  import org.apache.commons.geometry.euclidean.threed.Vector3D;
    22
    23  /** Class representing a convex subset of a line in 3D Euclidean space. Instances
    24   * need not be finite, in which case the start or end point (or both) will be null.
    25   * @see Lines3D
    26   */
    27  public abstract class LineConvexSubset3D extends LineSubset3D {
    28
    29      /** Construct a new instance for the given line.
    30       * @param line line containing this convex subset
    31       */
    32      LineConvexSubset3D(final Line3D line) {
    33          super(line);
    34      }
    35
    36      /** Get the start point for the line subset.
    37       * @return the start point for the line subset, or null if no start point exists
    38       */
    39      public abstract Vector3D getStartPoint();
    40
    41      /** Get the 1D start location of the line subset or {@link Double#NEGATIVE_INFINITY} if
    42       * no start location exists.
    43       * @return the 1D start location of the line subset or {@link Double#NEGATIVE_INFINITY} if
    44       *      no start location exists.
    45       */
    46      public abstract double getSubspaceStart();
    47
    48      /** Get the end point for the line subset.
    49       * @return the end point for the line subset, or null if no end point exists.
    50       */
    51      public abstract Vector3D getEndPoint();
    52
    53      /** Get the 1D end location of the line subset or {@link Double#POSITIVE_INFINITY} if
    54       * no end location exists.
    55       * @return the 1D end location of the line subset or {@link Double#POSITIVE_INFINITY} if
    56       *      no end location exists
    57       */
    58      public abstract double getSubspaceEnd();
    59
    60      /** {@inheritDoc} */
    61      @Override
    62      public Interval getSubspaceRegion() {
    63          final double start = getSubspaceStart();
    64          final double end = getSubspaceEnd();
    65
    66          return Interval.of(start, end, getLine().getPrecision());
    67      }
    68
    69      /** Get the 1D interval for the line subset. This method is an alias for {@link #getSubspaceRegion()}.
    70       * @return the 1D interval for the line subset.
    71       */
    72      public Interval getInterval() {
    73          return getSubspaceRegion();
    74      }
    75
    76      /** Return true if the given point lies in the line subset.
    77       * @param pt point to check
    78       * @return true if the point lies in the line subset
    79       */
    80      public boolean contains(final Vector3D pt) {
    81          final Line3D line = getLine();
    82          return line.contains(pt) && containsAbscissa(line.abscissa(pt));
    83      }
    84
    85      /** Transform this instance.
    86       * @param transform the transform to apply
    87       * @return a new, transformed instance
    88       */
    89      public abstract LineConvexSubset3D transform(Transform<Vector3D> transform);
    90
    91      /** Return true if the given abscissa value is contained in the line subset (ie, in the subspace region
    92       * or one of its 1D boundaries).
    93       * @param abscissa abscissa to check
    94       * @return true if {@code abscissa} lies on the inside or boundary of the subspace region
    95       */
    96      abstract boolean containsAbscissa(double abscissa);
    97  }