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      /** Return true if the line subset is infinite.
37       * @return true if the line subset is infinite.
38       */
39      @Override
40      public abstract boolean isInfinite();
41  
42      /** Return true if the line subset is finite.
43       * @return true if the line subset is finite.
44       */
45      @Override
46      public abstract boolean isFinite();
47  
48      /** Get the start point for the line subset.
49       * @return the start point for the line subset, or null if no start point exists
50       */
51      public abstract Vector3D getStartPoint();
52  
53      /** Get the 1D start location of the line subset or {@link Double#NEGATIVE_INFINITY} if
54       * no start location exists.
55       * @return the 1D start location of the line subset or {@link Double#NEGATIVE_INFINITY} if
56       *      no start location exists.
57       */
58      public abstract double getSubspaceStart();
59  
60      /** Get the end point for the line subset.
61       * @return the end point for the line subset, or null if no end point exists.
62       */
63      public abstract Vector3D getEndPoint();
64  
65      /** Get the 1D end location of the line subset or {@link Double#POSITIVE_INFINITY} if
66       * no end location exists.
67       * @return the 1D end location of the line subset or {@link Double#POSITIVE_INFINITY} if
68       *      no end location exists
69       */
70      public abstract double getSubspaceEnd();
71  
72      /** Get the size (length) of the line subset.
73       * @return the size of the line subset
74       */
75      @Override
76      public abstract double getSize();
77  
78      /** {@inheritDoc} */
79      @Override
80      public Interval getSubspaceRegion() {
81          final double start = getSubspaceStart();
82          final double end = getSubspaceEnd();
83  
84          return Interval.of(start, end, getLine().getPrecision());
85      }
86  
87      /** Get the 1D interval for the line subset. This method is an alias for {@link #getSubspaceRegion()}.
88       * @return the 1D interval for the line subset.
89       */
90      public Interval getInterval() {
91          return getSubspaceRegion();
92      }
93  
94      /** Return true if the given point lies in the line subset.
95       * @param pt point to check
96       * @return true if the point lies in the line subset
97       */
98      public boolean contains(final Vector3D pt) {
99          final Line3D line = getLine();
100         return line.contains(pt) && containsAbscissa(line.abscissa(pt));
101     }
102 
103     /** Transform this instance.
104      * @param transform the transform to apply
105      * @return a new, transformed instance
106      */
107     public abstract LineConvexSubset3D transform(Transform<Vector3D> transform);
108 
109     /** Return true if the given abscissa value is contained in the line subset (ie, in the subspace region
110      * or one of its 1D boundaries).
111      * @param abscissa abscissa to check
112      * @return true if {@code abscissa} lies on the inside or boundary of the subspace region
113      */
114     abstract boolean containsAbscissa(double abscissa);
115 }