Document — Math Solvers & Local Properties
This page covers Document.swift lines 9930–11123: 2D conic utilities, normal projection, disk/shared-library/message system helpers, PlateSolver constraint extensions, extra methods on Shape, Curve3D, Curve2D, and Surface, the full MathSolver numerical toolkit, PolynomialSolver Laguerre extensions, BRepLProp edge/face local properties, GeomGridEval batch evaluators, single-parameter curve/surface evaluators, and the Newton-Hessian minimizer.
See also the main Document page for the
Documentclass itself and the other chunk pages.
Topics
- IntAna2d_Conic — 2D Conics · BRepAlgo_NormalProjection · OSD_Disk · OSD_SharedLibrary · Message_Msg · Plate Constraint Extensions · Shape Topology Extras · Curve3D Extras · Curve2D Extras · Surface Extras · Math Solvers · PolynomialSolver Laguerre Extensions · BRepLProp Edge Extensions · BRepLProp Face Extensions · GridEval Curve3D Extensions · GridEval Curve2D Extensions · GridEval Surface Extensions · Curve3D Evaluation · Curve2D Evaluation · Surface Evaluation · math_NewtonMinimum
IntAna2d_Conic — 2D Conics
Conic2D is a value type holding the six implicit coefficients of a 2D conic A·x² + B·x·y + C·y² + D·x + E·y + F = 0, plus static factories and a line-circle intersection query. Wraps IntAna2d_Conic / IntAna2d_AnaIntersection.
Conic2D
Coefficients of a 2D implicit conic A·x² + B·x·y + C·y² + D·x + E·y + F = 0.
public struct Conic2D: Sendable {
public let a, b, c, d, e, f: Double
}
Conic2D.fromCircle(center:direction:radius:)
Create Conic2D coefficients from a 2D circle.
public static func fromCircle(
center: SIMD2<Double>, direction: SIMD2<Double>, radius: Double
) -> Conic2D
- Parameters:
center— circle centre;direction— local X axis direction;radius— circle radius. - Returns:
Conic2Dwith the six implicit coefficients. - OCCT:
IntAna2d_Conic(circle constructor) viaOCCTConic2dFromCircle. - Example:
let c = Conic2D.fromCircle(center: SIMD2(0, 0), direction: SIMD2(1, 0), radius: 3) // c.a == 1, c.c == 1, c.f == -9 (approximate unit-circle form scaled by r²)
Conic2D.fromLine(point:direction:)
Create Conic2D coefficients from a 2D line.
public static func fromLine(
point: SIMD2<Double>, direction: SIMD2<Double>
) -> Conic2D
- Parameters:
point— any point on the line;direction— line direction vector. - Returns:
Conic2Dwhose non-zero linear coefficients describe the line. - OCCT:
IntAna2d_Conic(line constructor) viaOCCTConic2dFromLine. - Example:
let l = Conic2D.fromLine(point: .zero, direction: SIMD2(1, 0))
Conic2D.fromEllipse(center:direction:majorRadius:minorRadius:)
Create Conic2D coefficients from a 2D ellipse.
public static func fromEllipse(
center: SIMD2<Double>, direction: SIMD2<Double>,
majorRadius: Double, minorRadius: Double
) -> Conic2D
- Parameters:
center— ellipse centre;direction— local X axis;majorRadius/minorRadius— semi-axes. - Returns:
Conic2Dwith the six implicit conic coefficients. - OCCT:
IntAna2d_Conic(ellipse constructor) viaOCCTConic2dFromEllipse. - Example:
let e = Conic2D.fromEllipse(center: .zero, direction: SIMD2(1, 0), majorRadius: 5, minorRadius: 3)
Conic2D.lineCircleIntersection(linePoint:lineDir:circleCenter:circleDir:radius:)
Intersect a 2D line with a 2D circle, returning all intersection points.
public static func lineCircleIntersection(
linePoint: SIMD2<Double>, lineDir: SIMD2<Double>,
circleCenter: SIMD2<Double>, circleDir: SIMD2<Double>, radius: Double
) -> [SIMD2<Double>]
- Returns: 0, 1, or 2 intersection points. Empty array when the line misses the circle.
- OCCT:
IntAna2d_AnaIntersectionviaOCCTConic2dLineCircleIntersect. - Example:
let pts = Conic2D.lineCircleIntersection( linePoint: SIMD2(-5, 0), lineDir: SIMD2(1, 0), circleCenter: .zero, circleDir: SIMD2(1, 0), radius: 3) // pts.count == 2 → [-3,0] and [3,0]
BRepAlgo_NormalProjection
NormalProjection projects wires or edges onto a shape by shooting normals. Wraps BRepAlgo_NormalProjection.
NormalProjection.init(target:)
Create a normal-projection builder targeting the given shape.
public init?(target: Shape)
- Parameters:
target— the shape that wires/edges will be projected onto. - Returns:
nilif the internal object could not be created. - OCCT:
BRepAlgo_NormalProjectionconstructor viaOCCTNormalProjectionCreate. - Example:
guard let proj = NormalProjection(target: face) else { return }
NormalProjection.add(_:)
Add a wire or edge shape to be projected.
public func add(_ shape: Shape)
- Parameters:
shape— a wire or edge to project. - OCCT:
BRepAlgo_NormalProjection::AddviaOCCTNormalProjectionAdd. - Example:
proj.add(wireShape)
NormalProjection.build()
Build the projection. Returns true on success.
@discardableResult
public func build() -> Bool
- Returns:
trueif projection succeeded;falseon geometry failure. - OCCT:
BRepAlgo_NormalProjection::BuildviaOCCTNormalProjectionBuild. - Example:
if proj.build() { let result = proj.result }
NormalProjection.result
The projected shape after a successful build().
public var result: Shape? { get }
- Returns: The resulting projected wire/edge compound, or
nilif not built or failed. - OCCT:
BRepAlgo_NormalProjection::ProjectionviaOCCTNormalProjectionResult. - Example:
if let projected = proj.result { // use projected shape }
OSD_Disk
DiskInfo is a namespace for disk/volume introspection utilities. Wraps OSD_Disk.
DiskInfo.size(path:)
Get the total disk size in kilobytes for the given path.
public static func size(path: String = "/") -> Int64
- Parameters:
path— filesystem path; defaults to root/. - Returns: Total disk capacity in KB.
- OCCT:
OSD_Disk::DiskSizeviaOCCTDiskSize. - Example:
let totalKB = DiskInfo.size()
DiskInfo.freeSpace(path:)
Get the free space in kilobytes for the given path.
public static func freeSpace(path: String = "/") -> Int64
- Returns: Available free space in KB.
- OCCT:
OSD_Disk::DiskFreeviaOCCTDiskFree. - Example:
let freeKB = DiskInfo.freeSpace(path: "/tmp")
DiskInfo.isValid(path:)
Check whether a disk path is accessible.
public static func isValid(path: String) -> Bool
- Returns:
trueif the path names a mounted, accessible volume. - OCCT:
OSD_Diskvalidity check viaOCCTDiskIsValid. - Example:
if DiskInfo.isValid(path: "/Volumes/Data") { ... }
DiskInfo.name(path:)
Get the volume name for a given path.
public static func name(path: String = "/") -> String?
- Returns: Volume label string, or
nilif unavailable. - OCCT:
OSD_Diskname query viaOCCTDiskName. - Example:
if let vol = DiskInfo.name() { print(vol) }
OSD_SharedLibrary
SharedLibrary wraps a handle to a dynamically loaded library. Wraps OSD_SharedLibrary.
SharedLibrary.init(name:)
Create a shared-library handle for the given name or path.
public init?(name: String)
- Parameters:
name— library filename or full path (e.g."libFoo.dylib"). - Returns:
nilif the handle cannot be created. - OCCT:
OSD_SharedLibraryconstructor viaOCCTSharedLibCreate. - Example:
guard let lib = SharedLibrary(name: "libFoo.dylib") else { return }
SharedLibrary.open()
Load the shared library.
@discardableResult
public func open() -> Bool
- Returns:
trueif the library was successfully opened. - OCCT:
OSD_SharedLibrary::DlOpenviaOCCTSharedLibOpen. - Example:
if lib.open() { print("loaded") }
SharedLibrary.close()
Unload the shared library.
public func close()
- OCCT:
OSD_SharedLibrary::DlCloseviaOCCTSharedLibClose.
SharedLibrary.name
The name or path of the shared library.
public var name: String? { get }
- Returns: Library name, or
nilif unavailable. - OCCT:
OSD_SharedLibrary::NameviaOCCTSharedLibName.
Message_Msg
MessageSystem provides access to OCCT’s string-keyed message catalogue. Wraps Message_Msg / Message_MsgFile.
MessageSystem.message(forKey:)
Get the localized message text for a catalogue key.
public static func message(forKey key: String) -> String?
- Returns: The message string, or
nilif the key is not registered. - OCCT:
Message_Msglook-up viaOCCTMessageMsgGet. - Example:
if let text = MessageSystem.message(forKey: "BRep_API.NoFace") { print(text) }
MessageSystem.loadFile(_:)
Load message definitions from a .msg file.
@discardableResult
public static func loadFile(_ path: String) -> Bool
- Returns:
trueif the file was parsed successfully. - OCCT:
Message_MsgFile::LoadFileviaOCCTMessageMsgFileLoad.
MessageSystem.loadDefault()
Load the default OCCT message file bundled with the framework.
@discardableResult
public static func loadDefault() -> Bool
- Returns:
trueon success. - OCCT:
Message_MsgFile::LoadFile(default path) viaOCCTMessageMsgFileLoadDefault.
MessageSystem.hasMessage(forKey:)
Check whether a message key is registered.
public static func hasMessage(forKey key: String) -> Bool
- Returns:
trueif the key exists in the currently loaded catalogues. - OCCT:
Message_MsgFile::HasMsgviaOCCTMessageMsgHasMsg.
Plate Constraint Extensions
Extension on PlateSolver adding advanced constraint types. See the main PlateSolver page for the core solver.
PlateSolver.loadGlobalTranslation(uvPoints:)
Load a global translation constraint — all sample UV points are constrained to shift by the same unknown rigid displacement.
@discardableResult
public func loadGlobalTranslation(uvPoints: [SIMD2<Double>]) -> Bool
- Parameters:
uvPoints— UV parameter points where the constraint is sampled. - Returns:
trueif the constraint was accepted. - OCCT:
Plate_GlobalTranslationConstraintviaOCCTPlateLoadGlobalTranslation. - Example:
let uvs: [SIMD2<Double>] = [SIMD2(0.5, 0.5)] plate.loadGlobalTranslation(uvPoints: uvs)
PlateSolver.loadLinearXYZ(uvPoints:targets:coefficients:)
Load a linear XYZ constraint — a weighted linear combination of UV-sample positions must match the target.
@discardableResult
public func loadLinearXYZ(
uvPoints: [SIMD2<Double>],
targets: [SIMD3<Double>],
coefficients: [Double]
) -> Bool
- Parameters:
uvPoints— UV parameter points;targets— target XYZ positions;coefficients— scalar weights. - Returns:
trueif the constraint was accepted. - OCCT:
Plate_LinearXYZConstraintviaOCCTPlateLoadLinearXYZ.
Shape Topology Extras
Extension on Shape.
Shape.shapeTypeString
The topology type of the shape as a lowercase string ("compound", "solid", "face", etc.).
public var shapeTypeString: String { get }
- Returns: Type name string;
"unknown"if the handle is invalid. - OCCT:
BRep_Builder/TopAbs_ShapeEnumviaOCCTShapeTypeString. - Example:
let box = Shape.box(dx: 1, dy: 1, dz: 1)! print(box.shapeTypeString) // "solid"
Curve3D Extras
Extension on Curve3D.
Curve3D.reverse()
Reverse the orientation of the curve in-place.
@discardableResult
public func reverse() -> Bool
- Returns:
trueon success. - OCCT:
Geom_Curve::ReverseviaOCCTCurve3DReverse. - Example:
let ok = myCurve.reverse()
Curve3D.copy()
Create a deep copy of this curve.
public func copy() -> Curve3D?
- Returns: A new independent
Curve3D, ornilon failure. - OCCT:
Geom_Geometry::CopyviaOCCTCurve3DCopy. - Example:
if let clone = myCurve.copy() { clone.reverse() }
Curve2D Extras
Extension on Curve2D.
Curve2D.reverse()
Reverse the orientation of the 2D curve in-place.
@discardableResult
public func reverse() -> Bool
- Returns:
trueon success. - OCCT:
Geom2d_Curve::ReverseviaOCCTCurve2DReverse.
Curve2D.copy()
Create a deep copy of this 2D curve.
public func copy() -> Curve2D?
- Returns: A new independent
Curve2D, ornilon failure. - OCCT:
Geom2d_Geometry::CopyviaOCCTCurve2DCopy.
Surface Extras
Extension on Surface.
Surface.parameterBounds
The (u, v) parameter domain of the surface.
public var parameterBounds: (uMin: Double, uMax: Double, vMin: Double, vMax: Double) { get }
- OCCT:
Geom_Surface::BoundsviaOCCTSurfaceBounds. - Example:
let s = Surface.cylinder(axis: .zero, direction: SIMD3(0,0,1), radius: 5)! let b = s.parameterBounds print(b.uMin, b.uMax) // 0.0, 2π
Surface.surfaceContinuityOrder
Continuity order as an integer: 0=C0, 1=C1, 2=C2, 3=C3, 99=CN.
public var surfaceContinuityOrder: Int { get }
- OCCT:
Geom_Surface::ContinuityviaOCCTSurfaceContinuity.
Surface.copy()
Create a deep copy of this surface.
public func copy() -> Surface?
- Returns: A new independent
Surface, ornilon failure. - OCCT:
Geom_Geometry::CopyviaOCCTSurfaceCopy.
Math Solvers
MathSolver is a Swift namespace (enum) exposing OCCT’s math library via Swift closure callbacks. All closures are bridged through C void* context pointers using ClosureBox<T>. Introduced v0.110.0 / v0.111.0.
1D Root Finding
MathSolver.findRoot(near:tolerance:maxIterations:function:)
Find a root of f(x)=0 near guess using Newton-Raphson.
public static func findRoot(
near guess: Double,
tolerance: Double = 1e-8,
maxIterations: Int = 100,
function: @escaping (Double) -> (value: Double, derivative: Double)
) -> Double?
- Parameters:
guess— starting estimate;tolerance— convergence criterion;function— closure returning(f(x), f'(x)). - Returns: Root value, or
nilif the solver did not converge withinmaxIterations. - OCCT:
math_FunctionRootviaOCCTMathFunctionRoot. - Example:
// Find root of x² - 2 = 0 near 1 if let root = MathSolver.findRoot(near: 1.0) { x in (x * x - 2, 2 * x) } { print(root) // ≈ 1.41421356 }
MathSolver.findRoot(near:in:tolerance:maxIterations:function:)
Find a root of f(x)=0 near guess restricted to the closed range [a, b].
public static func findRoot(
near guess: Double,
in range: ClosedRange<Double>,
tolerance: Double = 1e-8,
maxIterations: Int = 100,
function: @escaping (Double) -> (value: Double, derivative: Double)
) -> Double?
- Parameters:
range— hard bounds for the search; other parameters as above. - Returns: Root within
range, ornilif not converged. - OCCT:
math_FunctionRoots(bounded) viaOCCTMathFunctionRootBounded. - Example:
let root = MathSolver.findRoot(near: 1.2, in: 1.0...2.0) { x in (x * x - 2, 2 * x) }
MathSolver.findRootBisection(in:tolerance:maxIterations:function:)
Find a root of f(x)=0 in [a, b] using a bisection + Newton hybrid.
public static func findRootBisection(
in range: ClosedRange<Double>,
tolerance: Double = 1e-8,
maxIterations: Int = 100,
function: @escaping (Double) -> (value: Double, derivative: Double)
) -> Double?
- Returns: Root within
range, ornilif not converged. - OCCT:
math_BissecNewtonviaOCCTMathBissecNewton. - Note: More robust than pure Newton when the function is not smooth near the root; the bracket
[a, b]must bracket a sign change.
System of Equations
MathSolver.solveSystem(variables:equations:startPoint:tolerance:maxIterations:values:jacobian:)
Solve a system of non-linear equations using Newton’s method.
public static func solveSystem(
variables: Int,
equations: Int,
startPoint: [Double],
tolerance: Double = 1e-8,
maxIterations: Int = 100,
values: @escaping ([Double]) -> [Double],
jacobian: @escaping ([Double]) -> [Double]
) -> [Double]?
- Parameters:
variables— number of unknowns.equations— number of equations (may differ fromvariablesfor over/under-determined systems).startPoint— initial guess array of lengthvariables.values— closure returning equation valuesF(x), lengthequations.jacobian— closure returning the row-major JacobianJ(x), lengthequations × variables.
- Returns: Solution point array of length
variables, ornilif not converged. - OCCT:
math_FunctionSetRootviaOCCTMathFunctionSetRoot. - Example:
// Solve x² + y² = 1, x - y = 0 (roots at ±1/√2) let sol = MathSolver.solveSystem( variables: 2, equations: 2, startPoint: [0.5, 0.5], values: { x in [x[0]*x[0] + x[1]*x[1] - 1, x[0] - x[1]] }, jacobian: { x in [2*x[0], 2*x[1], 1, -1] } )
BFGS Minimization
MathSolver.minimize(variables:startPoint:tolerance:maxIterations:function:)
Minimize a multivariate function using the BFGS quasi-Newton method (requires gradient).
public static func minimize(
variables: Int,
startPoint: [Double],
tolerance: Double = 1e-8,
maxIterations: Int = 200,
function: @escaping ([Double]) -> (value: Double, gradient: [Double])
) -> (point: [Double], minimum: Double)?
- Parameters:
function— closure returning(f(x), ∇f(x)). - Returns:
(minimizer, f(minimizer)), ornilif not converged. - OCCT:
math_BFGSviaOCCTMathBFGS. - Example:
// Minimize (x-1)² + (y-2)² if let res = MathSolver.minimize(variables: 2, startPoint: [0, 0]) { x in let v = (x[0]-1)*(x[0]-1) + (x[1]-2)*(x[1]-2) return (v, [2*(x[0]-1), 2*(x[1]-2)]) } { print(res.point) // ≈ [1, 2] print(res.minimum) // ≈ 0 }
Powell Minimization
MathSolver.minimizePowell(variables:startPoint:tolerance:maxIterations:function:)
Minimize a multivariate function using Powell’s direction-set method (derivative-free).
public static func minimizePowell(
variables: Int,
startPoint: [Double],
tolerance: Double = 1e-8,
maxIterations: Int = 200,
function: @escaping ([Double]) -> Double
) -> (point: [Double], minimum: Double)?
- Parameters:
function— closure returning a scalar valuef(x). - Returns:
(minimizer, f(minimizer)), ornilif not converged. - OCCT:
math_PowellviaOCCTMathPowell. - Note: Preferred when derivatives are unavailable or expensive; generally slower than BFGS for smooth functions.
Brent Minimization
MathSolver.minimizeBrent(ax:bx:cx:tolerance:maxIterations:function:)
Minimize a 1D function over a bracketed interval using Brent’s method.
public static func minimizeBrent(
ax: Double, bx: Double, cx: Double,
tolerance: Double = 1e-8,
maxIterations: Int = 100,
function: @escaping (Double) -> (value: Double, derivative: Double)
) -> (location: Double, minimum: Double)?
- Parameters:
ax,bx,cx— bracket triplet withax < bx < cxandf(bx) < f(ax),f(bx) < f(cx);function— closure returning(f(x), f'(x)). - Returns:
(x_min, f(x_min)), ornilif not converged. - OCCT:
math_BrentMinimumviaOCCTMathBrentMinimum. - Example:
// Minimize x² in [-2, 2] if let res = MathSolver.minimizeBrent(ax: -2, bx: 0.1, cx: 2) { x in (x * x, 2 * x) } { print(res.location) // ≈ 0 }
Particle Swarm Optimization
MathSolver.particleSwarm(variables:lower:upper:steps:particles:iterations:function:)
Minimize a multivariate function using Particle Swarm Optimization (PSO), a stochastic, derivative-free global search.
public static func particleSwarm(
variables: Int,
lower: [Double],
upper: [Double],
steps: [Double],
particles: Int = 64,
iterations: Int = 100,
function: @escaping ([Double]) -> Double
) -> (point: [Double], minimum: Double)?
- Parameters:
lower/upper— per-variable bounds;steps— initial step sizes;particles— swarm size;iterations— number of swarm iterations. - Returns:
(minimizer, f(minimizer)), ornilon failure. - OCCT:
math_PSOviaOCCTMathPSO. - Note: Good for highly multimodal or discontinuous objectives; does not require derivatives. Use
globalMinimizefor a deterministic alternative.
Global Minimization
MathSolver.globalMinimize(variables:lower:upper:function:)
Find the global minimum of a multivariate function using Lipschitz-based optimization.
public static func globalMinimize(
variables: Int,
lower: [Double],
upper: [Double],
function: @escaping ([Double]) -> Double
) -> (point: [Double], minimum: Double)?
- Parameters:
lower/upper— search domain bounds per variable;function— objective. - Returns:
(global minimizer, f(minimizer)), ornilon failure. - OCCT:
math_GlobOptMinviaOCCTMathGlobOptMin. - Example:
if let res = MathSolver.globalMinimize( variables: 2, lower: [-5, -5], upper: [5, 5] ) { x in x[0]*x[0] + x[1]*x[1] } { print(res.minimum) // ≈ 0 }
Find All Roots
MathSolver.findAllRoots(in:samples:function:)
Find all roots of f(x)=0 in a given interval using a subdivision-plus-Newton strategy.
public static func findAllRoots(
in range: ClosedRange<Double>,
samples: Int = 20,
function: @escaping (Double) -> (value: Double, derivative: Double)
) -> [Double]
- Parameters:
samples— number of sub-intervals for sign-change detection (more samples finds more roots but is slower). - Returns: Array of root values (may be empty). Up to 100 roots are returned.
- OCCT:
math_FunctionRootsviaOCCTMathFunctionRoots. - Example:
// Find all roots of sin(x) in [0, 4π] let roots = MathSolver.findAllRoots(in: 0...4*.pi, samples: 40) { x in (sin(x), cos(x)) }
Gauss Integration
MathSolver.integrate(from:to:order:function:)
Integrate a function over [lower, upper] using Gauss-Legendre quadrature.
public static func integrate(
from lower: Double,
to upper: Double,
order: Int = 10,
function: @escaping (Double) -> Double
) -> Double
- Parameters:
order— number of Gauss quadrature points (higher = more accurate for smooth functions). - Returns: Numerical integral value.
- OCCT:
math_GaussSingleIntegrationviaOCCTMathGaussIntegrate. - Example:
let area = MathSolver.integrate(from: 0, to: .pi) { x in sin(x) } // ≈ 2.0
Newton System Solver
MathSolver.solveSystemNewton(variables:equations:startPoint:tolerance:maxIterations:values:jacobian:)
Solve a system of equations using Newton’s method (NewtonFunctionSetRoot variant, stricter convergence criterion than solveSystem).
public static func solveSystemNewton(
variables: Int,
equations: Int,
startPoint: [Double],
tolerance: Double = 1e-8,
maxIterations: Int = 100,
values: @escaping ([Double]) -> [Double],
jacobian: @escaping ([Double]) -> [Double]
) -> [Double]?
- Parameters: Same interface as
solveSystem; internally usesmath_NewtonFunctionSetRoot. - Returns: Solution array of length
variables, ornil. - OCCT:
math_NewtonFunctionSetRootviaOCCTMathNewtonFuncSetRoot. - Note: More aggressive damping than
solveSystem; prefer when starting close to the solution.
PolynomialSolver Laguerre Extensions
Extension on PolynomialSolver adding Laguerre iteration for general-degree polynomials. Wraps OCCT’s math_Laguerre.
PolynomialSolver.laguerreRoots(coefficients:)
Find all real roots of a polynomial using Laguerre’s method.
public static func laguerreRoots(coefficients: [Double]) -> [Double]
- Parameters:
coefficients— polynomial coefficients in ascending power order:[a0, a1, …, an]fora0 + a1·x + … + an·xⁿ. - Returns: Sorted array of real roots (up to 20).
- OCCT:
math_Laguerre/math_DirectPolynomialRootsviaOCCTPolyLaguerreRoots. - Example:
// Roots of x³ - 6x² + 11x - 6 = 0 → [1, 2, 3] let r = PolynomialSolver.laguerreRoots(coefficients: [-6, 11, -6, 1])
PolynomialSolver.laguerreComplexRoots(coefficients:)
Find all (possibly complex) roots using Laguerre’s method.
public static func laguerreComplexRoots(coefficients: [Double]) -> [(real: Double, imaginary: Double)]
- Parameters: Same ascending-order convention as
laguerreRoots. - Returns: Array of
(real, imaginary)pairs (up to 20 roots). - OCCT:
math_Laguerrecomplex variant viaOCCTPolyLaguerreComplexRoots. - Example:
// Roots of x² + 1 = 0 → [(0, 1), (0, -1)] let r = PolynomialSolver.laguerreComplexRoots(coefficients: [1, 0, 1])
PolynomialSolver.quinticRoots(a:b:c:d:e:f:)
Find real roots of the quintic a·x⁵ + b·x⁴ + c·x³ + d·x² + e·x + f = 0.
public static func quinticRoots(a: Double, b: Double, c: Double, d: Double, e: Double, f: Double) -> [Double]
- Returns: Up to 5 real roots (sorted).
- OCCT:
math_DirectPolynomialRoots(degree 5) viaOCCTPolyQuinticRoots. - Example:
let r = PolynomialSolver.quinticRoots(a: 1, b: 0, c: 0, d: 0, e: 0, f: -32) // root of x⁵ - 32 = 0 → [2]
BRepLProp Edge Extensions
Extension on Shape for edge-level local geometric properties using BRepLProp_CLProps.
Shape.edgeLPropValue(at:)
Evaluate the 3D point on an edge at the given parameter.
public func edgeLPropValue(at param: Double) -> SIMD3<Double>?
- Returns: Point on the edge curve at
param. - OCCT:
BRepLProp_CLProps::ValueviaOCCTEdgeLPropValue.
Shape.edgeTangent(at:)
Tangent direction on an edge at the given parameter.
public func edgeTangent(at param: Double) -> SIMD3<Double>?
- Returns: Unit tangent vector, or
nilif the tangent is not defined (e.g. at a cusp). - OCCT:
BRepLProp_CLProps::TangentviaOCCTEdgeLPropTangent.
Shape.edgeCurvatureLP(at:)
Scalar curvature on an edge at the given parameter.
public func edgeCurvatureLP(at param: Double) -> Double
- Returns: Signed curvature value (0 for a straight edge).
- OCCT:
BRepLProp_CLProps::CurvatureviaOCCTEdgeLPropCurvature.
Shape.edgeNormalLP(at:)
Normal direction on an edge at the given parameter.
public func edgeNormalLP(at param: Double) -> SIMD3<Double>
- Returns: Normal vector in the osculating plane.
- OCCT:
BRepLProp_CLProps::NormalviaOCCTEdgeLPropNormal.
Shape.edgeCentreOfCurvature(at:)
Centre of curvature on an edge at the given parameter.
public func edgeCentreOfCurvature(at param: Double) -> SIMD3<Double>
- Returns: The centre of the osculating circle at
param. - OCCT:
BRepLProp_CLProps::CentreOfCurvatureviaOCCTEdgeLPropCentreOfCurvature.
Shape.edgeLPropD1(at:)
First derivative vector on an edge at the given parameter.
public func edgeLPropD1(at param: Double) -> SIMD3<Double>
- Returns: The first derivative
C'(param). - OCCT:
BRepLProp_CLProps::D1viaOCCTEdgeLPropD1. - Example:
let edge: Shape = ... // an edge shape let tangent = edge.edgeTangent(at: 0.5) let curv = edge.edgeCurvatureLP(at: 0.5)
BRepLProp Face Extensions
Extension on Shape for face-level local surface properties using BRepLProp_SLProps.
Shape.faceLPropValue(u:v:)
Evaluate the 3D point on a face at the given (u, v) parameter.
public func faceLPropValue(u: Double, v: Double) -> SIMD3<Double>
- OCCT:
BRepLProp_SLProps::ValueviaOCCTFaceLPropValue.
Shape.faceLPropNormal(u:v:)
Surface normal on a face at (u, v).
public func faceLPropNormal(u: Double, v: Double) -> SIMD3<Double>?
- Returns: Unit normal, or
nilif the normal is undefined (e.g. at a singular point). - OCCT:
BRepLProp_SLProps::NormalviaOCCTFaceLPropNormal.
Shape.faceLPropMaxCurvature(u:v:)
Maximum principal curvature on a face at (u, v).
public func faceLPropMaxCurvature(u: Double, v: Double) -> Double
- OCCT:
BRepLProp_SLProps::MaxCurvatureviaOCCTFaceLPropMaxCurvature.
Shape.faceLPropMinCurvature(u:v:)
Minimum principal curvature on a face at (u, v).
public func faceLPropMinCurvature(u: Double, v: Double) -> Double
- OCCT:
BRepLProp_SLProps::MinCurvatureviaOCCTFaceLPropMinCurvature.
Shape.faceLPropMeanCurvature(u:v:)
Mean curvature (κ₁ + κ₂) / 2 on a face at (u, v).
public func faceLPropMeanCurvature(u: Double, v: Double) -> Double
- OCCT:
BRepLProp_SLProps::MeanCurvatureviaOCCTFaceLPropMeanCurvature.
Shape.faceLPropGaussianCurvature(u:v:)
Gaussian curvature κ₁ · κ₂ on a face at (u, v).
public func faceLPropGaussianCurvature(u: Double, v: Double) -> Double
- OCCT:
BRepLProp_SLProps::GaussianCurvatureviaOCCTFaceLPropGaussianCurvature.
Shape.faceLPropIsUmbilic(u:v:)
Test whether a face is umbilic at (u, v) — both principal curvatures are equal.
public func faceLPropIsUmbilic(u: Double, v: Double) -> Bool
- OCCT:
BRepLProp_SLProps::IsUmbilicviaOCCTFaceLPropIsUmbilic.
Shape.faceLPropTangentU(u:v:)
Tangent in the U direction on a face at (u, v).
public func faceLPropTangentU(u: Double, v: Double) -> SIMD3<Double>?
- Returns: U tangent, or
nilif not defined. - OCCT:
BRepLProp_SLProps::TangentUviaOCCTFaceLPropTangentU. - Example:
let face: Shape = ... if let n = face.faceLPropNormal(u: 0.5, v: 0.5) { print("normal:", n) } let gauss = face.faceLPropGaussianCurvature(u: 0.5, v: 0.5)
GridEval Curve3D Extensions
Extension on Curve3D for optimized batch evaluation using GeomGridEval_Curve. Preferred over calling evalD0 / evalD1 in a loop for large parameter sets.
Curve3D.gridEvalD0(params:)
Batch-evaluate 3D curve positions at multiple parameters (D0).
public func gridEvalD0(params: [Double]) -> [SIMD3<Double>]
- Returns: Point for each input parameter, in the same order.
- OCCT:
GeomGridEval_CurveD0 viaOCCTGridEvalCurveD0. - Example:
let pts = myCurve.gridEvalD0(params: stride(from: 0, through: 1, by: 0.1).map { $0 })
Curve3D.gridEvalD1(params:)
Batch-evaluate 3D curve positions and first derivatives at multiple parameters.
public func gridEvalD1(params: [Double]) -> [(point: SIMD3<Double>, d1: SIMD3<Double>)]
- Returns:
(point, first derivative)tuples in input order. - OCCT:
GeomGridEval_CurveD1 viaOCCTGridEvalCurveD1.
GridEval Curve2D Extensions
Extension on Curve2D for optimized batch evaluation using Geom2dGridEval_Curve.
Curve2D.gridEvalD0(params:)
Batch-evaluate 2D curve positions at multiple parameters.
public func gridEvalD0(params: [Double]) -> [SIMD2<Double>]
- OCCT:
Geom2dGridEval_CurveD0 viaOCCTGridEvalCurve2dD0.
Curve2D.gridEvalD1(params:)
Batch-evaluate 2D curve positions and first derivatives.
public func gridEvalD1(params: [Double]) -> [(point: SIMD2<Double>, d1: SIMD2<Double>)]
- OCCT:
Geom2dGridEval_CurveD1 viaOCCTGridEvalCurve2dD1.
GridEval Surface Extensions
Extension on Surface for optimized grid evaluation using GeomGridEval_Surface. Output is row-major with dimensions [uParams.count × vParams.count].
Surface.gridEvalD0(uParams:vParams:)
Batch-evaluate surface positions at a UV grid.
public func gridEvalD0(uParams: [Double], vParams: [Double]) -> [SIMD3<Double>]
- Returns: Row-major point array, length
uParams.count × vParams.count. - OCCT:
GeomGridEval_SurfaceD0 viaOCCTGridEvalSurfaceD0. - Example:
let us = [0.0, 0.5, 1.0] let vs = [0.0, 0.5, 1.0] let pts = mySurface.gridEvalD0(uParams: us, vParams: vs) // pts[row * vs.count + col] = point at (us[row], vs[col])
Surface.gridEvalD1(uParams:vParams:)
Batch-evaluate surface positions and first partial derivatives at a UV grid.
public func gridEvalD1(uParams: [Double], vParams: [Double]) -> [(point: SIMD3<Double>, d1u: SIMD3<Double>, d1v: SIMD3<Double>)]
- Returns: Row-major array of
(point, ∂/∂u, ∂/∂v)tuples. - OCCT:
GeomGridEval_SurfaceD1 viaOCCTGridEvalSurfaceD1.
Curve3D Evaluation
Extension on Curve3D for single-parameter evaluation at up to D3. These complement the gridEval* batch methods for scalar queries.
Curve3D.evalD0(at:)
Evaluate curve position at parameter u.
public func evalD0(at u: Double) -> SIMD3<Double>
- OCCT:
Geom_Curve::D0viaOCCTCurve3DEvalD0.
Curve3D.evalD1(at:)
Evaluate curve position and first derivative at u.
public func evalD1(at u: Double) -> (point: SIMD3<Double>, d1: SIMD3<Double>)
- OCCT:
Geom_Curve::D1viaOCCTCurve3DEvalD1.
Curve3D.evalD2(at:)
Evaluate curve position and first and second derivatives at u.
public func evalD2(at u: Double) -> (point: SIMD3<Double>, d1: SIMD3<Double>, d2: SIMD3<Double>)
- OCCT:
Geom_Curve::D2viaOCCTCurve3DEvalD2.
Curve3D.evalD3(at:)
Evaluate curve position and first, second, and third derivatives at u.
public func evalD3(at u: Double) -> (point: SIMD3<Double>, d1: SIMD3<Double>, d2: SIMD3<Double>, d3: SIMD3<Double>)
- OCCT:
Geom_Curve::D3viaOCCTCurve3DEvalD3. - Example:
let (pt, d1, d2, d3) = myCurve.evalD3(at: 0.5)
Curve3D.evalBatchD0(params:)
Evaluate positions at multiple parameters (batch D0).
public func evalBatchD0(params: [Double]) -> [SIMD3<Double>]
- OCCT:
Geom_Curve::D0(batch) viaOCCTCurve3DEvalBatchD0.
Curve3D.evalBatchD1(params:)
Evaluate positions and first derivatives at multiple parameters (batch D1).
public func evalBatchD1(params: [Double]) -> [(point: SIMD3<Double>, d1: SIMD3<Double>)]
- OCCT:
Geom_Curve::D1(batch) viaOCCTCurve3DEvalBatchD1.
Curve2D Evaluation
Extension on Curve2D for single-parameter evaluation at up to D2.
Curve2D.evalD0(at:)
Evaluate 2D curve position at parameter u.
public func evalD0(at u: Double) -> SIMD2<Double>
- OCCT:
Geom2d_Curve::D0viaOCCTCurve2DEvalD0.
Curve2D.evalD1(at:)
Evaluate 2D curve position and first derivative at u.
public func evalD1(at u: Double) -> (point: SIMD2<Double>, d1: SIMD2<Double>)
- OCCT:
Geom2d_Curve::D1viaOCCTCurve2DEvalD1.
Curve2D.evalD2(at:)
Evaluate 2D curve position and first and second derivatives at u.
public func evalD2(at u: Double) -> (point: SIMD2<Double>, d1: SIMD2<Double>, d2: SIMD2<Double>)
- OCCT:
Geom2d_Curve::D2viaOCCTCurve2DEvalD2.
Curve2D.evalBatchD0(params:)
Evaluate 2D positions at multiple parameters (batch D0).
public func evalBatchD0(params: [Double]) -> [SIMD2<Double>]
- OCCT:
Geom2d_Curve::D0(batch) viaOCCTCurve2DEvalBatchD0.
Curve2D.evalBatchD1(params:)
Evaluate 2D positions and first derivatives at multiple parameters (batch D1).
public func evalBatchD1(params: [Double]) -> [(point: SIMD2<Double>, d1: SIMD2<Double>)]
- OCCT:
Geom2d_Curve::D1(batch) viaOCCTCurve2DEvalBatchD1.
Surface Evaluation
Extension on Surface for single (u, v) evaluation at up to D2.
Surface.evalD0(u:v:)
Evaluate surface position at (u, v).
public func evalD0(u: Double, v: Double) -> SIMD3<Double>
- OCCT:
Geom_Surface::D0viaOCCTSurfaceEvalD0.
Surface.evalD1(u:v:)
Evaluate surface position and first partial derivatives at (u, v).
public func evalD1(u: Double, v: Double) -> (point: SIMD3<Double>, d1u: SIMD3<Double>, d1v: SIMD3<Double>)
- OCCT:
Geom_Surface::D1viaOCCTSurfaceEvalD1.
Surface.evalD2(u:v:)
Evaluate surface position, first and second partial derivatives at (u, v).
public func evalD2(u: Double, v: Double) -> (point: SIMD3<Double>, d1u: SIMD3<Double>, d1v: SIMD3<Double>, d2u: SIMD3<Double>, d2v: SIMD3<Double>, d2uv: SIMD3<Double>)
- OCCT:
Geom_Surface::D2viaOCCTSurfaceEvalD2. - Example:
let (pt, du, dv, d2u, d2v, d2uv) = mySurface.evalD2(u: 0.5, v: 0.5) let normal = (du.cross(dv)).normalized
math_NewtonMinimum
Extension on MathSolver adding Newton’s Hessian-based minimizer. Introduced v0.111.1.
MathSolver.minimizeNewton(variables:startPoint:tolerance:maxIterations:function:)
Minimize a multivariate function using Newton’s method with analytical Hessian — the most precise local minimizer when second derivatives are available.
public static func minimizeNewton(
variables n: Int,
startPoint: [Double],
tolerance: Double = 1e-8,
maxIterations: Int = 40,
function: @escaping ([Double]) -> (value: Double, gradient: [Double], hessian: [Double])
) -> (point: [Double], minimum: Double)?
- Parameters:
n— number of variables.startPoint— initial guess, lengthn.function— closure returning(f(x), ∇f(x)[n], H(x)[n×n] row-major).
- Returns:
(minimizer, f(minimizer)), ornilif not converged. - OCCT:
math_NewtonMinimumviaOCCTMathNewtonMinimum. - Note: Quadratic convergence near the minimum; requires a positive-definite Hessian. Falls back gracefully but may not converge if the Hessian is indefinite away from the minimum — in that case, prefer
minimize(BFGS). - Example:
// Minimize f(x,y) = x² + y² (minimum at origin) if let res = MathSolver.minimizeNewton(variables: 2, startPoint: [1.0, 1.0]) { x in let v = x[0]*x[0] + x[1]*x[1] let g = [2*x[0], 2*x[1]] let h = [2.0, 0.0, 0.0, 2.0] // row-major 2×2 identity * 2 return (v, g, h) } { print(res.point) // ≈ [0, 0] print(res.minimum) // ≈ 0 }