1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
use crate::*;
use std::ops::{Deref, DerefMut, Mul};
/// surface constructed by revoluting a curve
/// # Examples
/// Revoluted sphere
/// ```
/// use truck_geometry::*;
/// use std::f64::consts::PI;
/// let knot_vec = KnotVec::bezier_knot(2);
/// let control_points = vec![
/// Vector4::new(1.0, 0.0, 0.0, 1.0),
/// Vector4::new(0.0, 1.0, 0.0, 0.0),
/// Vector4::new(-1.0, 0.0, 0.0, 1.0),
/// ];
/// // upper half circle on xy-plane
/// let uhcircle = NURBSCurve::new(BSplineCurve::new(knot_vec, control_points));
/// // sphere constructed by revolute circle
/// let sphere = RevolutedCurve::by_revolution(
/// uhcircle, Point3::origin(), Vector3::unit_x(),
/// );
/// const N: usize = 30;
/// for i in 0..=N {
/// for j in 0..=N {
/// let u = i as f64 / N as f64;
/// let v = 2.0 * PI * j as f64 / N as f64;
/// let pt: Vector3 = sphere.subs(u, v).to_vec();
/// assert_near2!(pt.magnitude2(), 1.0);
/// assert_near!(pt, sphere.normal(u, v));
/// }
/// }
/// ```
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub struct RevolutedCurve<C> {
curve: C,
origin: Point3,
axis: Vector3,
}
/// Linearly extruded curve
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub struct ExtrudedCurve<C, V> {
curve: C,
vector: V,
}
/// invertible and transformable geometric element
/// # Examples
/// Curve processing example
/// ```
/// use truck_geometry::*;
/// let curve: BSplineCurve<Point3> = BSplineCurve::new(
/// KnotVec::bezier_knot(2),
/// vec![
/// Point3::new(0.0, 0.0, 0.0),
/// Point3::new(0.0, 0.0, 1.0),
/// Point3::new(1.0, 0.0, 0.0),
/// ],
/// );
/// let mut processed = Processor::<_, Matrix4>::new(curve.clone());
///
/// // both curves are the same curve
/// const N: usize = 100;
/// for i in 0..=N {
/// let t = i as f64 / N as f64;
/// assert_eq!(curve.subs(t), processed.subs(t));
/// }
///
/// // Processed curve can inverted!
/// processed.invert();
/// for i in 0..=N {
/// let t = i as f64 / N as f64;
/// assert_eq!(curve.subs(1.0 - t), processed.subs(t));
/// }
/// ```
/// Surface processing example
/// ```
/// use truck_geometry::*;
/// use std::f64::consts::PI;
///
/// let sphere = Sphere::new(Point3::new(1.0, 2.0, 3.0), 2.45);
/// let mut processed = Processor::<_, Matrix4>::new(sphere);
///
/// // both surfaces are the same surface
/// const N: usize = 100;
/// for i in 0..=N {
/// for j in 0..=N {
/// let u = PI * i as f64 / N as f64;
/// let v = 2.0 * PI * j as f64 / N as f64;
/// assert_eq!(sphere.subs(u, v), processed.subs(u, v));
/// }
/// }
///
/// // Processed surface can be inverted!
/// // Here, "invert surface" means swap (u, v)-axes.
/// processed.invert();
/// for i in 0..=N {
/// for j in 0..=N {
/// let u = PI * i as f64 / N as f64;
/// let v = 2.0 * PI * j as f64 / N as f64;
/// assert_eq!(sphere.subs(u, v), processed.subs(v, u));
/// }
/// }
/// ```
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub struct Processor<E, T> {
entity: E,
transform: T,
orientation: bool,
}
/// The composited maps
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub struct PCurve<C, S> {
curve: C,
surface: S,
}
/// Intersection curve between two surfaces.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IntersectionCurve<C, S> {
// Considering rotational surfaces, we can consider the case
// where the class `S` holds the curve `C` as a variable.
surface0: Box<S>,
surface1: Box<S>,
leader: C,
tol: f64,
}
/// trimmed curve for parametric curve
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct TrimmedCurve<C> {
curve: C,
range: (f64, f64),
}
mod curve_on_surface;
mod extruded_curve;
mod intersection_curve;
mod processor;
mod revolved_curve;
mod trimmied_curve;
pub use intersection_curve::double_projection;