UNPKG

react-three-nurbs

Version:

A React component library for NURBS (Non-Uniform Rational B-Spline) curves, surfaces, and solids in Three.js. Built with React Three Fiber, zero external NURBS dependencies — all math implemented from scratch. Boolean operations powered by OpenCASCADE WAS

69 lines (68 loc) 2.94 kB
/** * NURBS surface evaluation and operations. * Implements algorithms from "The NURBS Book" (Piegl & Tiller), Chapters 4, 6. */ import { NurbsCurve } from "./curve"; import type { SurfaceData } from "./types"; export declare class NurbsSurface { private _degreeU; private _degreeV; private _knotsU; private _knotsV; private _controlPoints; private _weights; constructor(data: SurfaceData); static byKnotsControlPointsWeights(degreeU: number, degreeV: number, knotsU: number[], knotsV: number[], controlPoints: number[][][], weights: number[][]): NurbsSurface; static byLoftingCurves(curves: NurbsCurve[], degreeV: number): NurbsSurface; static byCorners(p0: number[], p1: number[], p2: number[], p3: number[]): NurbsSurface; /** * Evaluate surface point at (u, v) — Algorithm A4.3 (rational tensor product). */ point(u: number, v: number): number[]; /** * Compute surface normal at (u, v) as cross product of partial derivatives. */ normal(u: number, v: number): number[]; /** * Compute partial derivatives of the rational surface at (u, v). * Returns ders[k][l] = mixed partial derivative ∂^(k+l)S / ∂u^k ∂v^l. * Algorithm A4.4 adapted for rational surfaces (Eq. 4.20 generalized). */ derivatives(u: number, v: number, numDerivs: number): number[][][]; /** * Find closest UV parameters to a 3D point. * Implements the surface point projection from "The NURBS Book" Section 6.1. * * Phase 1: Initial guess via closest control point (Greville abscissa) * + grid refinement near the best candidate. * Phase 2: Newton iteration with four convergence criteria: * (1) Point coincidence: ||S(u,v) - P|| < eps1 * (2) Zero cosine (U): |S_u · (S - P)| / (|S_u| · |S - P|) < eps2 * (2) Zero cosine (V): |S_v · (S - P)| / (|S_v| · |S - P|) < eps2 * (3) Parameter correction: |Δu·S_u + Δv·S_v| < eps1 * (4) Domain bounds */ closestParam(point: number[]): number[]; /** * Extract an iso-parametric curve from the surface. * If useV=false: fix u=param, extract curve in V direction. * If useV=true: fix v=param, extract curve in U direction. */ /** * Extract an iso-parametric curve from the surface. * If useV=true: fix v=param, extract curve in U direction. * If useV=false: fix u=param, extract curve in V direction. * * Works in homogeneous coordinates: for each row/column, blend the * homogeneous control points (w*P, w) using basis functions, then * store the result as the new curve's control points and weights. */ isocurve(param: number, useV: boolean): NurbsCurve; degreeU(): number; degreeV(): number; knotsU(): number[]; knotsV(): number[]; controlPoints(): number[][][]; weights(): number[][]; asData(): SurfaceData; }