Class AABBd
- java.lang.Object
-
- org.joml.AABBd
-
- All Implemented Interfaces:
Externalizable,Serializable
public class AABBd extends Object implements Externalizable
Represents an axis-aligned box defined via the minimum and maximum corner coordinates.- Author:
- Kai Burjack
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description doublemaxXThe x coordinate of the maximum corner.doublemaxYThe y coordinate of the maximum corner.doublemaxZThe z coordinate of the maximum corner.doubleminXThe x coordinate of the minimum corner.doubleminYThe y coordinate of the minimum corner.doubleminZThe z coordinate of the minimum corner.
-
Constructor Summary
Constructors Constructor Description AABBd()Create a newAABBdrepresenting the box with(minX, minY, minZ)=(+inf, +inf, +inf)and(maxX, maxY, maxZ)=(-inf, -inf, -inf).AABBd(double minX, double minY, double minZ, double maxX, double maxY, double maxZ)Create a newAABBdwith the given minimum and maximum corner coordinates.AABBd(AABBd source)Create a newAABBdas a copy of the givensource.AABBd(Vector3dc min, Vector3dc max)Create a newAABBdwith the given minimum and maximum corner coordinates.AABBd(Vector3fc min, Vector3fc max)Create a newAABBdwith the given minimum and maximum corner coordinates.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AABBdcorrectBounds()Ensure that the minimum coordinates are strictly less than or equal to the maximum coordinates by swapping them if necessary.booleanequals(Object obj)doublegetMax(int component)Get the maximum corner coordinate of the given component.doublegetMin(int component)Get the minimum corner coordinate of the given component.inthashCode()intintersectLineSegment(double p0X, double p0Y, double p0Z, double p1X, double p1Y, double p1Z, Vector2d result)Determine whether the undirected line segment with the end points(p0X, p0Y, p0Z)and(p1X, p1Y, p1Z)intersects this AABB, and return the values of the parameter t in the ray equation p(t) = origin + p0 * (p1 - p0) of the near and far point of intersection.intintersectLineSegment(LineSegmentf lineSegment, Vector2d result)Determine whether the given undirected line segment intersects this AABB, and return the values of the parameter t in the ray equation p(t) = origin + p0 * (p1 - p0) of the near and far point of intersection.booleanintersectRay(double originX, double originY, double originZ, double dirX, double dirY, double dirZ, Vector2d result)Determine whether the given ray with the origin(originX, originY, originZ)and direction(dirX, dirY, dirZ)intersects this AABB, and return the values of the parameter t in the ray equation p(t) = origin + t * dir of the near and far point of intersection.booleanintersectRay(Rayd ray, Vector2d result)Determine whether the given ray intersects this AABB, and return the values of the parameter t in the ray equation p(t) = origin + t * dir of the near and far point of intersection.voidreadExternal(ObjectInput in)AABBdsetMax(double maxX, double maxY, double maxZ)Set the maximum corner coordinates.AABBdsetMax(Vector3dc max)Set the maximum corner coordinates.AABBdsetMin(double minX, double minY, double minZ)Set the minimum corner coordinates.AABBdsetMin(Vector3dc min)Set the minimum corner coordinates.booleantestAABB(AABBd other)Test whetherthisandotherintersect.booleantestPlane(double a, double b, double c, double d)Test whether the plane given via its plane equationa*x + b*y + c*z + d = 0intersects this AABB.booleantestPlane(Planed plane)Test whether the given plane intersects this AABB.booleantestPoint(double x, double y, double z)Test whether the point(x, y, z)lies inside this AABB.booleantestPoint(Vector3dc point)Test whether the given point lies inside this AABB.booleantestRay(double originX, double originY, double originZ, double dirX, double dirY, double dirZ)Test whether the given ray with the origin(originX, originY, originZ)and direction(dirX, dirY, dirZ)intersects this AABB.booleantestRay(Rayd ray)Test whether the given ray intersects this AABB.booleantestSphere(double centerX, double centerY, double centerZ, double radiusSquared)Test whether this AABB intersects the given sphere with equation(x - centerX)^2 + (y - centerY)^2 + (z - centerZ)^2 - radiusSquared = 0.booleantestSphere(Spheref sphere)Test whether this AABB intersects the given sphere.StringtoString()Return a string representation of this AABB.StringtoString(NumberFormat formatter)Return a string representation of this AABB by formatting the vector components with the givenNumberFormat.AABBdtransform(Matrix4dc m)AABBdtransform(Matrix4dc m, AABBd dest)AABBdtranslate(double x, double y, double z)Translatethisby the vector(x, y, z).AABBdtranslate(double x, double y, double z, AABBd dest)Translatethisby the vector(x, y, z)and store the result indest.AABBdtranslate(Vector3dc xyz)Translatethisby the given vectorxyz.AABBdtranslate(Vector3dc xyz, AABBd dest)Translatethisby the given vectorxyzand store the result indest.AABBdtranslate(Vector3fc xyz)Translatethisby the given vectorxyz.AABBdtranslate(Vector3fc xyz, AABBd dest)Translatethisby the given vectorxyzand store the result indest.AABBdunion(double x, double y, double z)Setthisto the union ofthisand the given point(x, y, z).AABBdunion(double x, double y, double z, AABBd dest)Compute the union ofthisand the given point(x, y, z)and store the result indest.AABBdunion(AABBd other)Setthisto the union ofthisandother.AABBdunion(AABBd other, AABBd dest)Compute the union ofthisandotherand store the result indest.AABBdunion(Vector3dc p)Setthisto the union ofthisand the given pointp.AABBdunion(Vector3dc p, AABBd dest)Compute the union ofthisand the given pointpand store the result indest.voidwriteExternal(ObjectOutput out)
-
-
-
Field Detail
-
minX
public double minX
The x coordinate of the minimum corner.
-
minY
public double minY
The y coordinate of the minimum corner.
-
minZ
public double minZ
The z coordinate of the minimum corner.
-
maxX
public double maxX
The x coordinate of the maximum corner.
-
maxY
public double maxY
The y coordinate of the maximum corner.
-
maxZ
public double maxZ
The z coordinate of the maximum corner.
-
-
Constructor Detail
-
AABBd
public AABBd()
Create a newAABBdrepresenting the box with(minX, minY, minZ)=(+inf, +inf, +inf)and(maxX, maxY, maxZ)=(-inf, -inf, -inf).
-
AABBd
public AABBd(AABBd source)
Create a newAABBdas a copy of the givensource.- Parameters:
source- theAABBdto copy from
-
AABBd
public AABBd(Vector3fc min, Vector3fc max)
Create a newAABBdwith the given minimum and maximum corner coordinates.- Parameters:
min- the minimum coordinatesmax- the maximum coordinates
-
AABBd
public AABBd(Vector3dc min, Vector3dc max)
Create a newAABBdwith the given minimum and maximum corner coordinates.- Parameters:
min- the minimum coordinatesmax- the maximum coordinates
-
AABBd
public AABBd(double minX, double minY, double minZ, double maxX, double maxY, double maxZ)Create a newAABBdwith the given minimum and maximum corner coordinates.- Parameters:
minX- the x coordinate of the minimum cornerminY- the y coordinate of the minimum cornerminZ- the z coordinate of the minimum cornermaxX- the x coordinate of the maximum cornermaxY- the y coordinate of the maximum cornermaxZ- the z coordinate of the maximum corner
-
-
Method Detail
-
setMin
public AABBd setMin(double minX, double minY, double minZ)
Set the minimum corner coordinates.- Parameters:
minX- the x coordinate of the minimum cornerminY- the y coordinate of the minimum cornerminZ- the z coordinate of the minimum corner- Returns:
- this
-
setMax
public AABBd setMax(double maxX, double maxY, double maxZ)
Set the maximum corner coordinates.- Parameters:
maxX- the x coordinate of the maximum cornermaxY- the y coordinate of the maximum cornermaxZ- the z coordinate of the maximum corner- Returns:
- this
-
setMin
public AABBd setMin(Vector3dc min)
Set the minimum corner coordinates.- Parameters:
min- the minimum coordinates- Returns:
- this
-
setMax
public AABBd setMax(Vector3dc max)
Set the maximum corner coordinates.- Parameters:
max- the maximum coordinates- Returns:
- this
-
getMax
public double getMax(int component) throws IllegalArgumentExceptionGet the maximum corner coordinate of the given component.- Parameters:
component- the component, within[0..2]- Returns:
- the maximum coordinate
- Throws:
IllegalArgumentException- ifcomponentis not within[0..2]
-
getMin
public double getMin(int component) throws IllegalArgumentExceptionGet the minimum corner coordinate of the given component.- Parameters:
component- the component, within[0..2]- Returns:
- the maximum coordinate
- Throws:
IllegalArgumentException- ifcomponentis not within[0..2]
-
union
public AABBd union(double x, double y, double z)
Setthisto the union ofthisand the given point(x, y, z).- Parameters:
x- the x coordinate of the pointy- the y coordinate of the pointz- the z coordinate of the point- Returns:
- this
-
union
public AABBd union(Vector3dc p)
Setthisto the union ofthisand the given pointp.- Parameters:
p- the point- Returns:
- this
-
union
public AABBd union(double x, double y, double z, AABBd dest)
Compute the union ofthisand the given point(x, y, z)and store the result indest.- Parameters:
x- the x coordinate of the pointy- the y coordinate of the pointz- the z coordinate of the pointdest- will hold the result- Returns:
- dest
-
union
public AABBd union(Vector3dc p, AABBd dest)
Compute the union ofthisand the given pointpand store the result indest.- Parameters:
p- the pointdest- will hold the result- Returns:
- dest
-
union
public AABBd union(AABBd other)
Setthisto the union ofthisandother.- Parameters:
other- the otherAABBd- Returns:
- this
-
union
public AABBd union(AABBd other, AABBd dest)
Compute the union ofthisandotherand store the result indest.- Parameters:
other- the otherAABBddest- will hold the result- Returns:
- dest
-
correctBounds
public AABBd correctBounds()
Ensure that the minimum coordinates are strictly less than or equal to the maximum coordinates by swapping them if necessary.- Returns:
- this
-
translate
public AABBd translate(Vector3dc xyz)
Translatethisby the given vectorxyz.- Parameters:
xyz- the vector to translate by- Returns:
- this
-
translate
public AABBd translate(Vector3dc xyz, AABBd dest)
Translatethisby the given vectorxyzand store the result indest.- Parameters:
xyz- the vector to translate bydest- will hold the result- Returns:
- dest
-
translate
public AABBd translate(Vector3fc xyz)
Translatethisby the given vectorxyz.- Parameters:
xyz- the vector to translate by- Returns:
- this
-
translate
public AABBd translate(Vector3fc xyz, AABBd dest)
Translatethisby the given vectorxyzand store the result indest.- Parameters:
xyz- the vector to translate bydest- will hold the result- Returns:
- dest
-
translate
public AABBd translate(double x, double y, double z)
Translatethisby the vector(x, y, z).- Parameters:
x- the x coordinate to translate byy- the y coordinate to translate byz- the z coordinate to translate by- Returns:
- this
-
translate
public AABBd translate(double x, double y, double z, AABBd dest)
Translatethisby the vector(x, y, z)and store the result indest.- Parameters:
x- the x coordinate to translate byy- the y coordinate to translate byz- the z coordinate to translate bydest- will hold the result- Returns:
- dest
-
testPoint
public boolean testPoint(double x, double y, double z)Test whether the point(x, y, z)lies inside this AABB.- Parameters:
x- the x coordinate of the pointy- the y coordinate of the pointz- the z coordinate of the point- Returns:
trueiff the given point lies inside this AABB;falseotherwise
-
testPoint
public boolean testPoint(Vector3dc point)
Test whether the given point lies inside this AABB.- Parameters:
point- the coordinates of the point- Returns:
trueiff the given point lies inside this AABB;falseotherwise
-
testPlane
public boolean testPlane(double a, double b, double c, double d)Test whether the plane given via its plane equationa*x + b*y + c*z + d = 0intersects this AABB.Reference: http://www.lighthouse3d.com ("Geometric Approach - Testing Boxes II")
- Parameters:
a- the x factor in the plane equationb- the y factor in the plane equationc- the z factor in the plane equationd- the constant in the plane equation- Returns:
trueiff the plane intersects this AABB;falseotherwise
-
testPlane
public boolean testPlane(Planed plane)
Test whether the given plane intersects this AABB.Reference: http://www.lighthouse3d.com ("Geometric Approach - Testing Boxes II")
- Parameters:
plane- the plane- Returns:
trueiff the plane intersects this AABB;falseotherwise
-
testAABB
public boolean testAABB(AABBd other)
Test whetherthisandotherintersect.- Parameters:
other- the other AABB- Returns:
trueiff both AABBs intersect;falseotherwise
-
testSphere
public boolean testSphere(double centerX, double centerY, double centerZ, double radiusSquared)Test whether this AABB intersects the given sphere with equation(x - centerX)^2 + (y - centerY)^2 + (z - centerZ)^2 - radiusSquared = 0.Reference: http://stackoverflow.com
- Parameters:
centerX- the x coordinate of the center of the spherecenterY- the y coordinate of the center of the spherecenterZ- the z coordinate of the center of the sphereradiusSquared- the square radius of the sphere- Returns:
trueiff this AABB and the sphere intersect;falseotherwise
-
testSphere
public boolean testSphere(Spheref sphere)
Test whether this AABB intersects the given sphere.Reference: http://stackoverflow.com
- Parameters:
sphere- the sphere- Returns:
trueiff this AABB and the sphere intersect;falseotherwise
-
testRay
public boolean testRay(double originX, double originY, double originZ, double dirX, double dirY, double dirZ)Test whether the given ray with the origin(originX, originY, originZ)and direction(dirX, dirY, dirZ)intersects this AABB.This method returns
truefor a ray whose origin lies inside this AABB.Reference: An Efficient and Robust Ray–Box Intersection
- Parameters:
originX- the x coordinate of the ray's originoriginY- the y coordinate of the ray's originoriginZ- the z coordinate of the ray's origindirX- the x coordinate of the ray's directiondirY- the y coordinate of the ray's directiondirZ- the z coordinate of the ray's direction- Returns:
trueif this AABB and the ray intersect;falseotherwise
-
testRay
public boolean testRay(Rayd ray)
Test whether the given ray intersects this AABB.This method returns
truefor a ray whose origin lies inside this AABB.Reference: An Efficient and Robust Ray–Box Intersection
- Parameters:
ray- the ray- Returns:
trueif this AABB and the ray intersect;falseotherwise
-
intersectRay
public boolean intersectRay(double originX, double originY, double originZ, double dirX, double dirY, double dirZ, Vector2d result)Determine whether the given ray with the origin(originX, originY, originZ)and direction(dirX, dirY, dirZ)intersects this AABB, and return the values of the parameter t in the ray equation p(t) = origin + t * dir of the near and far point of intersection.This method returns
truefor a ray whose origin lies inside this AABB.Reference: An Efficient and Robust Ray–Box Intersection
- Parameters:
originX- the x coordinate of the ray's originoriginY- the y coordinate of the ray's originoriginZ- the z coordinate of the ray's origindirX- the x coordinate of the ray's directiondirY- the y coordinate of the ray's directiondirZ- the z coordinate of the ray's directionresult- a vector which will hold the resulting values of the parameter t in the ray equation p(t) = origin + t * dir of the near and far point of intersection iff the ray intersects this AABB- Returns:
trueif the given ray intersects this AABB;falseotherwise
-
intersectRay
public boolean intersectRay(Rayd ray, Vector2d result)
Determine whether the given ray intersects this AABB, and return the values of the parameter t in the ray equation p(t) = origin + t * dir of the near and far point of intersection.This method returns
truefor a ray whose origin lies inside this AABB.Reference: An Efficient and Robust Ray–Box Intersection
- Parameters:
ray- the rayresult- a vector which will hold the resulting values of the parameter t in the ray equation p(t) = origin + t * dir of the near and far point of intersection iff the ray intersects this AABB- Returns:
trueif the given ray intersects this AABB;falseotherwise
-
intersectLineSegment
public int intersectLineSegment(double p0X, double p0Y, double p0Z, double p1X, double p1Y, double p1Z, Vector2d result)Determine whether the undirected line segment with the end points(p0X, p0Y, p0Z)and(p1X, p1Y, p1Z)intersects this AABB, and return the values of the parameter t in the ray equation p(t) = origin + p0 * (p1 - p0) of the near and far point of intersection.This method returns
truefor a line segment whose either end point lies inside this AABB.Reference: An Efficient and Robust Ray–Box Intersection
- Parameters:
p0X- the x coordinate of the line segment's first end pointp0Y- the y coordinate of the line segment's first end pointp0Z- the z coordinate of the line segment's first end pointp1X- the x coordinate of the line segment's second end pointp1Y- the y coordinate of the line segment's second end pointp1Z- the z coordinate of the line segment's second end pointresult- a vector which will hold the resulting values of the parameter t in the ray equation p(t) = p0 + t * (p1 - p0) of the near and far point of intersection iff the line segment intersects this AABB- Returns:
Intersectiond.INSIDEif the line segment lies completely inside of this AABB; orIntersectiond.OUTSIDEif the line segment lies completely outside of this AABB; orIntersectiond.ONE_INTERSECTIONif one of the end points of the line segment lies inside of this AABB; orIntersectiond.TWO_INTERSECTIONif the line segment intersects two sides of this AABB or lies on an edge or a side of this AABB
-
intersectLineSegment
public int intersectLineSegment(LineSegmentf lineSegment, Vector2d result)
Determine whether the given undirected line segment intersects this AABB, and return the values of the parameter t in the ray equation p(t) = origin + p0 * (p1 - p0) of the near and far point of intersection.This method returns
truefor a line segment whose either end point lies inside this AABB.Reference: An Efficient and Robust Ray–Box Intersection
- Parameters:
lineSegment- the line segmentresult- a vector which will hold the resulting values of the parameter t in the ray equation p(t) = p0 + t * (p1 - p0) of the near and far point of intersection iff the line segment intersects this AABB- Returns:
Intersectiond.INSIDEif the line segment lies completely inside of this AABB; orIntersectiond.OUTSIDEif the line segment lies completely outside of this AABB; orIntersectiond.ONE_INTERSECTIONif one of the end points of the line segment lies inside of this AABB; orIntersectiond.TWO_INTERSECTIONif the line segment intersects two sides of this AABB or lies on an edge or a side of this AABB
-
transform
public AABBd transform(Matrix4dc m)
- Parameters:
m- the affine transformation matrix- Returns:
- this
-
transform
public AABBd transform(Matrix4dc m, AABBd dest)
Apply the givenaffinetransformation to thisAABBdand store the resulting AABB intodest.The matrix in
mmust beaffine.- Parameters:
m- the affine transformation matrixdest- will hold the result- Returns:
- dest
-
toString
public String toString()
Return a string representation of this AABB.This method creates a new
DecimalFormaton every invocation with the format string "0.000E0;-".
-
toString
public String toString(NumberFormat formatter)
Return a string representation of this AABB by formatting the vector components with the givenNumberFormat.- Parameters:
formatter- theNumberFormatused to format the vector components with- Returns:
- the string representation
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
-