Skip to main content

Constraints

Constraint statements declare relationships between the entities of a 2D sketch. The coordinates written in line(), arc(), circle(), and point() statements are guesses; the sketch solver moves the entities so every constraint holds. Each statement appears in the timeline like any other feature.

import { coincident, horizontal, vertical, parallel, perpendicular, tangent, equal, concentric, collinear, midpoint, symmetric, fix, distance, angle, radius, diameter } from 'fluidcad/constraints';

Constraint targets​

Every entity argument accepts a ConstraintTarget — one of the following forms:

FormExampleDescription
Entity statementconst l = line([0, 0], [40, 0]); horizontal(l)A SolvedLine, SolvedArc, SolvedCircle, or point() statement — the entity itself.
Point accessorl.start(), l.end(), c.center()A Vertex naming one of an entity's solver points. l.mid() is accepted by coincident() only (it lowers to the midpoint constraint).
Datumorigin(), xAxis(), yAxis()The sketch plane's fixed origin point and infinite axis lines — see origin, xAxis, yAxis.
Fixed referenceproject(bore), p.ref(i), p.ref(i).start()A Reference from project()/intersect() — the statement itself when it produced exactly one edge, a ReferenceEntity via .ref(i), or one of their point accessors.
note

Datums and fixed references never move. A constraint must reference at least one drawn (free) entity — a constraint over only fixed targets is an error. Cross-sketch targets are not supported.

Geometric constraints​

coincident()​

coincident(a: ConstraintTarget, b: ConstraintTarget): SceneObject

Makes two points coincide (2 dims), or puts a point on an entity (1 dim: point-on-infinite-line, point-on-circle/arc). coincident(p, l.mid()) lowers to the midpoint constraint.

ParameterTypeDescription
aConstraintTargetA point accessor, point statement, or entity
bConstraintTargetA point accessor, point statement, or entity

horizontal()​

horizontal(a: ConstraintTarget, b?: ConstraintTarget, ...rest: ConstraintTarget[]): SceneObject

Constrains a line to be horizontal, an ellipse's RX axis to run along the sketch X direction, or two or more points to share a y value. Every point after the first is aligned to the first.

ParameterTypeDescription
aConstraintTargetA line, an ellipse, or the first point
bConstraintTargetThe second point (point form) (optional)
...restConstraintTarget[]Further points to align to the first

vertical()​

vertical(a: ConstraintTarget, b?: ConstraintTarget, ...rest: ConstraintTarget[]): SceneObject

Constrains a line to be vertical, an ellipse's RX axis to run along the sketch Y direction, or two or more points to share an x value. Every point after the first is aligned to the first.

ParameterTypeDescription
aConstraintTargetA line, an ellipse, or the first point
bConstraintTargetThe second point (point form) (optional)
...restConstraintTarget[]Further points to align to the first

parallel()​

parallel(a: ConstraintTarget, b: ConstraintTarget, ...rest: ConstraintTarget[]): SceneObject

Constrains two or more lines to be parallel (1 dim per pair). Every line after the first is paralleled to the first.

ParameterTypeDescription
aConstraintTargetThe reference line
bConstraintTargetThe second line
...restConstraintTarget[]Further lines to parallel to the first

perpendicular()​

perpendicular(a: ConstraintTarget, b: ConstraintTarget): SceneObject

Constrains two lines to be perpendicular (1 dim).

ParameterTypeDescription
aConstraintTargetThe first entity
bConstraintTargetThe second entity

tangent()​

tangent(a: ConstraintTarget, b: ConstraintTarget): SceneObject

Constrains two curves to be tangent (1 dim): a line and a circle/arc/ellipse, or any two of circle/arc/ellipse. The tangency side (internal vs external) is locked from the guess positions. Also accepts a fixed reference: tangent(bore, l) with a single-edge project() result.

ParameterTypeDescription
aConstraintTargetThe first entity
bConstraintTargetThe second entity

equal()​

equal(a: ConstraintTarget, b: ConstraintTarget, ...rest: ConstraintTarget[]): SceneObject

Constrains two or more entities to be equal (1 dim per pair): equal line lengths or equal circle/arc radii. Every entity after the first is equated to the first.

ParameterTypeDescription
aConstraintTargetThe reference entity
bConstraintTargetThe second entity
...restConstraintTarget[]Further entities to equate to the first

concentric()​

concentric(a: ConstraintTarget, b: ConstraintTarget): SceneObject

Constrains two circles/arcs/ellipses to share a center (2 dims).

ParameterTypeDescription
aConstraintTargetThe first entity
bConstraintTargetThe second entity

collinear()​

collinear(a: ConstraintTarget, b: ConstraintTarget): SceneObject

Constrains line b to lie on the infinite line of a (2 dims). The first slot also takes an axis datum: collinear(xAxis(), l).

ParameterTypeDescription
aConstraintTargetThe first entity
bConstraintTargetThe second entity

midpoint()​

midpoint(p: ConstraintTarget, l: ConstraintTarget, b?: ConstraintTarget): SceneObject

Constrains point p to be the midpoint of line l — or, with three arguments, to sit halfway between points a and b (2 dims either way).

ParameterTypeDescription
pConstraintTargetThe point
lConstraintTargetThe line whose midpoint p takes; with b given, the first of the two points
bConstraintTargetThe second point, for the point-pair form midpoint(p, a, b) (optional)

symmetric()​

symmetric(a: ConstraintTarget, b: ConstraintTarget, l: ConstraintTarget): SceneObject

Constrains a and b to mirror across line l: two points (2 dims), or two entities of one kind — two lines (4), two circles (3: centers mirror, equal radii), two arcs (5: centers and starts mirror, the ends reflect), two ellipses (5: centers mirror, equal semi-radii, the RX axes reflect). The entity forms are what the sketch Mirror tool writes, one statement per mirrored entity.

ParameterTypeDescription
aConstraintTargetThe first point or entity
bConstraintTargetThe second point or entity (same kind as a)
lConstraintTargetThe mirror line — a sketched line or xAxis() / yAxis()

fix()​

fix(p: ConstraintTarget, position?: Point2DLike): SceneObject

Anchors a point in place (2 dims). Without an explicit position the point's current (guess) coordinates are captured at statement time.

ParameterTypeDescription
pConstraintTargetThe point to anchor
positionPoint2DLikeOptional explicit [x, y] anchor position (optional)

Dimensions​

distance()​

distance(a: ConstraintTarget, b: ConstraintTarget, value: NumberParam, axis?: 'x' | 'y'): Distance

Distance dimension. Forms by what the targets resolve to: point–point (optionally measured along one axis), point–line (perpendicular), point–circle/arc (to the circumference), line–line (pair with parallel), line–circle/arc (perpendicular to the circumference), circle–circle (gap between circumferences). Circle/arc measurements take the NEAR side of the circumference by default; chain .max() for the far side.

Returns: Distance

ParameterTypeDescription
aConstraintTargetFirst point/entity
bConstraintTargetSecond point/entity
valueNumberParamThe distance value
axis'x' | 'y'Optional 'x' or 'y' to measure along one axis (point–point) (optional)

angle()​

angle(a: ConstraintTarget, b: ConstraintTarget, degrees: NumberParam): SceneObject

Dimensions the counterclockwise angle from line a to line b, in degrees (0–360). Each argument is a line or one of its endpoint accessors, which orients the line toward that endpoint — angle(l1, l2.start(), 45) measures to l2 pointing at its start. A bare line points at its end. There are no negative angles: a clockwise angle is the counterclockwise angle of the swapped pair.

ParameterTypeDescription
aConstraintTargetThe first line, optionally oriented via .start()/.end()
bConstraintTargetThe second line, optionally oriented via .start()/.end()
degreesNumberParamThe angle in degrees, 0 (inclusive) to 360 (exclusive)

radius()​

radius(c: ConstraintTarget, value: NumberParam, axis?: 'x' | 'y'): SceneObject

Dimensions the radius of a circle or arc, or one semi-radius of an ellipse: radius(el, 20, 'x') sizes the RX axis, 'y' the RY axis (the axis is required for an ellipse and refused elsewhere).

ParameterTypeDescription
cConstraintTargetThe circle, arc or ellipse
valueNumberParamThe radius value
axis'x' | 'y'Ellipses only: which semi-radius, 'x' (RX) or 'y' (RY) (optional)

diameter()​

diameter(c: ConstraintTarget, value: NumberParam): SceneObject

Dimensions the diameter of a circle or arc.

ParameterTypeDescription
cConstraintTargetThe circle or arc
valueNumberParamThe diameter value