three.js Box2

2023-02-16 17:46 更新

表示二維空間中的一個軸對齊包圍盒(axis-aligned bounding box,AABB)。

構(gòu)造函數(shù)(Constructor)

Box2( min : Vector2, max : Vector2 )

min - (可選) Vector2 表示該盒子的下邊界(x, y)。默認(rèn)值為( + Infinity, + Infinity )。
max - (可選) Vector2 表示該盒子的上邊界(x, y)。默認(rèn)值為( - Infinity, - Infinity )。

創(chuàng)建一個介于最小和最大值之間的Box2。

屬性(Properties)

.min : Vector2

Vector2 表示該盒子的下邊界(x, y)。

默認(rèn)值為( + Infinity, + Infinity )。

.max : Vector2

Vector2 表示該盒子的上邊界(x, y)。

默認(rèn)值為( - Infinity, - Infinity )。

方法(Methods)

.clampPoint ( point : Vector2, target : Vector2 ) : Vector2

point - clamp 的位置 (Vector2)
target — 結(jié)果會被復(fù)制到該二維向量中。

在該盒子范圍內(nèi)夾緊(Clamps)point。

.clone () : Box2

返回一個新的Box2,其min和max與此盒子相同。

.containsBox ( box : Box2 ) : Boolean

box - 要檢查是否被包含的盒子。

如果盒子包含整個被檢查盒子,則返回true。如果兩者重疊,
也會返回true。

.containsPoint ( point : Vector2 ) : Boolean

point - 要檢查是否被包含的點Vector2。

如果指定的點(point)位于盒子的邊界內(nèi)或邊界上,則返回true。

.copy ( box : Box2 ) : this

將box的min 和 max復(fù)制到此盒子中。

.distanceToPoint ( point : Vector2 ) : Float

point - 要測量距離的點(Vector2)。

返回這個盒子的任何邊緣到指定點的距離。如果這個點(point)位于這個盒子里,距離將是0。

.equals ( box : Box2 ) : Boolean

box - 要對比的盒子

如果這個盒子和被對比盒子具有相同的上下邊界,則返回true。

.expandByPoint ( point : Vector2 ) : this

point - 應(yīng)該被盒子包含的點。

擴展盒子的邊界來包含該點。

.expandByScalar ( scalar : Float ) : this

scalar - 盒子擴展的距離。

在每個維度上擴展參數(shù)scalar所指定的距離,如果為負數(shù),則盒子空間將收縮。

.expandByVector ( vector : Vector2 ) : this

vector - 按照該向量擴展。

在每個維度中按vector的數(shù)值進行擴展。寬度在兩個方向上的擴展將由vector的x分量確定, 高度在兩個方向上的擴展則由y分量確定。

.getCenter ( target : Vector2 ) : Vector2

target — 結(jié)果將被復(fù)制到此二維向量中。

以二維向量形式返回盒子的中心點。

.getParameter ( point : Vector2, target : Vector2 ) : Vector2

point - 二維向量(Vector2).
target — 結(jié)果將被復(fù)制到此二維向量中。

返回一個點作為此盒子的寬度和高度的比例。

.getSize ( target : Vector2 ) : Vector2

target — 結(jié)果將被復(fù)制到此二維向量中。

返回此盒子的寬度和高度。

.intersect ( box : Box2 ) : this

box - 要相交的盒子。

返回兩者的相交后的盒子,并將相交后的盒子的上限設(shè)置為兩者的上限中的較小者,將下限設(shè)置為兩者的下限中的較大者。

.intersectsBox ( box : Box2 ) : Boolean

box - 用來檢查相交的盒子。

確定該盒子是否和其相交。

.isEmpty () : Boolean

如果這個盒子包含0個頂點,則返回true。

請注意,一個下上邊界相等的的盒子仍然包括一個點,一個兩個邊界共享的點。

.makeEmpty () : this

使此盒子為空。

.set ( min : Vector2, max : Vector2 ) : this

min - (必須) 表示該盒子的下邊界(x, y)。

max - (必須) 表示該盒子的上邊界(x, y)。

設(shè)置這個盒子的上下(x, y)的界限。
請注意,此方法僅復(fù)制給定對象的值。

.setFromCenterAndSize ( center : Vector2, size : Vector2 ) : this

center - 盒子所要設(shè)置的中心位置。 (Vector2).
size - 盒子所要設(shè)置的x和y尺寸 (Vector2).

使盒子的中心點位于center,并設(shè)置寬高為size中指定的值。

.setFromPoints ( points : Array ) : this

points - 點的集合,由這些點確定的空間將被盒子包圍。

設(shè)置這個盒子的上下邊界,來包含所有設(shè)置在points參數(shù)中的點。

.translate ( offset : Vector2 ) : this

offset - 偏移方向和距離。

添加 offset 到這個盒子的上下邊界,實際上在2D空間移動這個盒子offset個單位。

.union ( box : Box2 ) : this

box - 將要與該盒子聯(lián)合的盒子

在box參數(shù)的上邊界和該盒子的上邊界之間取較大者,而對兩者的下邊界取較小者,這樣獲得一個新的較大的聯(lián)合盒子。

源碼(Source)

src/math/Box2.js


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號