Skip to main content

Polygon

A regular polygon in one gesture: hex bosses, nut pockets, octagonal bodies. The tool writes one line per side around a guide circle, plus the constraints that keep the sides equal and the shape regular — and one dimension, the circle's diameter, resizes the whole polygon.

In the viewport

  1. Click Polygon on the sketch toolbar. The button opens a menu with the sizing mode: Circumscribed (the default) draws the sides tangent to the guide circle, so the size is measured across the flats; Inscribed puts the vertices on the circle, so the size is measured across the corners.
  2. Click the centre. The X / Y pill places it exactly; a centre that snaps onto a vertex or the origin gets a coincident written for the guide circle's centre.
  3. Move out to size the polygon and click — or type the diameter and press Enter.
  4. The pill switches to N. Moving the mouse away from the centre adds sides to the preview; type the count and press Enter. Between 3 and 24 sides.

A typed diameter becomes a diameter dimension on the guide circle; a clicked size stays a guess.

A hexagon 60 across the flats, centred on the origin

The code behind it
boss.part.js
import { sketch, line, circle, origin } from 'fluidcad/core';
import { coincident, equal, tangent, angle, diameter, horizontal } from 'fluidcad/constraints';

sketch("xy", () => {
// A circumscribed hexagon: the centre clicked on the origin, 60 typed
// for the diameter, 6 for the sides. One line per side, corner to
// corner, and a guide circle the sides are tangent to.
const l1 = line([34.64, 0], [17.32, 30]);
const l2 = line([17.32, 30], [-17.32, 30]);
const l3 = line([-17.32, 30], [-34.64, 0]);
const l4 = line([-34.64, 0], [-17.32, -30]);
const l5 = line([-17.32, -30], [17.32, -30]);
const l6 = line([17.32, -30], [34.64, 0]);
const c1 = circle([0, 0], 60).guide();
coincident(l1.end(), l2.start());
coincident(l2.end(), l3.start());
coincident(l3.end(), l4.start());
coincident(l4.end(), l5.start());
coincident(l5.end(), l6.start());
coincident(l6.end(), l1.start());
// Regular: equal sides, every side tangent to the guide circle. With
// an even number of sides the last side is left out of the equal (the
// tangents already force it) and one corner angle pins the shape.
equal(l1, l2, l3, l4, l5);
tangent(l1, c1);
tangent(l2, c1);
tangent(l3, c1);
tangent(l4, c1);
tangent(l5, c1);
tangent(l6, c1);
angle(l1, l2, 60);
// Circumscribed: the typed diameter is the guide circle's, measured
// across the flats. Resize the polygon by changing this one value.
diameter(c1, 60);
// The centre click snapped onto the origin.
coincident(c1.center(), origin());
// The tool leaves one degree of freedom: the polygon can spin about its
// centre. Horizontal on one side settles it.
horizontal(l2);
})

The tool leaves one degree of freedom: the polygon can spin about its centre. Select a side and click Horizontal or Vertical on the constraint bar to settle it, as the example does.

Circumscribed and inscribed

Both modes write the same lines, the same coincident chain and the same .guide() circle; they differ in how the sides are tied to the circle.

CircumscribedCircumscribed modetangent(side, guide)

Every side is tangent to the guide circle. The diameter is the across-flats size — what a wrench or a nut pocket measures.

InscribedInscribed modecoincident(vertex, guide)

Every vertex lies on the guide circle. The diameter is the across-corners size — what a round bar must be to turn the polygon from.

The code behind it
boss.part.js
import { sketch, line, circle, origin } from 'fluidcad/core';
import { coincident, equal, diameter, vertical } from 'fluidcad/constraints';

sketch("xy", () => {
// An inscribed pentagon, 50 across the corners: the vertices sit on
// the guide circle instead of the sides touching it.
const l1 = line([25, 0], [7.73, 23.78]);
const l2 = line([7.73, 23.78], [-20.23, 14.69]);
const l3 = line([-20.23, 14.69], [-20.23, -14.69]);
const l4 = line([-20.23, -14.69], [7.73, -23.78]);
const l5 = line([7.73, -23.78], [25, 0]);
const c1 = circle([0, 0], 50).guide();
coincident(l1.end(), l2.start());
coincident(l2.end(), l3.start());
coincident(l3.end(), l4.start());
coincident(l4.end(), l5.start());
coincident(l5.end(), l1.start());
equal(l1, l2, l3, l4, l5);
// Inscribed: every vertex is coincident with the guide circle.
coincident(l1.start(), c1);
coincident(l2.start(), c1);
coincident(l3.start(), c1);
coincident(l4.start(), c1);
coincident(l5.start(), c1);
diameter(c1, 50);
coincident(c1.center(), origin());
// Added afterwards to stop the spin.
vertical(l3);
})

One equal runs across the sides. For a circumscribed polygon with an even number of sides the last side is left out of it — the tangents already force it equal, and listing it would only add a redundant row — and one corner angle (360° divided by the side count) pins the shape instead.

By hand

There is no polygon() statement. Write the sides as lines, a circle(...).guide() for the size, and the constraints from the example: a coincident at each corner, one variadic equal across the sides, then either tangent(side, guide) per side or coincident(vertex, guide) per vertex. Dimension the guide circle's diameter to size the polygon.

The guide circle is construction geometry: it stays out of the profile when the sketch is extruded, and it is the entity to pick when you want the polygon's centre — coincident(c1.center(), origin()), or concentric with a bore.