Class BoundingBox
แพคเกจ: @aspose/3d (v24.12.0)
BoundingBox แสดงถึง axis-aligned bounding box (AABB) ใน 3D space. มันเก็บ minimum มุมหนึ่งและ maximum มุมเป็นอ็อบเจ็กต์ธรรมดาที่มี x, y, z ฟิลด์. อ็อบเจ็กต์ที่สร้างใหม่ BoundingBox() โดยไม่มีอาร์กิวเมนต์อยู่ในสถานะ “null” — minimum คืนค่า +Infinity และ maximum คืนค่า -Infinity — และขยายอย่างถูกต้องเมื่อจุดถูกเพิ่มผ่าน merge(). BoundingBox ถูกส่งออกจาก @aspose/3d/utilities sub-path.
export class BoundingBoximport { BoundingBox } from '@aspose/3d/utilities';Properties
คำนวณกล่องขอบเขตสำหรับชุดของจุด.
import { BoundingBox, Vector3 } from '@aspose/3d/utilities';
const points = [
new Vector3(-1, 0, -1),
new Vector3(1, 2, 1),
new Vector3(0, -0.5, 0),
];
const bbox = new BoundingBox();
for (const p of points) {
bbox.merge(p);
}
console.log(`Min: (${bbox.minimum.x}, ${bbox.minimum.y}, ${bbox.minimum.z})`);
// Min: (-1, -0.5, -1)
console.log(`Max: (${bbox.maximum.x}, ${bbox.maximum.y}, ${bbox.maximum.z})`);
// Max: (1, 2, 1)
const c = bbox.center;
console.log(`Center: (${c.x}, ${c.y.toFixed(3)}, ${c.z})`);
// Center: (0, 0.750, 0)
Properties
| Properties | Properties |
|---|---|
new BoundingBox() | สร้าง null bounding box. ขยายเมื่อ merge() ถูกเรียก. |
new BoundingBox(minimum, maximum) | สร้างกล่องจากสอง {x, y, z} วัตถุมุม. |
new BoundingBox(minX, minY, minZ, maxX, maxY, maxZ) | สร้างกล่องจากส่วนประกอบเชิงสเกลาร์หกตัว. |
คุณสมบัติสถิต
| Properties | Properties | Properties |
|---|---|---|
BoundingBox.null | BoundingBox | กล่องขอบเขตศูนย์ (ไม่มีขนาด, ไม่ได้เริ่มต้น). |
BoundingBox.infinite | BoundingBox | กล่องที่ครอบคลุมช่วงตัวเลขทั้งหมดตั้งแต่ -Infinity ถึง +Infinity. |
Properties
การตั้งชื่อที่สำคัญ: BoundingBox ใช้ minimum และ maximum — ไม่ใช่ min และ max.
| Properties | Properties | Properties |
|---|---|---|
minimum | {x: number, y: number, z: number} (อ่านอย่างเดียว) | มุมที่มีค่า x, y, z เล็กที่สุด. คืนค่า +Infinity บนแต่ละแกนเมื่อกล่องเป็นค่าว่าง. |
maximum | {x: number, y: number, z: number} (อ่านอย่างเดียว) | มุมที่มีค่า x, y, z มากที่สุด. คืนค่า -Infinity บนแต่ละแกนเมื่อกล่องเป็นค่าว่าง. |
center | {x: number, y: number, z: number} (อ่านอย่างเดียว) | จุดศูนย์กลางเชิงเรขาคณิต, คำนวณโดย (minimum + maximum) / 2. คืนค่า (0, 0, 0) เมื่อ null. |
size | {x: number, y: number, z: number} (อ่านอย่างเดียว) | ขนาดของกล่อง: maximum - minimum ต่อแกน. |
extent | BoundingBoxExtent (อ่านอย่างเดียว) | ครึ่งขนาดตามแต่ละแกน แต่ละฟิลด์คือ Math.abs(size / 2). |
Properties
merge(point)
ขยายกล่องขอบเขตเพื่อรวมจุดหนึ่ง รับค่าเป็น {x, y, z} อ็อบเจ็กต์, a Vector3, อาเรย์ของ 3 ตัวเลข, หรือสามค่าแยกกัน (x, y, z) อาร์กิวเมนต์.
merge(point: Vector3 | {x: number, y: number, z: number}): void
merge(x: number, y: number, z: number): voidProperties
import { BoundingBox, Vector3 } from '@aspose/3d/utilities';
const bb = new BoundingBox();
bb.merge(new Vector3(2, 3, 4));
bb.merge(-1, 0, 0);
console.log(`Min X: ${bb.minimum.x}`); // Min X: -1
console.log(`Max Y: ${bb.maximum.y}`); // Max Y: 3
contains(arg)
Properties true หากจุดหรือกล่องขอบเขตที่กำหนดอยู่ภายในกล่องนี้อย่างเต็มที่ รับค่าเป็น {x, y, z} อ็อบเจ็กต์จุด, a Vector3, หรืออีกหนึ่ง BoundingBox.
contains(arg: Vector3 | {x: number, y: number, z: number} | BoundingBox): booleanProperties
import { BoundingBox, Vector3 } from '@aspose/3d/utilities';
const bb = new BoundingBox(-1, -1, -1, 1, 1, 1);
console.log(bb.contains(new Vector3(0, 0, 0))); // true
console.log(bb.contains(new Vector3(2, 0, 0))); // false
overlapsWith(box)
Properties true หากกล่องขอบเขตนี้ทับซ้อนกับอีกกล่องหนึ่ง BoundingBox (การสัมผัสขอบถือเป็นการทับซ้อน).
overlapsWith(box: BoundingBox): booleanscale()
คืนค่าพิกัดสัมบูรณ์สูงสุดจากทุกมุม แสดงถึงสเกลหลักของกล่องขอบเขต คืนค่า 0 เมื่อกล่องเป็นค่า null.
scale(): numberBoundingBoxExtent
BoundingBoxExtent เป็นคลาสคู่ที่ส่งกลับโดย BoundingBox.extent. มันเก็บครึ่งขนาดตามแต่ละแกน.
| Properties | Properties | Properties |
|---|---|---|
extentX | number | ครึ่งความกว้างตามแกน X. |
extentY | number | ครึ่งความสูงตามแกน Y. |
extentZ | number | ครึ่งความลึกตามแกน Z. |