Sketcher & PlaneGCS Solver
Relevant source files
The following files were used as context for generating this wiki page:
The Sketcher module and its core PlaneGCS solver provide a constraint-based 2D environment for defining geometric profiles. The system allows users to create wireframe geometry (lines, arcs, circles, and B-splines) and apply mathematical relationships, known as constraints, to lock the geometry into specific shapes and positions.
The PlaneGCS solver is the numerical engine responsible for calculating the positions of geometric elements based on the provided constraints. It evaluates the sketch's "Degrees of Freedom" (DoF) to determine if the system is under-constrained, fully constrained, or over-constrained. This logic is fundamental for downstream operations such as Pad or Pocket in the PartDesign workbench.
Sources: src/Mod/Sketcher/Gui/Resources/translations/Sketcher.ts:3534-3578, src/Mod/PartDesign/Gui/Resources/translations/PartDesign.ts:1098-1129
Solver Architecture and Algorithms
The Sketcher utilizes several trust-region and optimization algorithms to reach convergence when solving the system of non-linear equations represented by the geometric constraints.
Optimization Algorithms
The solver allows selection between three primary mathematical algorithms:
- BFGS (Broyden–Fletcher–Goldfarb–Shanno): A quasi-Newton method used for solving unconstrained non-linear optimization problems.
- Levenberg-Marquardt: A standard method for solving non-linear least squares problems, acting as a middle ground between the Gauss-Newton algorithm and gradient descent.
- DogLeg: A trust-region method that combines Gauss-Newton steps with steepest descent.
Sources: src/Mod/Sketcher/Gui/Resources/translations/Sketcher.ts:393-403
Numerical Decomposition
To diagnose the rank of the constraint matrix and identify redundant or conflicting constraints, the system uses QR Decomposition. Users can configure the solver to use either:
- Eigen Dense QR: A dense matrix QR with full pivoting, suitable for smaller, highly interconnected sketches.
- Eigen Sparse QR: Optimized for sparse matrices, providing faster performance for large sketches with many independent components.
Sources: src/Mod/Sketcher/Gui/Resources/translations/Sketcher.ts:301-328
Solver Logic Flow
The diagram below illustrates the high-level process of solving a sketch after a user modifies geometry or adds a constraint.
The solver process ensures that the sketch geometry updates in real-time as constraints are added, while providing feedback on the solvability of the system.
Sources: src/Mod/Sketcher/Gui/Resources/translations/Sketcher.ts:114-124, src/Mod/Sketcher/Gui/Resources/translations/Sketcher.ts:3566-3574
Geometric Constraints
Constraints are the fundamental rules applied to geometry. They are divided into geometric constraints (shape/alignment) and dimensional constraints (size/position).
Supported Constraint Types
| Category | Type | Description |
|---|---|---|
| Geometric | Coincident | Forces two points to share the same coordinates. |
| Point on Object | Constrains a vertex to lie on a line, arc, or circle. | |
| Tangent | Forces two curves to touch without crossing. | |
| Parallel / Perpendicular | Defines the angular relationship between two lines. | |
| Symmetric | Equidistant points relative to a line or point. | |
| Dimensional | Distance | Fixed length or distance between elements. |
| Radius / Diameter | Fixed size for circular elements. | |
| Angle | Fixed rotation between two lines. | |
| Advanced | Snell's Law | Refraction law constraint for ray-boundary interactions. |
| Block | Prevents any movement of the selected edge. |
Sources: src/Mod/Sketcher/Gui/Resources/translations/Sketcher.ts:4158-4159, src/Mod/Sketcher/Gui/Resources/translations/Sketcher.ts:6951-6952, src/Mod/Sketcher/Gui/Resources/translations/Sketcher.ts:10091-10092, src/Mod/Sketcher/Gui/Resources/translations/Sketcher_af.ts:1769-1771
Solver Diagnostics and Status
The solver provides continuous feedback regarding the state of the sketch. This is expressed through the "Degrees of Freedom" (DoF) count and specific error states.
Sketch States
- Empty Sketch: No geometry exists.
- Under-constrained: The sketch has degrees of freedom remaining (e.g., "3 Degrees of Freedom").
- Fully Constrained: All geometric entities are fixed in space relative to the origin.
- Over-constrained: Conflicting or redundant constraints exist.
- Malformed: Constraints point to invalid indices or corrupted geometry.
Redundancy Detection
The solver distinguishes between:
- Redundant Constraints: Constraints that provide no new information to the solver.
- Conflicting Constraints: Constraints that mathematically contradict one another.
- Partially Redundant: Combinations of constraints that overlap in their restrictive effects.
Sources: src/Mod/Sketcher/Gui/Resources/translations/Sketcher.ts:3534-3578, src/Mod/Sketcher/Gui/Resources/translations/Sketcher.ts:552-722
Diagnostic Logic
This sequence represents how the solver evaluates the degree of freedom and constraint health.
B-Spline and Complex Geometry Solving
B-Splines introduce complex constraints related to their mathematical properties. The solver manages these through:
- Knot Multiplicity: Adjusting the multiplicity of B-spline knots to control local curvature and continuity.
- Poles and Weights: Constraining the position of control points (poles) and their influence (weight) on the spline curve.
- Internal Alignment: Automatically aligning internal geometric elements of B-splines or ellipses to ensure mathematical validity.
Sources: src/Mod/Sketcher/Gui/Resources/translations/Sketcher.ts:6616-6676, src/Mod/Sketcher/Gui/Resources/translations/Sketcher.ts:121-131
Summary
The Sketcher & PlaneGCS Solver system is a robust numerical framework designed to resolve complex geometric relationships. By utilizing advanced optimization algorithms like Levenberg-Marquardt and providing detailed diagnostic feedback on degrees of freedom and constraint health, it allows for the precise definition of 2D profiles. This accuracy is critical as these sketches serve as the foundation for 3D modeling operations across the application.