Struct truck_geometry::specifieds::Sphere
source · pub struct Sphere { /* private fields */ }
Expand description
sphere
Examples
use truck_geometry::*;
use std::f64::consts::PI;
let center = Point3::new(1.0, 2.0, 3.0);
let radius = 4.56;
let sphere = Sphere::new(center, radius);
const N: usize = 100;
for i in 0..=N {
for j in 0..=N {
// the parameter u is latitude
let u = PI * i as f64 / N as f64;
// the parameter v is longitude
let v = 2.0 * PI * j as f64 / N as f64;
// simple relation between a point and its normal.
let pt = sphere.subs(u, v);
let n = sphere.normal(u, v);
assert_near!(pt - center, n * radius);
// the proof of u is latitude and v is longitude
assert!((PI / 2.0 - u) * (pt.z - center.z) >= 0.0);
assert!((PI - v) * (pt.y - center.y) >= 0.0);
}
}
Implementations§
source§impl Sphere
impl Sphere
sourcepub fn include(&self, pt: Point3) -> bool
pub fn include(&self, pt: Point3) -> bool
Returns whether the point pt
is on sphere
Examples found in repository?
src/specifieds/sphere.rs (line 85)
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
fn include(&self, curve: &BSplineCurve<Point3>) -> bool {
curve.is_const() && self.include(curve.front())
}
}
impl IncludeCurve<NURBSCurve<Vector4>> for Sphere {
fn include(&self, curve: &NURBSCurve<Vector4>) -> bool {
let (knots, _) = curve.knot_vec().to_single_multi();
let degree = curve.degree() * 2;
knots
.windows(2)
.flat_map(move |window| (1..degree).map(move |i| (window, i)))
.all(move |(window, i)| {
let t = i as f64 / degree as f64;
let t = window[0] * (1.0 - t) + window[1] * t;
self.include(curve.subs(t))
})
}
Trait Implementations§
source§impl BoundedSurface for Sphere
impl BoundedSurface for Sphere
source§impl<'de> Deserialize<'de> for Sphere
impl<'de> Deserialize<'de> for Sphere
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>,
Deserialize this value from the given Serde deserializer. Read more