Up to date

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

Plane

使用黑塞范式的平面。

描述

代表归一化的平面方程。normal 是平面的法线(归一化的 a、b、c),而 d 是原点到平面的距离(沿“法线”方向)。平面的“上方”是平面朝向法线方向的一面。

教程

属性

float

d

0.0

Vector3

normal

Vector3(0, 0, 0)

float

x

0.0

float

y

0.0

float

z

0.0

构造函数

Plane

Plane ( )

Plane

Plane ( Plane from )

Plane

Plane ( float a, float b, float c, float d )

Plane

Plane ( Vector3 normal )

Plane

Plane ( Vector3 normal, float d )

Plane

Plane ( Vector3 normal, Vector3 point )

Plane

Plane ( Vector3 point1, Vector3 point2, Vector3 point3 )

方法

float

distance_to ( Vector3 point ) const

Vector3

get_center ( ) const

bool

has_point ( Vector3 point, float tolerance=1e-05 ) const

Variant

intersect_3 ( Plane b, Plane c ) const

Variant

intersects_ray ( Vector3 from, Vector3 dir ) const

Variant

intersects_segment ( Vector3 from, Vector3 to ) const

bool

is_equal_approx ( Plane to_plane ) const

bool

is_finite ( ) const

bool

is_point_over ( Vector3 point ) const

Plane

normalized ( ) const

Vector3

project ( Vector3 point ) const

操作符

bool

operator != ( Plane right )

Plane

operator * ( Transform3D right )

bool

operator == ( Plane right )

Plane

operator unary+ ( )

Plane

operator unary- ( )


常量

PLANE_YZ = Plane(1, 0, 0, 0)

在 Y 轴和 Z 轴上延伸的平面(法向量指向 +X)。

PLANE_XZ = Plane(0, 1, 0, 0)

在 X 轴和 Z 轴上延伸的平面(法向量朝向 +Y)。

PLANE_XY = Plane(0, 0, 1, 0)

在 X 轴和 Y 轴上延伸的平面(法向量朝向 +Z)。


属性说明

float d = 0.0

从原点到平面的距离,按照 normal 取值(根据其方向和长度)。原点与平面的实际绝对距离可以通过 abs(d) / normal.length() 计算(如果 normal 长度为零,则该 Plane 表示的不是有效平面)。

在平面 ax + by + cz = d 的标量方程中,这是 d,而 (a, b, c) 坐标由 normal 属性表示。


Vector3 normal = Vector3(0, 0, 0)

该平面的法线,通常为单位向量。不应该为零向量,因为 normal 为零的 Plane 代表的不是有效平面。

在平面 ax + by + cz = d 的标量方程中,这是向量 (a, b, c),其中 dd 属性。


float x = 0.0

平面法向量 normal 的 X 分量。


float y = 0.0

平面法向量 normal 的 Y 分量。


float z = 0.0

平面法向量 normal 的 Z 分量。


构造函数说明

Plane Plane ( )

构造默认初始化的 Plane,所有分量都设置为 0


Plane Plane ( Plane from )

构造给定 Plane 的副本。


Plane Plane ( float a, float b, float c, float d )

根据四个参数创建一个平面。产生的平面的 normal 的三个分量是 ab、和 c,且该平面与原点的距离为 d


Plane Plane ( Vector3 normal )

根据法向量创建一个平面。该平面将与原点相交。

该平面的 normal 必须是一个单位向量。


Plane Plane ( Vector3 normal, float d )

根据法向量和平面与原点的距离创建一个平面。

平面的 normal 必须是一个单位向量。


Plane Plane ( Vector3 normal, Vector3 point )

从法向量和平面上的一个点创建一个平面。

平面的 normal 必须是一个单位向量。


Plane Plane ( Vector3 point1, Vector3 point2, Vector3 point3 )

根据顺时针顺序给出的三个点创建一个平面。


方法说明

float distance_to ( Vector3 point ) const

返回从该平面到位置 point 的最短距离。如果该点在平面上方,则距离将为正。如果在下方,则距离将为负。


Vector3 get_center ( ) const

返回平面的中心。


bool has_point ( Vector3 point, float tolerance=1e-05 ) const

如果 point 在该平面内,则返回 true。比较将使用一个自定义的最小 tolerance 阈值。


Variant intersect_3 ( Plane b, Plane c ) const

返回 bc、该平面这三个平面的交点。如果没有找到交点,则返回 null


Variant intersects_ray ( Vector3 from, Vector3 dir ) const

返回由位置 from 和方向法线 dir 组成的射线与该平面的交点。如果没有找到交点,则返回 null


Variant intersects_segment ( Vector3 from, Vector3 to ) const

返回从位置 from 到位置 to 的线段与该平面的交点。如果没有找到交点,则返回 null


bool is_equal_approx ( Plane to_plane ) const

如果该平面和 to_plane 近似相等,则返回 true,判断近似相等的方法是通过在每个分量上运行 @GlobalScope.is_equal_approx


bool is_finite ( ) const

如果该平面是有限的,则返回 true,判断方法是在每个分量上调用 @GlobalScope.is_finite


bool is_point_over ( Vector3 point ) const

如果 point 位于平面上方,则返回 true


Plane normalized ( ) const

返回该平面归一化 normal 后的副本(法线成为单位向量)。如果 normal 无法归一化(长度为零),则返回 Plane(0, 0, 0, 0)


Vector3 project ( Vector3 point ) const

返回 point 在该平面中的正交投影。


操作符说明

bool operator != ( Plane right )

如果平面不相等,则返回 true

注意:由于浮点数精度误差,请考虑改用 is_equal_approx,会更可靠。


Plane operator * ( Transform3D right )

Plane 逆向变换(乘以)给定的 Transform3D 变换矩阵。

plane * transform 相当于 transform.affine_inverse() * plane。请参阅 Transform3D.affine_inverse


bool operator == ( Plane right )

如果平面完全相等,则返回 true

注意:由于浮点数精度误差,请考虑改用 is_equal_approx,会更可靠。


Plane operator unary+ ( )

返回与 + 不存在时相同的值。单目 + 没有作用,但有时可以使你的代码更具可读性。


Plane operator unary- ( )

返回该 Plane 的负值。和写 Plane(-p.normal, -p.d) 相同。该操作翻转了法线向量的方向,也翻转了距离值,得到的 Plane 位于同一个位置,但是朝向相反的方向。