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§

Creates a sphere

Returns the center

Examples found in repository?
src/specifieds/sphere.rs (line 23)
23
    fn subs(&self, u: f64, v: f64) -> Point3 { self.center() + self.radius * self.normal(u, v) }

Returns the radius

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§

The range of the parameter of the surface.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
Returns whether the curve curve is included in the surface self.
Returns whether the curve curve is included in the surface self.
Creates the surface division Read more
The surface is in the space of Self::Point.
The derivation vector of the curve.
Substitutes the parameter (u, v).
Returns the derivation by u.
Returns the derivation by v.
Returns the 2nd-order derivation by u.
Returns the 2nd-order derivation by both u and v.
Returns the 2nd-order derivation by v.
Returns the normal vector at (u, v).
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
point
Search nearest parameter t such that self.subs(t) is nearest point.
Returns None if could not find such parameter.
point
Search parameter t such that self.subs(t) is near point.
Returns None if could not find such parameter.
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.