Class Box

java.lang.Object
eu.iv4xr.framework.spatial.Box
All Implemented Interfaces:
LineIntersectable

public class Box extends Object implements LineIntersectable
Representing a 3D rectangular shape. For now, we don't support rotation.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
    (package private) float
     
    The x,y, and z width.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Box​(Vec3 center, Vec3 width)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) boolean
    between​(float lowerbound, float x, float upperbound)
    Check if x is between the given lower and upperbound, with additional epsilon as margin.
    In typical cases, if a line intersects with a 3D rectangle, it will intersect at one point (if the line ends somewhere inside the rectangle), or at two points (if the line pass through the whole rectangle).
    (package private) Vec3
    intersectPlaneXY​(Vec3 p, Vec3 q, float c)
    Calculate the intersection of the line between p and q, and a plane XY where z = c.
    (package private) Vec3
    intersectPlaneXZ​(Vec3 p, Vec3 q, float c)
    Calculate the intersection of the line between p and q, and a plane XZ where y = c.
    (package private) Vec3
    intersectPlaneYZ​(Vec3 p, Vec3 q, float c)
    Calculate the intersection of the line between p and q, and a plane YZ where x = c.
    static void
    main​(String[] args)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface eu.iv4xr.framework.spatial.LineIntersectable

    intersects
  • Field Details

    • center

      public Vec3 center
    • width

      public Vec3 width
      The x,y, and z width. Should be >0. So, from the center, the rectangle extend 1/2 its width to each of the corresponding direction.
    • epsilon

      float epsilon
  • Constructor Details

    • Box

      public Box(Vec3 center, Vec3 width)
  • Method Details

    • intersect

      public Collection<Vec3> intersect(Line l)
      In typical cases, if a line intersects with a 3D rectangle, it will intersect at one point (if the line ends somewhere inside the rectangle), or at two points (if the line pass through the whole rectangle). There are two a bit exceptional case: (1) the line touches one of the rectangle corner. Although technically it intersects with three of the rectangle's surfaces, the intersection points will all be the the same, namely the corner. So, we will only return this single intersection point. (2) the line slides along one of the rectangle's surfaces. Technically, it will then intersects at infinite number of points. However we will only return the points where the line would go through other surfaces (the one that it does NOT slide on). Bearing those special cases in mind, this method will therefore return at most 2 intersection points.
      Specified by:
      intersect in interface LineIntersectable
      Parameters:
      l - line segment
      Returns:
      list of intersections.
    • between

      boolean between(float lowerbound, float x, float upperbound)
      Check if x is between the given lower and upperbound, with additional epsilon as margin.
    • intersectPlaneXY

      Vec3 intersectPlaneXY(Vec3 p, Vec3 q, float c)
      Calculate the intersection of the line between p and q, and a plane XY where z = c.
    • intersectPlaneXZ

      Vec3 intersectPlaneXZ(Vec3 p, Vec3 q, float c)
      Calculate the intersection of the line between p and q, and a plane XZ where y = c.
    • intersectPlaneYZ

      Vec3 intersectPlaneYZ(Vec3 p, Vec3 q, float c)
      Calculate the intersection of the line between p and q, and a plane YZ where x = c.
    • main

      public static void main(String[] args)