Package org.bzdev.p3d

Class Model3D.Triangle

java.lang.Object
org.bzdev.p3d.Model3D.Triangle
All Implemented Interfaces:
Comparable<Model3D.Triangle>, Model3DOps.Triangle
Enclosing class:
Model3D

public static class Model3D.Triangle extends Object implements Comparable<Model3D.Triangle>, Model3DOps.Triangle
Class representing a triangle embedded in a 3 dimensional space.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Triangle(double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3)
    Constructor.
    Triangle(double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, Color color)
    Constructor specifying a color.
    Triangle(double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, Color color, Object tag)
    Constructor specifying a color and tag.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Compute the area of a triangle.
    int
    Comparison method.
    double
    Get the length parallel to the x axis of a triangle's bounding box.
    double
    Get the length parallel to the y axis of a triangle's bounding box.
    double
    Get the length parallel to the z axis of a triangle's bounding box.
    Get a triangle's color
    double
    Get the maximum value along the x axis for a triangle.
    double
    Get the maximum value along the y axis for a triangle.
    double
    Get the maximum value along the z axis for a triangle.
    double
    Get the minimum value along the x axis for a triangle.
    double
    Get the minimum value along the y axis for a triangle.
    double
    Get the minimum value along the z axis for a triangle.
    double
    Get the X component of the normal vector.
    double
    Get the Y component of the normal vector.
    double
    Get the Z component of the normal vector.
    Get the tag associated with a triangle.
    Get the tag history list for a triangle.
    double
    Get the x coordinate of a triangle's or patch's first vertex.
    double
    Get the x coordinate of a triangle's or patch's second vertex.
    double
    Get the x coordinate of a triangle's or patch's third vertex.
    double
    Get the x coordinate of a patch's fourth vertex.
    double
    Get the y coordinate of a triangle's or patch's first vertex.
    double
    Get the y coordinate of a triangle's or patch's second vertex.
    double
    Get the y coordinate of a triangle's or patch's third vertex.
    double
    Get the y coordinate of a patch's fourth vertex.
    double
    Get the z coordinate of a triangle's or patch's first vertex.
    double
    Get the z coordinate of a triangle's or patch's second vertex.
    double
    Get the z coordinate of a triangle's or patch's third vertex.
    double
    Get the z coordinate of a patch's fourth vertex.
    int
    Return this object's hash code,
    boolean
    Determine if this triangle represents a cubic Bézier patch.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Triangle

      public Triangle(double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3)
      Constructor. The orientation of the triangle is determined by the right-hand rule when going from vertex 1 to vertex 2 to vertex 3.
      Parameters:
      x1 - the x coordinate of vertex 1
      y1 - the y coordinate of vertex 1
      z1 - the z coordinate of vertex 1
      x2 - the x coordinate of vertex 2
      y2 - the y coordinate of vertex 2
      z2 - the z coordinate of vertex 2
      x3 - the x coordinate of vertex 3
      y3 - the y coordinate of vertex 3
      z3 - the z coordinate of vertex 3
      Throws:
      IllegalArgumentException - one of the first 9 arguments had the value Double.NaN
    • Triangle

      public Triangle(double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, Color color)
      Constructor specifying a color. The orientation of the triangle is determined by the right-hand rule when going from vertex 1 to vertex 2 to vertex 3.
      Parameters:
      x1 - the x coordinate of vertex 1
      y1 - the y coordinate of vertex 1
      z1 - the z coordinate of vertex 1
      x2 - the x coordinate of vertex 2
      y2 - the y coordinate of vertex 2
      z2 - the z coordinate of vertex 2
      x3 - the x coordinate of vertex 3
      y3 - the y coordinate of vertex 3
      z3 - the z coordinate of vertex 3
      color - the color of the triangle's front side; null for the default
      Throws:
      IllegalArgumentException - one of the first 9 arguments had the value Double.NaN
    • Triangle

      public Triangle(double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, Color color, Object tag)
      Constructor specifying a color and tag. The orientation of the triangle is determined by the right-hand rule when going from vertex 1 to vertex 2 to vertex 3. The tag must not be an instance of Triangle.
      Parameters:
      x1 - the x coordinate of vertex 1
      y1 - the y coordinate of vertex 1
      z1 - the z coordinate of vertex 1
      x2 - the x coordinate of vertex 2
      y2 - the y coordinate of vertex 2
      z2 - the z coordinate of vertex 2
      x3 - the x coordinate of vertex 3
      y3 - the y coordinate of vertex 3
      z3 - the z coordinate of vertex 3
      color - the color of the triangle's front side; null for the default
      tag - an object tagging the triangle; null if there is none
      Throws:
      IllegalArgumentException - a tag was a triangle or one of the first 9 arguments had the value Double.NaN
  • Method Details

    • hashCode

      public int hashCode()
      Return this object's hash code,
      Overrides:
      hashCode in class Object
      Returns:
      the hash code
    • isPatch

      public boolean isPatch()
      Determine if this triangle represents a cubic Bézier patch.
      Returns:
      true if this triangle represents a patch; false otherwise
    • area

      public double area()
      Compute the area of a triangle. The units are those in which a unit length is the distance between 0 and 1 along the x, y, and z axis all are assumed to use the same units. The algorithm computes the cross product of the vectors whose length and direction match the edges leading from the first vertex to the second and third respectively. The norm of this cross product is equal to twice the area of the triangle.
      Returns:
      the area of this triangle
    • getX1

      public double getX1()
      Get the x coordinate of a triangle's or patch's first vertex.
      Specified by:
      getX1 in interface Model3DOps.Triangle
      Returns:
      the x coordinate
    • getY1

      public double getY1()
      Get the y coordinate of a triangle's or patch's first vertex.
      Specified by:
      getY1 in interface Model3DOps.Triangle
      Returns:
      the y coordinate
    • getZ1

      public double getZ1()
      Get the z coordinate of a triangle's or patch's first vertex.
      Specified by:
      getZ1 in interface Model3DOps.Triangle
      Returns:
      the z coordinate
    • getX2

      public double getX2()
      Get the x coordinate of a triangle's or patch's second vertex.
      Specified by:
      getX2 in interface Model3DOps.Triangle
      Returns:
      the x coordinate
    • getY2

      public double getY2()
      Get the y coordinate of a triangle's or patch's second vertex.
      Specified by:
      getY2 in interface Model3DOps.Triangle
      Returns:
      the y coordinate
    • getZ2

      public double getZ2()
      Get the z coordinate of a triangle's or patch's second vertex.
      Specified by:
      getZ2 in interface Model3DOps.Triangle
      Returns:
      the z coordinate
    • getX3

      public double getX3()
      Get the x coordinate of a triangle's or patch's third vertex.
      Specified by:
      getX3 in interface Model3DOps.Triangle
      Returns:
      the x coordinate
    • getY3

      public double getY3()
      Get the y coordinate of a triangle's or patch's third vertex.
      Specified by:
      getY3 in interface Model3DOps.Triangle
      Returns:
      the y coordinate
    • getZ3

      public double getZ3()
      Get the z coordinate of a triangle's or patch's third vertex.
      Specified by:
      getZ3 in interface Model3DOps.Triangle
      Returns:
      the z coordinate
    • getX4

      public double getX4()
      Get the x coordinate of a patch's fourth vertex. The return value is valid only if isPatch() returns a value of true.
      Returns:
      the x coordinate
    • getY4

      public double getY4()
      Get the y coordinate of a patch's fourth vertex. The return value is valid only if isPatch() returns a value of true.
      Returns:
      the y coordinate
    • getZ4

      public double getZ4()
      Get the z coordinate of a patch's fourth vertex. The return value is valid only if isPatch() returns a value of true.
      Returns:
      the z coordinate
    • getMinX

      public double getMinX()
      Get the minimum value along the x axis for a triangle.
      Returns:
      the minimum x value
    • getMinY

      public double getMinY()
      Get the minimum value along the y axis for a triangle.
      Returns:
      the minimum y value
    • getMinZ

      public double getMinZ()
      Get the minimum value along the z axis for a triangle.
      Returns:
      the minimum z value
    • getMaxX

      public double getMaxX()
      Get the maximum value along the x axis for a triangle.
      Returns:
      the maximum x value
    • getMaxY

      public double getMaxY()
      Get the maximum value along the y axis for a triangle.
      Returns:
      the maximum y value
    • getMaxZ

      public double getMaxZ()
      Get the maximum value along the z axis for a triangle.
      Returns:
      the maximum z value
    • getBoundingBoxX

      public double getBoundingBoxX()
      Get the length parallel to the x axis of a triangle's bounding box. Each edge of the bounding box is parallel to either the x, y or z axis in the Model3D's coordinate system.
      Returns:
      the length of an edge of the bounding box parallel to the x axis
    • getBoundingBoxY

      public double getBoundingBoxY()
      Get the length parallel to the y axis of a triangle's bounding box. Each edge of the bounding box is parallel to either the x, y or z axis in the Model3D's coordinate system.
      Returns:
      the length of an edge of the bounding box parallel to the y axis
    • getBoundingBoxZ

      public double getBoundingBoxZ()
      Get the length parallel to the z axis of a triangle's bounding box. Each edge of the bounding box is parallel to either the x, y or z axis in the Model3D's coordinate system.
      Returns:
      the length of an edge of the bounding box parallel to the z axis
    • compareTo

      public int compareTo(Model3D.Triangle other)
      Comparison method. We compare on the basis of minimal z-axis values. This choice is convenient for rendering.
      Specified by:
      compareTo in interface Comparable<Model3D.Triangle>
      Parameters:
      other - the triangle to compare to.
      Returns:
      -1, 0, or 1 if this triangle is respectively lower than, equal to, or greater than the other triangle
    • getNormX

      public double getNormX()
      Get the X component of the normal vector.
      Returns:
      the X component of the normal vector
    • getNormY

      public double getNormY()
      Get the Y component of the normal vector.
      Returns:
      the Y component of the normal vector
    • getNormZ

      public double getNormZ()
      Get the Z component of the normal vector.
      Returns:
      the Z component of the normal vector
    • getTag

      public Object getTag()
      Get the tag associated with a triangle.
      Specified by:
      getTag in interface Model3DOps.Triangle
      Returns:
      the triangle's tag; null if there is none
    • getTagHistory

      public List<Object> getTagHistory()
      Get the tag history list for a triangle. A history list can be created when a model adds triangles with tags from another model.
      Returns:
      the tag history list
    • getColor

      public Color getColor()
      Get a triangle's color
      Specified by:
      getColor in interface Model3DOps.Triangle
      Returns:
      the triangle's color; null if no color is specified.