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 java.util.List;
20  
21  /** Interface for objects that support linecast operations in Euclidean 3D space.
22   *
23   * <p>
24   * Linecasting is a process that takes a line or line convex subset and intersects it with
25   * the boundaries of a region. This is similar to
26   * <a href="https://en.wikipedia.org/wiki/Ray_casting">raycasting</a> used
27   * for collision detection with the exception that the intersecting element can be a
28   * line or line convex subset and not just a ray.
29   * </p>
30   */
31  public interface Linecastable3D {
32  
33      /** Intersect the given line against the boundaries in this instance, returning a
34       * list of all intersections in order of increasing distance along the line. An empty
35       * list is returned if no intersections are discovered.
36       * @param line line the line to intersect
37       * @return a list of computed intersections in order of increasing distance
38       *      along the line
39       */
40      default List<LinecastPoint3D> linecast(final Line3D line) {
41          return linecast(line.span());
42      }
43  
44      /** Intersect the given line convex subset against the boundaries in this instance, returning
45       * a list of all intersections in order of increasing distance along the line. An empty list is
46       * returned if no intersections are discovered.
47       * @param subset line subset to intersect
48       * @return a list of computed intersections in order of increasing distance
49       *      along the line
50       */
51      List<LinecastPoint3D> linecast(LineConvexSubset3D subset);
52  
53      /** Intersect the given line against the boundaries in this instance, returning the first
54       * intersection found when traveling in the direction of the line from infinity.
55       * @param line the line to intersect
56       * @return the first intersection found or null if no intersection
57       *      is found
58       */
59      default LinecastPoint3D linecastFirst(final Line3D line) {
60          return linecastFirst(line.span());
61      }
62  
63      /** Intersect the given line convex subset against the boundaries in this instance, returning
64       * the first intersection found when traveling in the direction of the line subset from its
65       * start point.
66       * @param subset line subset to intersect
67       * @return the first intersection found or null if no intersection
68       *      is found
69       */
70      LinecastPoint3D linecastFirst(LineConvexSubset3D subset);
71  }