Package com.jme3.math

Class Rectangle

java.lang.Object
com.jme3.math.Rectangle
All Implemented Interfaces:
Savable, Serializable, Cloneable

public final class Rectangle extends Object implements Savable, Cloneable, Serializable
Rectangle defines a finite plane within three-dimensional space that is specified via three points (A, B, C). These three points define a triangle with the fourth point defining the rectangle (B + C) - A.

The corner points are named as follows:

     C +---+ D
       |   |
       |   |
       |   |
       |   |
     A +---+ B
 

If angle BAC isn't exactly 90 degrees, then the resulting shape is actually parallelogram, not a rectangle.

See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor creates a new Rectangle with no defined corners.
    Constructor creates a new Rectangle with defined A, B, and C points that define the area of the rectangle.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the coordinates of the 4th corner, calculated by the formula D = (B + C) - A .
    Returns a normal vector, calculated by the formula
    Create a copy of this rectangle.
    getA returns the first point of the rectangle.
    getB returns the second point of the rectangle.
    getC returns the third point of the rectangle.
    random returns a random point within the plane defined by: A, B, C, and (B + C) - A.
    random(Vector3f result)
    random returns a random point within the plane defined by: A, B, C, and (B + C) - A.
    void
    read(JmeImporter importer)
    De-serialize this rectangle from the specified importer, for example when loading from a J3O file.
    void
    setA sets the first point of the rectangle.
    void
    setB sets the second point of the rectangle.
    void
    setC sets the third point of the rectangle.
    void
    Serialize this rectangle to the specified exporter, for example when saving to a J3O file.

    Methods inherited from class java.lang.Object

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

    • Rectangle

      public Rectangle()
      Constructor creates a new Rectangle with no defined corners. A, B, and C must be set to define a valid rectangle.
    • Rectangle

      public Rectangle(Vector3f a, Vector3f b, Vector3f c)
      Constructor creates a new Rectangle with defined A, B, and C points that define the area of the rectangle.
      Parameters:
      a - the first corner of the rectangle.
      b - the second corner of the rectangle.
      c - the third corner of the rectangle.
  • Method Details

    • getA

      public Vector3f getA()
      getA returns the first point of the rectangle.
      Returns:
      the first point of the rectangle.
    • setA

      public void setA(Vector3f a)
      setA sets the first point of the rectangle.
      Parameters:
      a - the first point of the rectangle.
    • getB

      public Vector3f getB()
      getB returns the second point of the rectangle.
      Returns:
      the second point of the rectangle.
    • setB

      public void setB(Vector3f b)
      setB sets the second point of the rectangle.
      Parameters:
      b - the second point of the rectangle.
    • getC

      public Vector3f getC()
      getC returns the third point of the rectangle.
      Returns:
      the third point of the rectangle.
    • setC

      public void setC(Vector3f c)
      setC sets the third point of the rectangle.
      Parameters:
      c - the third point of the rectangle.
    • calculateD

      public Vector3f calculateD()
      Returns the coordinates of the 4th corner, calculated by the formula D = (B + C) - A .
      Returns:
      the corner location (a new Vector3f)
    • calculateNormal

      public Vector3f calculateNormal(Vector3f normal)
      Returns a normal vector, calculated by the formula
            (C - B) x (B - A)
       N = -------------------
           |(C - B) x (B - A)|
       
      Parameters:
      normal - storage for the normal, or null for a new Vector3f
      Returns:
      the normal direction (either normal or a new Vector3f)
    • random

      public Vector3f random()
      random returns a random point within the plane defined by: A, B, C, and (B + C) - A.
      Returns:
      a random point within the rectangle.
    • random

      public Vector3f random(Vector3f result)
      random returns a random point within the plane defined by: A, B, C, and (B + C) - A.
      Parameters:
      result - Vector to store result in
      Returns:
      a random point within the rectangle.
    • write

      public void write(JmeExporter e) throws IOException
      Serialize this rectangle to the specified exporter, for example when saving to a J3O file.
      Specified by:
      write in interface Savable
      Parameters:
      e - (not null)
      Throws:
      IOException - from the exporter
    • read

      public void read(JmeImporter importer) throws IOException
      De-serialize this rectangle from the specified importer, for example when loading from a J3O file.
      Specified by:
      read in interface Savable
      Parameters:
      importer - (not null)
      Throws:
      IOException - from the importer
    • clone

      public Rectangle clone()
      Create a copy of this rectangle.
      Overrides:
      clone in class Object
      Returns:
      a new instance, equivalent to this one