Trait truck_polymesh::base::Homogeneous
source · pub trait Homogeneous<S>: VectorSpace<Scalar = S>where
S: BaseFloat,{
type Point: EuclideanSpace<Scalar = S>;
// Required methods
fn truncate(self) -> <Self::Point as EuclideanSpace>::Diff;
fn weight(self) -> S;
fn from_point(point: Self::Point) -> Self;
// Provided methods
fn from_point_weight(point: Self::Point, weight: S) -> Self { ... }
fn to_point(self) -> Self::Point { ... }
fn rat_der(self, der: Self) -> <Self::Point as EuclideanSpace>::Diff { ... }
fn rat_der2(
self,
der: Self,
der2: Self,
) -> <Self::Point as EuclideanSpace>::Diff { ... }
fn rat_cross_der(
&self,
uder: Self,
vder: Self,
uvder: Self,
) -> <Self::Point as EuclideanSpace>::Diff { ... }
}
Expand description
Homogeneous coordinate of an Euclidean space and a vector space.
§Examples
use truck_base::cgmath64::*;
use truck_base::cgmath_extend_traits::*;
assert_eq!(Vector4::new(8.0, 6.0, 4.0, 2.0).truncate(), Vector3::new(8.0, 6.0, 4.0));
assert_eq!(Vector4::new(8.0, 6.0, 4.0, 2.0).weight(), 2.0);
assert_eq!(Vector4::new(8.0, 6.0, 4.0, 2.0).to_point(), Point3::new(4.0, 3.0, 2.0));
assert_eq!(Vector4::from_point(Point3::new(4.0, 3.0, 2.0)), Vector4::new(4.0, 3.0, 2.0, 1.0));
Required Associated Types§
sourcetype Point: EuclideanSpace<Scalar = S>
type Point: EuclideanSpace<Scalar = S>
The point expressed by homogeneous coordinate
Required Methods§
sourcefn truncate(self) -> <Self::Point as EuclideanSpace>::Diff
fn truncate(self) -> <Self::Point as EuclideanSpace>::Diff
Returns the first dim - 1 components.
sourcefn from_point(point: Self::Point) -> Self
fn from_point(point: Self::Point) -> Self
Returns homogeneous coordinate.
Provided Methods§
sourcefn from_point_weight(point: Self::Point, weight: S) -> Self
fn from_point_weight(point: Self::Point, weight: S) -> Self
Returns homogeneous coordinate from point and weight.
sourcefn to_point(self) -> Self::Point
fn to_point(self) -> Self::Point
Returns the projection to the plane whose the last component is 1.0
.
sourcefn rat_der(self, der: Self) -> <Self::Point as EuclideanSpace>::Diff
fn rat_der(self, der: Self) -> <Self::Point as EuclideanSpace>::Diff
Returns the derivation of the rational curve.
For a curve c(t) = (c_0(t), c_1(t), c_2(t), c_3(t)), returns the derivation of the projected curve (c_0 / c_3, c_1 / c_3, c_2 / c_3, 1.0).
§Arguments
self
- the point of the curve c(t)der
- the derivation c’(t) of the curve
§Examples
use truck_base::cgmath64::*;
use truck_base::cgmath_extend_traits::*;
// calculate the derivation at t = 1.5
let t = 1.5;
// the curve: c(t) = (t^2, t^3, t^4, t)
let pt = Vector4::new(t * t, t * t * t, t * t * t * t, t);
// the derivation: c'(t) = (2t, 3t^2, 4t^3, 1)
let der = Vector4::new(2.0 * t, 3.0 * t * t, 4.0 * t * t * t, 1.0);
// the projected curve: \bar{c}(t) = (t, t^2, t^3, 1)
// the derivation of the proj'ed curve: \bar{c}'(t) = (1, 2t, 3t^2, 0)
let ans = Vector3::new(1.0, 2.0 * t, 3.0 * t * t);
assert_eq!(pt.rat_der(der), ans);
sourcefn rat_der2(
self,
der: Self,
der2: Self,
) -> <Self::Point as EuclideanSpace>::Diff
fn rat_der2( self, der: Self, der2: Self, ) -> <Self::Point as EuclideanSpace>::Diff
Returns the 2nd-ord derivation of the rational curve.
For a curve c(t) = (c_0(t), c_1(t), c_2(t), c_3(t)), returns the 2nd ordered derivation of the projected curve (c_0 / c_3, c_1 / c_3, c_2 / c_3).
§Arguments
self
- the point of the curve c(t)der
- the derivation c’(t) of the curveder2
- the 2nd ordered derivation c’’(t) of the curve
§Examples
use truck_base::cgmath64::*;
use truck_base::cgmath_extend_traits::*;
// calculate the derivation at t = 1.5
let t = 1.5;
// the curve: c(t) = (t^2, t^3, t^4, t)
let pt = Vector4::new(t * t, t * t * t, t * t * t * t, t);
// the derivation: c'(t) = (2t, 3t^2, 4t^3, 1)
let der = Vector4::new(2.0 * t, 3.0 * t * t, 4.0 * t * t * t, 1.0);
// the 2nd ord. deri.: c''(t) = (2, 6t, 12t^2, 0)
let der2 = Vector4::new(2.0, 6.0 * t, 12.0 * t * t, 0.0);
// the projected curve: \bar{c}(t) = (t, t^2, t^3, 1)
// the derivation of the proj'ed curve: \bar{c}'(t) = (1, 2t, 3t^2, 0)
// the 2nd ord. deri. of the proj'ed curve: \bar{c}''(t) = (0, 2, 6t, 0)
let ans = Vector3::new(0.0, 2.0, 6.0 * t);
assert_eq!(pt.rat_der2(der, der2), ans);
sourcefn rat_cross_der(
&self,
uder: Self,
vder: Self,
uvder: Self,
) -> <Self::Point as EuclideanSpace>::Diff
fn rat_cross_der( &self, uder: Self, vder: Self, uvder: Self, ) -> <Self::Point as EuclideanSpace>::Diff
Returns the cross derivation of the rational surface.
For a surface s(u, v) = (s_0(u, v), s_1(u, v), s_2(u, v), s_3(u, v)), returns the derivation of the projected surface (s_0 / s_3, s_1 / s_3, s_2 / s_3) by both u and v.
§Arguments
self
- the point of the surface s(u, v)uder
- the u-derivation s_u(u, v) of the surfacevder
- the v-derivation s_v(u, v) of the surfaceuvder
- the 2nd ordered derivation s_{uv}(u, v) of the surface
§Examples
use truck_base::cgmath64::*;
// calculate the derivation at (u, v) = (1.0, 2.0).
let (u, v) = (1.0, 2.0);
// the curve: s(u, v) = (u^3 v^2, u^2 v^3, u v, u)
let pt = Vector4::new(
u * u * u * v * v,
u * u * v * v * v,
u * v,
u,
);
// the u-derivation: s_u(u, v) = (3u^2 v^2, 2u * v^3, v, 1)
let uder = Vector4::new(
3.0 * u * u * v * v,
2.0 * u * v * v * v,
v,
1.0,
);
// the v-derivation: s_v(u, v) = (2u^3 v, 3u^2 v^2, u, 0)
let vder = Vector4::new(
2.0 * u * u * u * v,
3.0 * u * u * v * v,
u,
0.0,
);
// s_{uv}(u, v) = (6u^2 v, 6u v^2, 1, 0)
let uvder = Vector4::new(6.0 * u * u * v, 6.0 * u * v * v, 1.0, 0.0);
// the projected surface: \bar{s}(u, v) = (u^2 v^2, u v^3, v)
// \bar{s}_u(u, v) = (2u v^2, v^3, 0)
// \bar{s}_v(u, v) = (2u^2 v, 3u v^2, 1)
// \bar{s}_{uv}(u, v) = (4uv, 3v^2, 0)
let ans = Vector3::new(4.0 * u * v, 3.0 * v * v, 0.0);
assert_eq!(pt.rat_cross_der(uder, vder, uvder), ans);