pub struct Point3D {
pub x: Decimal,
pub y: Decimal,
pub z: Decimal,
}Expand description
Represents a point in three-dimensional space with x, y and z coordinates.
§Overview
The Point3D struct defines a point in a 3D Cartesian coordinate system.
All coordinates (x, y, and z) are stored as Decimal values to provide high precision,
making it suitable for applications requiring accurate numerical calculations.
§Fields
- x: The x-coordinate of the point, represented as a
Decimal - y: The y-coordinate of the point, represented as a
Decimal - z: The z-coordinate of the point, represented as a
Decimal
§Examples
use rust_decimal_macros::dec;
use optionstratlib_math::surfaces::Point3D;
// Create a new 3D point
let point = Point3D {
x: dec!(1.5),
y: dec!(2.0),
z: dec!(-3.25),
};§Usage
Point3D is primarily used within the surface module to represent vertices
of 3D surfaces and for various geometric calculations. The high-precision Decimal
type ensures accuracy in scientific and engineering applications.
Fields§
§x: DecimalThe x-coordinate in the Cartesian system
y: DecimalThe y-coordinate in the Cartesian system
z: DecimalThe z-coordinate in the Cartesian system
Implementations§
Source§impl Point3D
impl Point3D
Sourcepub fn new<T: Into<Decimal>, U: Into<Decimal>, V: Into<Decimal>>(
x: T,
y: U,
z: V,
) -> Self
pub fn new<T: Into<Decimal>, U: Into<Decimal>, V: Into<Decimal>>( x: T, y: U, z: V, ) -> Self
Creates a new instance of Point3D using the specified coordinates.
§Parameters
x: The x-coordinate, which implementsInto<Decimal>y: The y-coordinate, which implementsInto<Decimal>z: The z-coordinate, which implementsInto<Decimal>
Sourcepub fn to_tuple<T: TryFrom<Decimal> + 'static, U: TryFrom<Decimal> + 'static, V: TryFrom<Decimal> + 'static>(
&self,
) -> Result<(T, U, V), SurfaceError>
pub fn to_tuple<T: TryFrom<Decimal> + 'static, U: TryFrom<Decimal> + 'static, V: TryFrom<Decimal> + 'static>( &self, ) -> Result<(T, U, V), SurfaceError>
Converts the Point3D to a tuple of three values.
§Type Parameters
T: Type for x-coordinateU: Type for y-coordinateV: Type for z-coordinate
§Errors
Returns SurfaceError::Point3DError in three situations:
- when one of the target types is
Positive-like (detected via theis_positive::<T>()/is_positive::<U>()/is_positive::<V>()checks) and the corresponding coordinate is less than or equal to zero. - when one of the
Decimalcoordinates cannot be converted into the target numeric type (e.g. out-of-range forf32, overflow foru32).
Sourcepub fn from_tuple<T: Into<Decimal>, U: Into<Decimal>, V: Into<Decimal>>(
x: T,
y: U,
z: V,
) -> Result<Self, SurfaceError>
pub fn from_tuple<T: Into<Decimal>, U: Into<Decimal>, V: Into<Decimal>>( x: T, y: U, z: V, ) -> Result<Self, SurfaceError>
Creates a Point3D from a tuple of three values.
§Errors
Currently infallible for the blanket Into<Decimal>
bounds; the Result signature is retained so future
implementations that can reject non-finite or out-of-range
inputs (e.g. via TryFrom<f64>) can surface
SurfaceError::Point3DError without a breaking change.
Sourcepub fn to_f64_tuple(&self) -> Result<(f64, f64, f64), SurfaceError>
pub fn to_f64_tuple(&self) -> Result<(f64, f64, f64), SurfaceError>
Converts the Point3D to a tuple of f64 values.
§Errors
Returns SurfaceError::Point3DError when any coordinate
cannot be represented as an f64 (typically a Decimal
magnitude that exceeds the f64 range).
Sourcepub fn from_f64_tuple(x: f64, y: f64, z: f64) -> Result<Self, SurfaceError>
pub fn from_f64_tuple(x: f64, y: f64, z: f64) -> Result<Self, SurfaceError>
Creates a Point3D from a tuple of f64 values.
§Errors
Returns SurfaceError::Point3DError when any of x,
y or z is NaN or infinite and therefore not
representable as a Decimal.
Sourcepub fn point2d(&self) -> Box<Point2D>
pub fn point2d(&self) -> Box<Point2D>
Converts this Point3D instance to a Point2D by projecting onto the XY plane.
§Overview
This method creates a new Point2D instance using only the x and y coordinates
of the current Point3D object, effectively projecting the 3D point onto the XY plane.
The z coordinate is discarded in this operation.
§Returns
A heap-allocated Point2D instance (Box<Point2D>) containing the x and y coordinates
from this Point3D object.
§Example
use rust_decimal_macros::dec;
use optionstratlib_math::surfaces::Point3D;
let point3d = Point3D { x: dec!(1.5), y: dec!(2.0), z: dec!(3.5) };
let point2d = point3d.point2d();
assert_eq!(point2d.x, dec!(1.5));
assert_eq!(point2d.y, dec!(2.0));§Use Cases
This method is useful when:
- Working with visualization that requires 2D projections of 3D points
- Analyzing specific planes within a 3D model
- Converting between coordinate systems from 3D to 2D
Trait Implementations§
Source§impl AxisOperations<Point3D, Point2D> for Surface
impl AxisOperations<Point3D, Point2D> for Surface
Source§fn contains_point(&self, x: &Point2D) -> bool
fn contains_point(&self, x: &Point2D) -> bool
Reports whether any point sits above the xy-coordinate x.
Answers on the (x, y) pair alone, so it says nothing about how many
heights are stacked there. On a surface honouring the
one-height-per-cell rule of Surface::new there is at most one.
Source§fn get_index_values(&self) -> Vec<Point2D>
fn get_index_values(&self) -> Vec<Point2D>
Returns the xy-coordinate of every point, in (x, y, z) order.
A surface holding several heights above one cell yields that cell once per height; the duplicates are visible here rather than dropped.
Source§fn get_values(&self, x: Point2D) -> Vec<&Decimal>
fn get_values(&self, x: Point2D) -> Vec<&Decimal>
Returns every z above the xy-coordinate x, in ascending order.
This is the multi-valued reader: unlike Self::get_point, it never
picks a survivor. A surface honouring the one-height-per-cell rule of
Surface::new returns at most one value; anything longer says the
surface is not a function of its xy-coordinate.
Source§fn get_point(&self, x: &Point2D) -> Option<&Point3D>
fn get_point(&self, x: &Point2D) -> Option<&Point3D>
Returns the point above the xy-coordinate x, if there is one.
Assumes the one-height-per-cell rule of Surface::new. If the
surface breaks it, this returns the first match in (x, y, z)
order, which is the lowest z of the stack, and the rest are
invisible to the caller. Use Self::get_values to see all of them.
Source§type Error = SurfaceError
type Error = SurfaceError
Source§impl BiLinearInterpolation<Point3D, Point2D> for Surface
impl BiLinearInterpolation<Point3D, Point2D> for Surface
Source§fn bilinear_interpolate(
&self,
xy: Point2D,
) -> Result<Point3D, InterpolationError>
fn bilinear_interpolate( &self, xy: Point2D, ) -> Result<Point3D, InterpolationError>
impl Copy for Point3D
Source§impl CubicInterpolation<Point3D, Point2D> for Surface
impl CubicInterpolation<Point3D, Point2D> for Surface
Source§fn cubic_interpolate(&self, xy: Point2D) -> Result<Point3D, InterpolationError>
fn cubic_interpolate(&self, xy: Point2D) -> Result<Point3D, InterpolationError>
x input value
using cubic interpolation. Read moreSource§impl<'de> Deserialize<'de> for Point3D
impl<'de> Deserialize<'de> for Point3D
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Point3D
Source§impl GeometricObject<Point3D, Point2D> for Surface
Implementation of the GeometricObject trait for the Surface struct.
impl GeometricObject<Point3D, Point2D> for Surface
Implementation of the GeometricObject trait for the Surface struct.
This implementation provides functionality to create and manipulate 3D surfaces using points in three-dimensional space. It supports construction from explicit point collections or through parametric functions.
§Type Parameters
- Uses
Point3Das the points that form the surface - Uses
Point2Das the parametric input for surface generation
§Methods
get_points(): Retrieves all points in the surfacefrom_vector(): Constructs a surface from a vector of pointsconstruct(): Creates a surface using different construction methods
§Error Handling
Uses SurfaceError for various error conditions, including:
- Empty point collections
- Invalid construction parameters
- Errors during parametric function evaluation
Source§fn get_points(&self) -> BTreeSet<&Point3D>
fn get_points(&self) -> BTreeSet<&Point3D>
Returns a borrowed reference to all points in the surface as an ordered set
§Returns
BTreeSet<&Point3D>- A sorted set containing references to all points that define the surface, maintaining the natural ordering of points
§Example
use optionstratlib_math::surfaces::{Surface, Point3D};
use std::collections::BTreeSet;
use rust_decimal_macros::dec;
use optionstratlib_math::geometrics::GeometricObject;
// Create a surface with some points
let mut surface = Surface {
points: BTreeSet::new(),
x_range: (dec!(0), dec!(10)),
y_range: (dec!(0), dec!(10)),
};
// Add points to the surface
surface.points.insert(Point3D { x: dec!(1.0), y: dec!(2.0), z: dec!(3.0) });
surface.points.insert(Point3D { x: dec!(4.0), y: dec!(5.0), z: dec!(6.0) });
// Get references to all points in the surface
let points = surface.get_points();
assert_eq!(points.len(), 2);Source§fn from_vector<T>(points: Vec<T>) -> Self
fn from_vector<T>(points: Vec<T>) -> Self
Creates a new Surface from a vector of points that can be converted into Point3D objects.
This method constructs a Surface by converting each point in the input vector to a Point3D and collecting them into an ordered set. It also calculates the x and y coordinate ranges of the points to define the surface’s boundaries.
§Type Parameters
T: A type that can be converted into Point3D via the Into trait and can be cloned.
§Parameters
points: A vector of objects that can be converted to Point3D.
§Returns
A new Surface instance containing the converted points and their coordinate ranges.
§Example
use optionstratlib_math::surfaces::{Surface, Point3D};
use optionstratlib_math::geometrics::GeometricObject;
use rust_decimal_macros::dec;
// Create points data
let points = vec![
Point3D { x: dec!(1.0), y: dec!(2.0), z: dec!(3.0) },
Point3D { x: dec!(4.0), y: dec!(5.0), z: dec!(6.0) }
];
// Create a surface from the points
let surface = Surface::from_vector(points);
// The surface will contain both points and have x_range and y_range calculated automatically
assert_eq!(surface.points.len(), 2);
assert_eq!(surface.x_range, (dec!(1.0), dec!(4.0)));
assert_eq!(surface.y_range, (dec!(2.0), dec!(5.0)));Source§fn construct<T>(method: T) -> Result<Self, Self::Error>
fn construct<T>(method: T) -> Result<Self, Self::Error>
Constructs a Surface from a given construction method.
This function creates a Surface object from either a set of 3D points or a parametric function.
§Parameters
method- A construction method that can be converted into aConstructionMethod<Point3D, Point2D, SurfaceError>
§Type Parameters
T- Type that can be converted into aConstructionMethod<Point3D, Point2D, SurfaceError>
§Returns
Result<Self, Self::Error>- Either a successfully constructed Surface or an error
§Errors
SurfaceError::Point3DError- If an empty points array is providedSurfaceError::ConstructionError- If invalid parameters are provided or the parametric function fails
§Examples
§Creating from existing points
use std::collections::BTreeSet;
use optionstratlib_math::geometrics::{ConstructionMethod, GeometricObject};
use optionstratlib_math::surfaces::{Point3D, Surface};
let points = BTreeSet::from_iter(vec![
Point3D::new(0, 0, 0),
Point3D::new(1, 0, 1),
Point3D::new(0, 1, 1),
]);
let surface = Surface::construct(ConstructionMethod::FromData { points })?;§Creating from a parametric function
use rust_decimal_macros::dec;
use optionstratlib_math::curves::Point2D;
use optionstratlib_math::error::SurfaceError;
use optionstratlib_math::geometrics::{ConstructionMethod, ConstructionParams, GeometricObject};
use optionstratlib_math::surfaces::{Point3D, Surface};
let params = ConstructionParams::D3 {
x_start: dec!(-1.0),
x_end: dec!(1.0),
y_start: dec!(-1.0),
y_end: dec!(1.0),
x_steps: 20,
y_steps: 20,
};
// Parametric function defining a paraboloid: z = x² + y²
let f = Box::new(|p: Point2D| -> Result<Point3D, SurfaceError> {
Ok(Point3D {
x: p.x,
y: p.y,
z: p.x * p.x + p.y * p.y,
})
});
let surface = Surface::construct(ConstructionMethod::Parametric { f, params })?;Source§type Error = SurfaceError
type Error = SurfaceError
Source§fn vector(&self) -> Vec<&Point>
fn vector(&self) -> Vec<&Point>
Vec containing references to the points that constitute the geometric object.
This method simply converts the BTreeSet from get_points into a Vec.Source§impl GeometricTransformations<Point3D> for Surface
impl GeometricTransformations<Point3D> for Surface
Source§type Error = SurfaceError
type Error = SurfaceError
Source§fn translate(&self, deltas: Vec<&Decimal>) -> Result<Self, Self::Error>
fn translate(&self, deltas: Vec<&Decimal>) -> Result<Self, Self::Error>
Source§fn scale(&self, factors: Vec<&Decimal>) -> Result<Self, Self::Error>
fn scale(&self, factors: Vec<&Decimal>) -> Result<Self, Self::Error>
Source§fn intersect_with(&self, other: &Self) -> Result<Vec<Point3D>, Self::Error>
fn intersect_with(&self, other: &Self) -> Result<Vec<Point3D>, Self::Error>
Source§fn derivative_at(&self, point: &Point3D) -> Result<Vec<Decimal>, Self::Error>
fn derivative_at(&self, point: &Point3D) -> Result<Vec<Decimal>, Self::Error>
Source§impl Interpolate<Point3D, Point2D> for Surface
Implementation of the Interpolate trait for the Surface type, enabling
interpolation from 3D surface points to 2D points.
impl Interpolate<Point3D, Point2D> for Surface
Implementation of the Interpolate trait for the Surface type, enabling
interpolation from 3D surface points to 2D points.
§Overview
This implementation allows a Surface object to perform various types of interpolation
(linear, bilinear, cubic, and spline) by projecting 3D points from the surface to 2D points.
§Functionality
By implementing the Interpolate trait, Surface gains the following capabilities:
- Interpolating between 3D surface points to produce 2D projections
- Finding bracket points for interpolation operations
- Supporting multiple interpolation algorithms through the trait’s methods
§Usage Example
use rust_decimal_macros::dec;
use optionstratlib_math::surfaces::{Surface, Point3D};
use optionstratlib_math::curves::Point2D;
use optionstratlib_math::geometrics::{Interpolate, InterpolationType};
let surface = Surface::new(Default::default());
// Interpolate a 2D point at a specific position using linear interpolation
let input_point = Point2D { x: dec!(1.5), y: dec!(2.0) };
let result = surface.interpolate(input_point, InterpolationType::Linear);§Related Traits
This implementation relies on the surface also implementing:
LinearInterpolation<Point3D, Point2D>BiLinearInterpolation<Point3D, Point2D>CubicInterpolation<Point3D, Point2D>SplineInterpolation<Point3D, Point2D>GeometricObject<Point3D, Point2D>
Source§fn interpolate(
&self,
x: Input,
interpolation_type: InterpolationType,
) -> Result<Point, InterpolationError>
fn interpolate( &self, x: Input, interpolation_type: InterpolationType, ) -> Result<Point, InterpolationError>
Source§fn find_bracket_points(
&self,
x: Input,
) -> Result<(usize, usize), InterpolationError>
fn find_bracket_points( &self, x: Input, ) -> Result<(usize, usize), InterpolationError>
Source§impl LinearInterpolation<Point3D, Point2D> for Surface
§Linear Interpolation for Surfaces
Implementation of the LinearInterpolation trait for Surface structures, enabling
interpolation from 2D points to 3D points using barycentric coordinates.
impl LinearInterpolation<Point3D, Point2D> for Surface
§Linear Interpolation for Surfaces
Implementation of the LinearInterpolation trait for Surface structures, enabling
interpolation from 2D points to 3D points using barycentric coordinates.
§Overview
This implementation allows calculating the height (z-coordinate) of any point within the surface’s x-y range by using linear interpolation based on the three nearest points in the surface. The method employs barycentric coordinate interpolation with triangulation of the nearest points.
§Algorithm
The interpolation process follows these steps:
- Validate that the input point is within the surface’s range
- Check for degenerate cases (all points at same location)
- Check for exact matches with existing points
- Find the three nearest points to the query point
- Calculate barycentric coordinates for the triangle formed by these points
- Interpolate the z-value using the barycentric weights
Source§fn linear_interpolate(&self, xy: Point2D) -> Result<Point3D, InterpolationError>
fn linear_interpolate(&self, xy: Point2D) -> Result<Point3D, InterpolationError>
§Parameters
xy- APoint2Drepresenting the x and y coordinates where interpolation is needed
§Returns
Result<Point3D, InterpolationError>- The interpolated 3D point if successful, or an appropriate error if interpolation cannot be performed
§Errors
Returns InterpolationError::Linear in the following cases:
- When the surface contains only coincident points forming a degenerate triangle
- When the query point is outside the surface’s x-y range
Source§impl MergeAxisInterpolate<Point3D, Point2D> for Surfacewhere
Self: Sized,
impl MergeAxisInterpolate<Point3D, Point2D> for Surfacewhere
Self: Sized,
Source§fn merge_axis_interpolate(
&self,
other: &Self,
interpolation: InterpolationType,
) -> Result<(Self, Self), Self::Error>
fn merge_axis_interpolate( &self, other: &Self, interpolation: InterpolationType, ) -> Result<(Self, Self), Self::Error>
Resamples both surfaces onto the shared xy-grid of their merged indices.
Each result holds one z per cell of that grid, so it is a function
of its xy-coordinate whatever the inputs were: where a surface
already covers a cell, the point kept is the first match in
(x, y, z) order, so a stack of heights above one cell collapses to
its lowest. Aggregate such a surface before merging if a different
height is wanted.
Source§fn merge_axis_index<'a>(&'a self, other: &'a Self) -> Vec<Input>
fn merge_axis_index<'a>(&'a self, other: &'a Self) -> Vec<Input>
Source§impl Ord for Point3D
Orders on (x, y, z), lexicographically: the same triple PartialEq
reads, so cmp returns Ordering::Equal exactly when the points are
equal.
impl Ord for Point3D
Orders on (x, y, z), lexicographically: the same triple PartialEq
reads, so cmp returns Ordering::Equal exactly when the points are
equal.
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for Point3D
Two points are equal when all three coordinates are equal.
impl PartialEq for Point3D
Two points are equal when all three coordinates are equal.
PartialEq, Ord and Hash all read the full (x, y, z) triple, so
a == b holds exactly when a.cmp(&b) is Ordering::Equal, and equal
points hash alike, as Ord requires.
The “one z per (x, y)” rule is a property of a surface, not of a
point, and it is a container-level invariant that nothing enforces:
crate::surfaces::Surface::new retains a repeated (x, y) coordinate,
and points is a pub field, so no constructor could. The rule and what
each consumer does when it is broken are documented on
crate::surfaces::Surface::new.
Source§impl PartialOrd for Point3D
impl PartialOrd for Point3D
Source§impl SplineInterpolation<Point3D, Point2D> for Surface
impl SplineInterpolation<Point3D, Point2D> for Surface
Source§fn spline_interpolate(&self, xy: Point2D) -> Result<Point3D, InterpolationError>
fn spline_interpolate(&self, xy: Point2D) -> Result<Point3D, InterpolationError>
Auto Trait Implementations§
impl Freeze for Point3D
impl RefUnwindSafe for Point3D
impl Send for Point3D
impl Sync for Point3D
impl Unpin for Point3D
impl UnsafeUnpin for Point3D
impl UnwindSafe for Point3D
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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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 moreSource§impl<T> PartialSchema for Twhere
T: ComposeSchema + ?Sized,
impl<T> PartialSchema for Twhere
T: ComposeSchema + ?Sized,
Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Scalar for T
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.