Struct gdnative::core_types::Plane
source · [−]Expand description
3D plane in Hessian form: a*b + b*y + c*z + d = 0
Note: almost all methods on Plane
require that the normal
vector have
unit length and will panic if this invariant is violated. This is not separately
annotated for each method.
Fields
normal: Vector3
Normal vector, perpendicular to the plane.
Most Plane
methods expect this vector to be normalized and may panic if this is not the case.
d: f32
Distance from the coordinate system origin (in the direction of normal
).
This value is typically non-negative. It can however be negative, which behaves as if normal
changed direction.
Implementations
sourceimpl Plane
impl Plane
sourcepub fn new(normal: Vector3, d: f32) -> Plane
pub fn new(normal: Vector3, d: f32) -> Plane
Creates a new Plane
from the normal
and the distance from the origin d
.
Panics
In contrast to construction via Plane { normal, d }
, this verifies that normal
has unit length, and will
panic if this is not the case.
sourcepub fn from_coordinates(a: f32, b: f32, c: f32, d: f32) -> Plane
pub fn from_coordinates(a: f32, b: f32, c: f32, d: f32) -> Plane
Creates a new Plane
from normal and origin distance.
a
, b
, c
are used for the normal
vector.
d
is the distance from the origin.
Panics
See Self::new()
.
sourcepub fn from_points(a: Vector3, b: Vector3, c: Vector3) -> Option<Plane>
pub fn from_points(a: Vector3, b: Vector3, c: Vector3) -> Option<Plane>
Creates a new Plane
from three Vector3
, given in clockwise order.
If all three points are collinear, returns None
.
sourcepub fn center(self) -> Vector3
pub fn center(self) -> Vector3
Returns the point on the Plane
, which is closest to the origin.
This is equivalent to self.project(Vector3::ZERO)
.
sourcepub fn project(self, point: Vector3) -> Vector3
pub fn project(self, point: Vector3) -> Vector3
Returns the orthogonal projection of point
onto a point in the Plane
.
The projection is a point, which lies on the plane and is closest to point
.
sourcepub fn distance_to(self, point: Vector3) -> f32
pub fn distance_to(self, point: Vector3) -> f32
Returns the signed distance from the Plane
to point
.
This value is negative, if self.is_point_over(point)
is false.
sourcepub fn contains_point(self, point: Vector3) -> bool
pub fn contains_point(self, point: Vector3) -> bool
Returns true
if point
is inside the Plane
.
Uses a default epsilon for the boundary check. Use Self::contains_point_eps()
for more control.
sourcepub fn contains_point_eps(self, point: Vector3, epsilon: f32) -> bool
pub fn contains_point_eps(self, point: Vector3, epsilon: f32) -> bool
Returns true
if point
is inside the Plane
.
epsilon
specifies the minimum distance, at and below which a point is considered inside the Plane
.
sourcepub fn intersect_3(self, b: Plane, c: Plane) -> Option<Vector3>
pub fn intersect_3(self, b: Plane, c: Plane) -> Option<Vector3>
Returns the intersection point of the three planes self
, b
and c
.
Returns None
if the planes don’t intersect.
sourcepub fn intersect_ray(self, from: Vector3, dir: Vector3) -> Option<Vector3>
pub fn intersect_ray(self, from: Vector3, dir: Vector3) -> Option<Vector3>
Returns the intersection point of a ray consisting of the position from
and the direction vector dir
with this plane.
Returns None
if the ray doesn’t intersect.
sourcepub fn intersect_segment(self, begin: Vector3, end: Vector3) -> Option<Vector3>
pub fn intersect_segment(self, begin: Vector3, end: Vector3) -> Option<Vector3>
Returns the intersection point of a segment from begin
to end
with this Plane
.
Returns None
if the the segment doesn’t intersect.
sourcepub fn is_equal_approx(self, other: Plane) -> bool
pub fn is_equal_approx(self, other: Plane) -> bool
Returns true
if this Plane
and other
are approximately equal.
sourcepub fn is_point_over(self, point: Vector3) -> bool
pub fn is_point_over(self, point: Vector3) -> bool
Returns true
if point
is on the side of the Plane
, into which normal
points.
Points that lie exactly on the plane will be returned as false
.
sourcepub fn normalized(self) -> Plane
pub fn normalized(self) -> Plane
Returns the Plane
normalized.
Panics
If self.normal
is a zero vector. All other vectors are explicitly allowed.
Trait Implementations
sourceimpl CoerceFromVariant for Plane
impl CoerceFromVariant for Plane
fn coerce_from_variant(v: &Variant) -> Plane
sourceimpl<'de> Deserialize<'de> for Plane
impl<'de> Deserialize<'de> for Plane
sourcefn deserialize<__D>(
__deserializer: __D
) -> Result<Plane, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Plane, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
sourceimpl Export for Plane
impl Export for Plane
sourcefn export_info(_hint: Option<<Plane as Export>::Hint>) -> ExportInfo
fn export_info(_hint: Option<<Plane as Export>::Hint>) -> ExportInfo
ExportInfo
given an optional typed hint.