Up to date

This page is up to date for Godot `4.2`. If you still find outdated information, please open an issue.

# AABB¶

3D 轴对齐边界框。

## 描述¶

AABB 内置 Variant 类型表示 3D 空间中的轴对齐边界框。它由其 positionsize 定义，皆为 Vector3 类型。它经常被用于快速重叠测试（参见 intersects）。虽然 AABB 本身是轴对齐的，但它可以与 Transform3D 组合来表示旋转或倾斜的边界框。

## 属性¶

 Vector3 end `Vector3(0, 0, 0)` Vector3 position `Vector3(0, 0, 0)` Vector3 size `Vector3(0, 0, 0)`

## 构造函数¶

 AABB AABB ( ) AABB AABB ( AABB from ) AABB AABB ( Vector3 position, Vector3 size )

## 方法¶

 AABB abs ( ) const bool encloses ( AABB with ) const AABB expand ( Vector3 to_point ) const Vector3 get_center ( ) const Vector3 get_endpoint ( int idx ) const Vector3 get_longest_axis ( ) const int get_longest_axis_index ( ) const float get_longest_axis_size ( ) const Vector3 get_shortest_axis ( ) const int get_shortest_axis_index ( ) const float get_shortest_axis_size ( ) const Vector3 get_support ( Vector3 dir ) const float get_volume ( ) const AABB grow ( float by ) const bool has_point ( Vector3 point ) const bool has_surface ( ) const bool has_volume ( ) const AABB intersection ( AABB with ) const bool intersects ( AABB with ) const bool intersects_plane ( Plane plane ) const Variant intersects_ray ( Vector3 from, Vector3 dir ) const Variant intersects_segment ( Vector3 from, Vector3 to ) const bool is_equal_approx ( AABB aabb ) const bool is_finite ( ) const AABB merge ( AABB with ) const

## 操作符¶

 bool operator != ( AABB right ) AABB operator * ( Transform3D right ) bool operator == ( AABB right )

## 属性说明¶

Vector3 end = `Vector3(0, 0, 0)`

Vector3 position = `Vector3(0, 0, 0)`

Vector3 size = `Vector3(0, 0, 0)`

## 构造函数说明¶

AABB AABB ( )

AABB AABB ( AABB from )

AABB AABB ( Vector3 position, Vector3 size )

## 方法说明¶

AABB abs ( ) const

```var box = AABB(Vector3(5, 0, 5), Vector3(-20, -10, -5))
var absolute = box.abs()
print(absolute.position) # 打印 (-15, -10, 0)
print(absolute.size)     # 打印 (20, 10, 5)
```

bool encloses ( AABB with ) const

```var a = AABB(Vector3(0, 0, 0), Vector3(4, 4, 4))
var b = AABB(Vector3(1, 1, 1), Vector3(3, 3, 3))
var c = AABB(Vector3(2, 2, 2), Vector3(8, 8, 8))

print(a.encloses(a)) # 打印 true
print(a.encloses(b)) # 打印 true
print(a.encloses(c)) # 打印 false
```

AABB expand ( Vector3 to_point ) const

```var box = AABB(Vector3(0, 0, 0), Vector3(5, 2, 5))

box = box.expand(Vector3(10, 0, 0))
print(box.position) # 打印 (0, 0, 0)
print(box.size)     # 打印 (10, 2, 5)

box = box.expand(Vector3(-5, 0, 5))
print(box.position) # 打印 (-5, 0, 0)
print(box.size)     # 打印 (15, 2, 5)
```

Vector3 get_center ( ) const

Vector3 get_endpoint ( int idx ) const

Vector3 get_longest_axis ( ) const

```var box = AABB(Vector3(0, 0, 0), Vector3(2, 4, 8))

print(box.get_longest_axis())       # 打印 (0, 0, 1)
print(box.get_longest_axis_index()) # 打印 2
print(box.get_longest_axis_size())  # 打印 8
```

int get_longest_axis_index ( ) const

float get_longest_axis_size ( ) const

Vector3 get_shortest_axis ( ) const

```var box = AABB(Vector3(0, 0, 0), Vector3(2, 4, 8))

print(box.get_shortest_axis())       # 打印 (1, 0, 0)
print(box.get_shortest_axis_index()) # 打印 0
print(box.get_shortest_axis_size())  # 打印 2
```

int get_shortest_axis_index ( ) const

float get_shortest_axis_size ( ) const

Vector3 get_support ( Vector3 dir ) const

float get_volume ( ) const

AABB grow ( float by ) const

```var a = AABB(Vector3(4, 4, 4), Vector3(8, 8, 8)).grow(4)
print(a.position) # 打印 (0, 0, 0)
print(a.size)     # 打印 (16, 16, 16)

var b = AABB(Vector3(0, 0, 0), Vector3(8, 4, 2)).grow(2)
print(b.position) # 打印 (-2, -2, -2)
print(b.size)     # 打印 (12, 8, 6)
```

bool has_point ( Vector3 point ) const

bool has_surface ( ) const

bool has_volume ( ) const

AABB intersection ( AABB with ) const

```var box1 = AABB(Vector3(0, 0, 0), Vector3(5, 2, 8))
var box2 = AABB(Vector3(2, 0, 2), Vector3(8, 4, 4))

var intersection = box1.intersection(box2)
print(intersection.position) # 打印 (2, 0, 2)
print(intersection.size)     # 打印 (3, 2, 4)
```

bool intersects ( AABB with ) const

bool intersects_plane ( Plane plane ) const

Variant intersects_ray ( Vector3 from, Vector3 dir ) const

Variant intersects_segment ( Vector3 from, Vector3 to ) const

bool is_equal_approx ( AABB aabb ) const

bool is_finite ( ) const

AABB merge ( AABB with ) const

## 操作符说明¶

bool operator != ( AABB right )

AABB operator * ( Transform3D right )

`aabb * transform` 相当于 `transform.inverse() * aabb`。见 Transform3D.inverse

bool operator == ( AABB right )