您的位置:首页 > 编程语言 > Java开发

javafx.geometry.BoundingBox

2013-04-29 19:39 274 查看
public class BoundingBox
extends Bounds

A rectangular bounding(边界) box which is used to describe the bounds of a node or other scene graph object.

BoundingBox

public BoundingBox(double minX,

           double minY,

           double width,

           double height)

Creates a new instance of 2D BoundingBox.

Parameters:

minX - the X coordinate of the upper-left corner

minY - the Y coordinate of the upper-left corner

width - the width of the BoundingBox

height - the height of the BoundingBox

BoundingBox

public BoundingBox(double minX,

           double minY,

           double minZ,

           double width,

           double height,

           double depth)

Creates a new instance of 3D BoundingBox.

Parameters:

minX - the X coordinate of the upper-left corner

minY - the Y coordinate of the upper-left corner

minZ - the minimum(最低限度) z coordinate of the BoundingBox

width - the width of the BoundingBox

height - the height of the BoundingBox

depth - the depth of the BoundingBox

contains

public boolean contains(double x, double y)

Tests if the specified (x, y) coordinates are inside the boundary of Bounds. The points on the boundary(边界) are considered to lie inside the BoundingBox.

Specified by:

contains in class Bounds

Parameters:

x - the specified x coordinate to be tested

y - the specified y coordinate to be tested

Returns:

true if the specified (x, y) coordinates are inside the boundary of this Bounds; false otherwise.

isEmpty

public boolean isEmpty()

Indicates whether any of the dimensions(尺寸)(width, height or depth) of this bounds is less than zero.

Specified by:

isEmpty in class Bounds

Returns:

true if any of the dimensions(width, height or depth) of this bounds is less than zero.



intersects(相交)

public boolean intersects(Bounds b)

Tests if the interior(内部) of this Bounds intersects the interior(内部) of a specified Bounds, b.

Specified by:

intersects in class Bounds

Parameters:

b - The specified Bounds

Returns:

true if the interior of this Bounds and the interior of the specified Bounds, b, intersect.

java代码:
package geometry;

import javafx.geometry.BoundingBox;

public class TestBoundingBox{

public static void main(String[] args) {
BoundingBox boundingBox = new BoundingBox(0,0,18.2,28.9);
BoundingBox boundingBox2 = new BoundingBox(0,0,0,18.2,28.9,8);

System.out.println(boundingBox.contains(3, 5)); //某个点是否在这个界限内 true
System.out.println(boundingBox.contains(30, 5));//false

BoundingBox boundingBox3 = new BoundingBox(0,0,0,-9);
//一定要小于0才返回true,等于0都不返回,难道此方法是用来检测现在的状态是否正确
//如果一个节点的边界之间相见都小于0了,那这是什么边界?根本就不可能的事情
System.out.println(boundingBox3.isEmpty());

System.out.println(boundingBox.intersects(boundingBox2));//相交
System.out.println(boundingBox.intersects(boundingBox3));//不相交
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  javafx