Expand description
A 3-dimensional plane primitive.
Represented by a normal and the signed distance from the origin to the plane.
This representation can specify any possible plane in 3D space using 4 parameters (disregarding floating point precision). There are duplicate representations caused by negating both parameters, but that’s fine - you could view it as an oriented plane.
A point point
is on the plane when plane.normal.dot(point) + plane.d = 0
.
Fields
normal: Vec3
Normal vector
d: f32
Distance
Implementations
sourceimpl Plane3
impl Plane3
sourcepub fn from_normal_dist(normal: Vec3, d: f32) -> Plane3
pub fn from_normal_dist(normal: Vec3, d: f32) -> Plane3
From the plane normal and a distance d
so that for all points on the plane:
normal.dot(point) + d = 0
.
sourcepub fn from_normal_point(normal: Vec3, point: Vec3) -> Plane3
pub fn from_normal_point(normal: Vec3, point: Vec3) -> Plane3
From the plane normal and a point on the plane.
sourcepub fn normalized(&self) -> Plane3
pub fn normalized(&self) -> Plane3
Get normalized plane
sourcepub fn distance(&self, p: Vec3) -> f32
pub fn distance(&self, p: Vec3) -> f32
Computes the distance between the plane and the point p. The returned distance is only correct if the plane is normalized or the distance is zero.
sourcepub fn intersect_ray(&self, origin: Vec3, dir: Vec3) -> (bool, f32)
pub fn intersect_ray(&self, origin: Vec3, dir: Vec3) -> (bool, f32)
The bool is whether the plane was hit or not.
If false, the ray was either perpendicular to the plane, or the ray shot away from the plane.
The returned f32 is the t value so you can easily compute the intersection point through “origin + dir * t”.
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Plane3
impl<'de> Deserialize<'de> for Plane3
sourcefn deserialize<__D>(
__deserializer: __D
) -> Result<Plane3, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Plane3, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl PartialEq<Plane3> for Plane3
impl PartialEq<Plane3> for Plane3
sourceimpl<'a_, C_> Readable<'a_, C_> for Plane3 where
C_: Context,
impl<'a_, C_> Readable<'a_, C_> for Plane3 where
C_: Context,
fn read_from<R_>(_reader_: &mut R_) -> Result<Plane3, <C_ as Context>::Error> where
R_: Reader<'a_, C_>,
fn minimum_bytes_needed() -> usize
fn read_from_buffer_with_ctx(
context: C,
buffer: &'a [u8]
) -> Result<Self, <C as Context>::Error>
fn read_with_length_from_buffer_with_ctx(
context: C,
buffer: &'a [u8]
) -> (Result<Self, <C as Context>::Error>, usize)
fn read_from_buffer_copying_data_with_ctx(
context: C,
buffer: &[u8]
) -> Result<Self, <C as Context>::Error>
fn read_with_length_from_buffer_copying_data_with_ctx(
context: C,
buffer: &[u8]
) -> (Result<Self, <C as Context>::Error>, usize)
fn read_with_length_from_buffer_copying_data_with_ctx_mut(
context: &mut C,
buffer: &[u8]
) -> (Result<Self, <C as Context>::Error>, usize)
fn read_from_stream_unbuffered_with_ctx<S>(
context: C,
stream: S
) -> Result<Self, <C as Context>::Error> where
S: Read,
fn read_from_stream_buffered_with_ctx<S>(
context: C,
stream: S
) -> Result<Self, <C as Context>::Error> where
S: Read,
fn read_from_file_with_ctx(
context: C,
path: impl AsRef<Path>
) -> Result<Self, <C as Context>::Error>
sourceimpl Serialize for Plane3
impl Serialize for Plane3
sourcefn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
sourceimpl<C_> Writable<C_> for Plane3 where
C_: Context,
impl<C_> Writable<C_> for Plane3 where
C_: Context,
fn write_to<T_>(&self, _writer_: &mut T_) -> Result<(), <C_ as Context>::Error> where
T_: Writer<C_> + ?Sized,
fn write_to_buffer_with_ctx(
&self,
context: C,
buffer: &mut [u8]
) -> Result<(), <C as Context>::Error>
fn write_to_buffer_with_ctx_mut(
&self,
context: &mut C,
buffer: &mut [u8]
) -> Result<(), <C as Context>::Error>
fn write_to_vec_with_ctx(
&self,
context: C
) -> Result<Vec<u8, Global>, <C as Context>::Error>
fn write_to_vec_with_ctx_mut(
&self,
context: &mut C
) -> Result<Vec<u8, Global>, <C as Context>::Error>
fn write_to_stream_with_ctx<S>(
&self,
context: C,
stream: S
) -> Result<(), <C as Context>::Error> where
S: Write,
fn write_to_file_with_ctx(
&self,
context: C,
path: impl AsRef<Path>
) -> Result<(), <C as Context>::Error>
fn bytes_needed(&self) -> Result<usize, <C as Context>::Error>
impl Copy for Plane3
impl StructuralPartialEq for Plane3
Auto Trait Implementations
impl RefUnwindSafe for Plane3
impl Send for Plane3
impl Sync for Plane3
impl Unpin for Plane3
impl UnwindSafe for Plane3
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more