Geometry 2D

SVG coordinate plane and geometry primitives for math diagrams

Installation

npx docsui-cli@latest add geometry-2d

Usage

Wrap all Fig* primitives inside <FigScene>. The scene owns the SVG root, coordinate transform, grid, and axes. Children use world coordinates — no pixel math.

import {
  FigScene,
  FigPoint,
  FigVector,
  FigCircle,
  FigAngle,
  FigPolygon,
  FigLabel,
} from "@/components/mdx/geometry-2d";

Examples

Pythagorean theorem

A right triangle with labelled sides and the angle θ.

abcθOAB

Vectors in 2D

Adding two vectors u and v to get u + v.

uvu+vOP

Unit circle

The unit circle with a point at angle θ and its x/y projections.

r=1θ(cosθ, sinθ)

cosθ

sinθ

Props

FigScene

PropTypeDefaultDescription
widthnumber400SVG pixel width
heightnumber300SVG pixel height
xRange[number, number][-5, 5]World x axis range
yRange[number, number][-5, 5]World y axis range
showGridbooleantrueShow background grid
showAxesbooleantrueShow x/y axes with ticks
labelstring"Geometry diagram"Accessible SVG label

FigPoint

PropTypeDefaultDescription
xnumberWorld x
ynumberWorld y
labelstringText label
labelDir"ne" | "nw" | "se" | "sw""ne"Label placement
rnumber4Dot radius (px)

FigVector

PropTypeDefaultDescription
fromXnumber0Tail x
fromYnumber0Tail y
toXnumberHead x
toYnumberHead y
labelstringMidpoint label

FigCircle

PropTypeDefaultDescription
cxnumberCenter x
cynumberCenter y
rnumberWorld-unit radius
fillstring"none"Fill color
dashedbooleanfalseDashed stroke

FigAngle

PropTypeDefaultDescription
vertex{x,y}Angle vertex
from{x,y}Point on first ray
to{x,y}Point on second ray
labelstringArc label
radiusnumber0.5Arc radius (world units)