Class SimpleTriangle3D

All Implemented Interfaces:
HyperplaneConvexSubset<Vector3D>, HyperplaneSubset<Vector3D>, Splittable<Vector3D,HyperplaneSubset<Vector3D>>, Sized, ConvexPolygon3D, PlaneConvexSubset, PlaneSubset, Triangle3D

final class SimpleTriangle3D extends AbstractConvexPolygon3D implements Triangle3D
Simple implementation of Triangle3D.

Instances of this class are guaranteed to be immutable.

  • Field Details

    • p1

      private final Vector3D p1
      First point in the triangle.
    • p2

      private final Vector3D p2
      Second point in the triangle.
    • p3

      private final Vector3D p3
      Third point in the triangle.
  • Constructor Details

    • SimpleTriangle3D

      SimpleTriangle3D(Plane plane, Vector3D p1, Vector3D p2, Vector3D p3)
      Construct a new instance from a plane and 3 points. Callers are responsible for ensuring that the points lie on the plane and define a triangle. No validation is performed.
      Parameters:
      plane - the plane containing the triangle
      p1 - first point in the triangle
      p2 - second point in the triangle
      p3 - third point in the triangle
  • Method Details

    • getPoint1

      public Vector3D getPoint1()
      The first point in the triangle.
      Specified by:
      getPoint1 in interface Triangle3D
      Returns:
      the first point in the triangle
    • getPoint2

      public Vector3D getPoint2()
      The second point in the triangle.
      Specified by:
      getPoint2 in interface Triangle3D
      Returns:
      the second point in the triangle
    • getPoint3

      public Vector3D getPoint3()
      The third point in the triangle.
      Specified by:
      getPoint3 in interface Triangle3D
      Returns:
      the third point in the triangle
    • getVertices

      public List<Vector3D> getVertices()
      Get the vertices for the convex subset in a counter-clockwise order as viewed looking down the plane normal. Each vertex in the returned list is unique. If the boundary of the subset is closed, the start vertex is not repeated at the end of the list.

      It is important to note that, in general, the list of vertices returned by this method is not sufficient to completely characterize the subset. For example, a simple triangle has 3 vertices, but an infinite area constructed from two parallel lines and two lines that intersect between them will also have 3 vertices. It is also possible for non-empty subsets to contain no vertices at all. For example, a subset with no boundaries (representing the full plane), a subset with a single boundary (ie, a half-plane), or a subset with two parallel boundaries will not contain any vertices.

      Specified by:
      getVertices in interface PlaneConvexSubset
      Returns:
      the list of vertices for the plane convex subset in a counter-clockwise order as viewed looking down the plane normal
    • getSize

      public double getSize()
      Get the size of the instance.
      Specified by:
      getSize in interface Sized
      Overrides:
      getSize in class AbstractConvexPolygon3D
      Returns:
      the size of the instance
    • getCentroid

      public Vector3D getCentroid()
      Get the centroid, or geometric center, of the hyperplane subset or null if no centroid exists or one exists but is not unique. A centroid will not exist for empty or infinite subsets.

      The centroid of a geometric object is defined as the mean position of all points in the object, including interior points, vertices, and other points lying on the boundary. If a physical object has a uniform density, then its center of mass is the same as its geometric centroid.

      Specified by:
      getCentroid in interface HyperplaneSubset<Vector3D>
      Overrides:
      getCentroid in class AbstractConvexPolygon3D
      Returns:
      the centroid of the hyperplane subset or null if no unique centroid exists
      See Also:
    • reverse

      public SimpleTriangle3D reverse()
      Reverse the orientation of the hyperplane for this instance, returning the result as a new instance. The returned subset contains the same points but has a reversed orientation.
      Specified by:
      reverse in interface ConvexPolygon3D
      Specified by:
      reverse in interface HyperplaneConvexSubset<Vector3D>
      Specified by:
      reverse in interface PlaneConvexSubset
      Specified by:
      reverse in interface Triangle3D
      Returns:
      a hyperplane convex subset representing the same region but with the opposite orientation.
    • transform

      public SimpleTriangle3D transform(Transform<Vector3D> transform)
      Return a new hyperplane subset resulting from the application of the given transform. The current instance is not modified.
      Specified by:
      transform in interface ConvexPolygon3D
      Specified by:
      transform in interface HyperplaneConvexSubset<Vector3D>
      Specified by:
      transform in interface HyperplaneSubset<Vector3D>
      Specified by:
      transform in interface PlaneConvexSubset
      Specified by:
      transform in interface Triangle3D
      Parameters:
      transform - the transform instance to apply
      Returns:
      new transformed hyperplane subset