Skip to main content

Creating a basic sketch

The leaf starts as a rectangle: 30 mm wide, 60 mm along the pin axis, centred on the origin so the pin axis runs through the middle of one edge. You draw it with the Rectangle tool; the constraints that make it exactly that size are written for you, and one more pins it to the origin.

In the viewport

  1. Click Sketch on the toolbar. The Sketch dialog docks on the right with one Face / Plane slot and the three origin planes appear in the viewport as pickable quads.
  2. Click the XY plane (the horizontal one). The pick writes a sketch('xy', …) statement, the camera locks flat onto the plane, and the sketch toolbar appears: Line, Polyline, Bezier, Circle, Polygon, Rectangle, 3-Point Arc, Center Arc, Slot, Text, then the sketch tools.
  3. Click Rectangle. Click a first corner a little below the origin (the exact spot does not matter: a constraint will move it), then move towards the opposite corner. The coordinate pill next to the cursor takes typed values: type 30, Tab, 60, Enter.
  4. The rectangle is the right size but not yet pinned: it could still slide. Press Esc to leave the tool, then click the origin, the rectangle's top-left corner and its bottom-left corner. The constraint toolbar appears under the sketch toolbar; click Midpoint. The origin becomes the midpoint of the left edge, so the rectangle is centred on the X axis with its left edge on the Y axis.
  5. The rectangle turns green: every line is fully constrained. The sketch's status readout says Fully constrained.
  6. Click the green Finish sketch button. It leaves the sketch and offers the feature you most likely want next; ignore that for now.
The leaf outline, fully constrained

What the tool wrote

One gesture and one constraint click produced four lines and eleven constraints. In the History panel the sketch row lists the four Line rows and folds the rest behind an 11 constraints row. The constraints are the point of the exercise: the coordinates in the line() calls are only where you clicked (the -28.96 is where the first corner landed), and the solver moves them wherever the constraints say. Change the 30 in the distance() statement (or double-click the dimension label in the viewport) and the whole outline follows.

The code behind it
hinge-leaf-fixed.part.js
import { origin, xAxis, yAxis, part, sketch, line, circle, extrude, cut, repeat, fillet, connector } from 'fluidcad/core';
import { coincident, horizontal, vertical, midpoint, distance, diameter, fix } from 'fluidcad/constraints';
import { edge } from 'fluidcad/filters';

// The part container: everything inside the callback belongs to the
// "Fixed leaf". Exporting it is what lets an assembly insert() it later.
export const fixedLeaf = part('Fixed leaf', () => {
// Leaf outline, drawn with the Rectangle tool on the XY plane: 30 mm wide,
// 60 mm along the pin axis (Y). The four lines are guesses; the constraints
// below are what the tool wrote to pin the rectangle down.
sketch('xy', () => {
const b = line([0, -28.96], [30, -28.96]);
const r = line([30, -28.96], [30, 31.04]);
const t = line([30, 31.04], [0, 31.04]);
const l = line([0, 31.04], [0, -28.96]);
// corners: each line ends where the next one starts
coincident(b.end(), r.start());
coincident(r.end(), t.start());
coincident(t.end(), l.start());
coincident(l.end(), b.start());
// square it up
horizontal(b);
vertical(r);
horizontal(t);
vertical(l);
// the two dimensions (double-click a label in the viewport to change them)
distance(b.start(), b.end(), 30);
distance(r.start(), r.end(), 60);
// centre the left edge on the origin: the pin axis runs through the
// middle of the leaf, and the outline cannot slide
midpoint(origin(), t.end(), b.start());
});
});

The constraints break down as:

ConstraintsPurpose
4 × coincidentCorners: each line ends where the next begins
2 × horizontal, 2 × verticalSquare sides
2 × distanceThe 30 and 60 dimensions
midpointCentres the left edge on the origin, which also anchors the outline

Clicking the first corner exactly on the origin would have written a fix() on that corner instead, and the Rectangle tool's Centered option (in the button's menu) centres the rectangle on the first click and writes a midpoint() over a diagonal. The leaf uses the edge midpoint so that the pin axis runs through the middle of the leaf's edge.

tip

Sketch options live in the Sketch dialog while a sketch is open: Snap to vertices, Snap to grid, Auto-constraints → Infer while drawing (what added the coincident, horizontal and vertical constraints), and Show constraints toggles for the dimensional and positional markers. See Sketching.

Next: Applying 3D features.