NURBS surfaces
BSplineSurface carries the same three components per direction
(degree, poles, knots) with _u/_v suffixes, as in geomdl. A
bilinear patch over the unit square:
from geomcore import BSplineSurface, Point
poles = [[Point(0, 0, 0), Point(1, 0, 0)],
[Point(0, 1, 0), Point(1, 1, 0)]]
surf = BSplineSurface(1, 1, poles, [0.0, 1.0], [2, 2], [0.0, 1.0], [2, 2], False, False)
assert surf.point_at(0.5, 0.5) == Point(0.5, 0.5, 0)
use geomcore::prelude::*;
use geomcore::{BSplineSurface, Point};
let poles = vec![
vec![Point::new(0.0, 0.0, 0.0), Point::new(1.0, 0.0, 0.0)],
vec![Point::new(0.0, 1.0, 0.0), Point::new(1.0, 1.0, 0.0)],
];
let surf = BSplineSurface::new(1, 1, poles, vec![0.0, 1.0], vec![2, 2],
vec![0.0, 1.0], vec![2, 2], false, false).unwrap();
assert_eq!(surf.point_at(0.5, 0.5), Point::new(0.5, 0.5, 0.0));
Derivatives come from derivative (du, dv up to second
order); per-direction editing (insert_u_knot, elevate_v_degree,
split_u_at, extract, reversed_u/reversed_v,
to_bezier_patches) mirrors the curve API in
Editing & fitting.
Surface fitting (approximate over a point grid,
approximate_within) is covered there too.
Viewing
In the viewer a B-spline surface travels exact: its degree, poles,
weights and knots are evaluated in the page, and the display refines
with the zoom. Read the parameter window off the surface itself with
u_bounds()/v_bounds(), and draw curves in its (u, v) parameters
with pcurve.
import geomcore_viewer as gv
view = gv.Viewer("Bilinear patch")
view.add(surf, label="S", u=surf.u_bounds(), v=surf.v_bounds())
use geomcore_viewer::{Geom, Opts, Viewer};
let mut view = Viewer::new("Bilinear patch")?;
view.add(Geom::from(&surf), Opts::new().label("S"))?;