Skip to main content

Cartesian2D

Struct Cartesian2D 

Source
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: f64

x-coordinate (horizontal axis)

§y: f64

y-coordinate (vertical axis)

Implementations§

Source§

impl Cartesian2D

Source

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);
Source

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);
Source

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);
Source

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);
Source

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

Source§

fn clone(&self) -> Cartesian2D

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Cartesian2D

Source§

impl Debug for Cartesian2D

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Cartesian2D

Source§

fn eq(&self, other: &Cartesian2D) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Cartesian2D

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.