pub struct Triangle2<S> { /* private fields */ }Expand description
A 2-simplex or triangle in 2D space
Creation methods should fail with a debug assertion if the points are colinear.
Implementations§
Source§impl<S: OrderedField> Triangle<S>
impl<S: OrderedField> Triangle<S>
Sourcepub fn new(a: Point2<S>, b: Point2<S>, c: Point2<S>) -> Option<Self>where
S: AbsDiffEq<Epsilon = S>,
pub fn new(a: Point2<S>, b: Point2<S>, c: Point2<S>) -> Option<Self>where
S: AbsDiffEq<Epsilon = S>,
Returns None if the points are colinear:
assert!(Triangle::new (
[-1.0, -1.0].into(),
[ 0.0, 0.0].into(),
[ 1.0, 1.0].into()
).is_none());Sourcepub fn noisy(a: Point2<S>, b: Point2<S>, c: Point2<S>) -> Selfwhere
S: AbsDiffEq<Epsilon = S>,
pub fn noisy(a: Point2<S>, b: Point2<S>, c: Point2<S>) -> Selfwhere
S: AbsDiffEq<Epsilon = S>,
Panics if the points are colinear:
let s = Triangle::noisy (
[-1.0, -1.0].into(),
[ 0.0, 0.0].into(),
[ 1.0, 1.0].into());Sourcepub fn unchecked(a: Point2<S>, b: Point2<S>, c: Point2<S>) -> Selfwhere
S: AbsDiffEq<Epsilon = S>,
pub fn unchecked(a: Point2<S>, b: Point2<S>, c: Point2<S>) -> Selfwhere
S: AbsDiffEq<Epsilon = S>,
Debug panic if the points are colinear:
let s = Triangle::unchecked (
[-1.0, -1.0].into(),
[ 0.0, 0.0].into(),
[ 1.0, 1.0].into());pub fn from_array([a, b, c]: [Point2<S>; 3]) -> Option<Self>where
S: AbsDiffEq<Epsilon = S>,
pub const fn point_a(self) -> Point2<S>
pub const fn point_b(self) -> Point2<S>
pub const fn point_c(self) -> Point2<S>
pub const fn points(self) -> [Point2<S>; 3]
Sourcepub fn point(self, s: Normalized<S>, t: Normalized<S>) -> Option<Point2<S>>
pub fn point(self, s: Normalized<S>, t: Normalized<S>) -> Option<Point2<S>>
Return a parameterized point on the triangle.
Returns None if s + t > 1.0.
pub const fn edge_ab(self) -> Segment2<S>
pub const fn edge_bc(self) -> Segment2<S>
pub const fn edge_ca(self) -> Segment2<S>
Sourcepub const fn rewind(self) -> Self
pub const fn rewind(self) -> Self
Change triangle winding by swapping points B and C.
Equivalent to triangle.acb().
Sourcepub fn perpendicular_ab(self) -> NonZero2<S>
pub fn perpendicular_ab(self) -> NonZero2<S>
Returns perpendicular vector to edge AB.
let s = Triangle::unchecked (
[0.0, 0.0].into(),
[0.0, 2.0].into(),
[2.0, 1.0].into());
assert_eq!(*s.perpendicular_ab(), [-2.0, 0.0].into());
let s = Triangle::unchecked (
[ 0.0, 0.0].into(),
[ 0.0, 2.0].into(),
[-2.0, 1.0].into());
assert_eq!(*s.perpendicular_ab(), [2.0, 0.0].into());Sourcepub fn perpendicular_bc(self) -> NonZero2<S>
pub fn perpendicular_bc(self) -> NonZero2<S>
Returns perpendicular vector to edge BC.
let s = Triangle::unchecked (
[2.0, 1.0].into(),
[0.0, 0.0].into(),
[0.0, 2.0].into());
assert_eq!(*s.perpendicular_bc(), [-2.0, 0.0].into());
let s = Triangle::unchecked (
[-2.0, 1.0].into(),
[ 0.0, 0.0].into(),
[ 0.0, 2.0].into());
assert_eq!(*s.perpendicular_bc(), [2.0, 0.0].into());Sourcepub fn perpendicular_ca(self) -> NonZero2<S>
pub fn perpendicular_ca(self) -> NonZero2<S>
Returns perpendicular vector to edge CA.
let s = Triangle::unchecked (
[0.0, 2.0].into(),
[2.0, 1.0].into(),
[0.0, 0.0].into());
assert_eq!(*s.perpendicular_ca(), [-2.0, 0.0].into());
let s = Triangle::unchecked (
[ 0.0, 2.0].into(),
[-2.0, 1.0].into(),
[ 0.0, 0.0].into());
assert_eq!(*s.perpendicular_ca(), [2.0, 0.0].into());pub fn area(self) -> Positive<S>where
S: Real,
Sourcepub fn centroid(self) -> Point2<S>
pub fn centroid(self) -> Point2<S>
Barycentric coordinate $1/3 : 1/3 : 1/3$ corresponds to the center of mass (barycenter) of a uniform triangular lamina
Sourcepub fn incenter(self) -> Point2<S>
pub fn incenter(self) -> Point2<S>
Trilinear coordinate $1 : 1 : 1$ corresponds to center of inscribed circle
pub fn barycentric(self, coords: Vector3<S>) -> Point2<S>
pub fn trilinear(self, coords: Vector3<S>) -> Point2<S>
pub fn affine_plane(self) -> Plane2<S>
pub fn nearest_point(self, point: Point2<S>) -> TrianglePoint<S>
Trait Implementations§
impl<S: Copy> Copy for Triangle<S>
Source§impl<S: Field + Sqrt> Default for Triangle<S>
impl<S: Field + Sqrt> Default for Triangle<S>
Source§fn default() -> Self
fn default() -> Self
A default triangle is arbitrarily chosen to be the equilateral triangle with point at 1.0 on the Y axis:
use std::f64::consts::FRAC_1_SQRT_2;
let s = Triangle::default();
let t = Triangle::noisy (
[ 0.0, 1.0].into(),
[-FRAC_1_SQRT_2, -FRAC_1_SQRT_2].into(),
[ FRAC_1_SQRT_2, -FRAC_1_SQRT_2].into()
);
approx::assert_relative_eq!(s.point_a(), t.point_a());
approx::assert_relative_eq!(s.point_b(), t.point_b());
approx::assert_relative_eq!(s.point_c(), t.point_c());impl<S: Eq> Eq for Triangle<S>
impl<S: PartialEq> StructuralPartialEq for Triangle<S>
Auto Trait Implementations§
impl<S> Freeze for Triangle<S>where
S: Freeze,
impl<S> RefUnwindSafe for Triangle<S>where
S: RefUnwindSafe,
impl<S> Send for Triangle<S>where
S: Send,
impl<S> Sync for Triangle<S>where
S: Sync,
impl<S> Unpin for Triangle<S>where
S: Unpin,
impl<S> UnsafeUnpin for Triangle<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for Triangle<S>where
S: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more