pub struct Cartesian2D {
pub x: f64,
pub y: f64,
}Expand description
2D Cartesian coordinates (x, y).
Represents a point in the 2D Cartesian plane with x and y coordinates. Provides conversions to polar coordinates, complex numbers, and nalgebra vectors.
§Mathematical Representation
A point P in 2D Cartesian coordinates is represented as:
P = (x, y)§Examples
use thales::transforms::Cartesian2D;
// Create a point at (3, 4)
let point = Cartesian2D::new(3.0, 4.0);
assert_eq!(point.x, 3.0);
assert_eq!(point.y, 4.0);
// Calculate distance from origin
let magnitude = point.magnitude();
assert!((magnitude - 5.0).abs() < 1e-10);Fields§
§x: f64x-coordinate (horizontal axis)
y: f64y-coordinate (vertical axis)
Implementations§
Source§impl Cartesian2D
impl Cartesian2D
Sourcepub fn new(x: f64, y: f64) -> Self
pub fn new(x: f64, y: f64) -> Self
Create new 2D Cartesian coordinates.
§Examples
use thales::transforms::Cartesian2D;
let point = Cartesian2D::new(3.0, 4.0);
assert_eq!(point.x, 3.0);
assert_eq!(point.y, 4.0);Sourcepub fn to_polar(&self) -> Polar
pub fn to_polar(&self) -> Polar
Convert to polar coordinates.
Converts Cartesian coordinates (x, y) to polar coordinates (r, θ) using:
r = √(x² + y²)
θ = atan2(y, x)The angle θ is in radians, measured counterclockwise from the positive x-axis, and ranges from -π to π.
§Examples
use thales::transforms::Cartesian2D;
use std::f64::consts::PI;
// Point at (1, 1) should be at 45 degrees (π/4 radians)
let point = Cartesian2D::new(1.0, 1.0);
let polar = point.to_polar();
assert!((polar.r - std::f64::consts::SQRT_2).abs() < 1e-10);
assert!((polar.theta - PI / 4.0).abs() < 1e-10);
// Point on negative x-axis
let point = Cartesian2D::new(-2.0, 0.0);
let polar = point.to_polar();
assert!((polar.r - 2.0).abs() < 1e-10);
assert!((polar.theta - PI).abs() < 1e-10);Sourcepub fn to_complex(&self) -> Complex64
pub fn to_complex(&self) -> Complex64
Convert to complex number.
Represents the Cartesian point (x, y) as the complex number x + yi.
§Examples
use thales::transforms::Cartesian2D;
let point = Cartesian2D::new(3.0, 4.0);
let complex = point.to_complex();
assert_eq!(complex.re, 3.0);
assert_eq!(complex.im, 4.0);Sourcepub fn to_vector(&self) -> Vector2<f64>
pub fn to_vector(&self) -> Vector2<f64>
Convert to nalgebra vector.
Returns a 2D column vector [x, y]ᵀ for use with nalgebra linear algebra operations.
§Examples
use thales::transforms::Cartesian2D;
let point = Cartesian2D::new(3.0, 4.0);
let vec = point.to_vector();
assert_eq!(vec[0], 3.0);
assert_eq!(vec[1], 4.0);Sourcepub fn magnitude(&self) -> f64
pub fn magnitude(&self) -> f64
Distance from origin.
Calculates the Euclidean distance from the origin (0, 0) to the point (x, y):
|P| = √(x² + y²)This is equivalent to the radius r in polar coordinates.
§Examples
use thales::transforms::Cartesian2D;
// 3-4-5 right triangle
let point = Cartesian2D::new(3.0, 4.0);
assert!((point.magnitude() - 5.0).abs() < 1e-10);
// Point at origin
let origin = Cartesian2D::new(0.0, 0.0);
assert_eq!(origin.magnitude(), 0.0);Trait Implementations§
Source§impl Clone for Cartesian2D
impl Clone for Cartesian2D
Source§fn clone(&self) -> Cartesian2D
fn clone(&self) -> Cartesian2D
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Cartesian2D
impl Debug for Cartesian2D
Source§impl PartialEq for Cartesian2D
impl PartialEq for Cartesian2D
impl Copy for Cartesian2D
impl StructuralPartialEq for Cartesian2D
Auto Trait Implementations§
impl Freeze for Cartesian2D
impl RefUnwindSafe for Cartesian2D
impl Send for Cartesian2D
impl Sync for Cartesian2D
impl Unpin for Cartesian2D
impl UnwindSafe for Cartesian2D
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.