Skip to content
On this page

Style Functions

Constraint Functions

equal

Require that the value x is equal to the value y

Parameters:

NameTypeType DescriptionDescription
xReal NumberFirst value
yReal NumberSecond value

lessThan

Require that the value x is less than the value y with optional padding padding

Parameters:

NameTypeType DescriptionDescription
xReal NumberFirst value
yReal NumberSecond value
paddingReal NumberPadding

greaterThan

Require that the value x is greater than the value y with optional padding padding

Parameters:

NameTypeType DescriptionDescription
xReal NumberFirst value
yReal NumberSecond value
paddingReal NumberPadding

lessThanSq

Require that the value x is less than the value y, with steeper penalty

Parameters:

NameTypeType DescriptionDescription
xReal NumberFirst value
yReal NumberSecond value

greaterThanSq

Require that the value x is greater than the value y, with steeper penalty

Parameters:

NameTypeType DescriptionDescription
xReal NumberFirst value
yReal NumberSecond value

inRange

Require that the value x is in the range defined by [x0, x1].

Parameters:

NameTypeType DescriptionDescription
xReal NumberValue
x0Real NumberLower bound
x1Real NumberUpper bound

contains1D

Require that an interval [l1, r1] contains another interval [l2, r2]. If not possible, returns 0.

Parameters:

NameTypeType DescriptionDescription
[l1, r1]ℝ²2d Vector of RealsFirst interval
[l2, r2]ℝ²2d Vector of RealsSecond interval

disjointScalar

Make scalar c disjoint from a range left, right.

Parameters:

NameTypeType DescriptionDescription
cReal NumberScalar
leftReal NumberLeft bound
rightReal NumberRight bound

perpendicular

Require that the vector defined by (q, p) is perpendicular from the vector defined by (r, p).

Parameters:

NameTypeType DescriptionDescription
qℝⁿVector of RealsFirst point
pℝⁿVector of RealsSecond point
rℝⁿVector of RealsThird point

collinear

Require that three points be collinear. This does not enforce a specific ordering of points, instead it takes the arrangement of points that is most easily satisfiable.

Parameters:

NameTypeType DescriptionDescription
c1ℝⁿVector of RealsFirst point
c2ℝⁿVector of RealsSecond point
c3ℝⁿVector of RealsThird point

collinearOrdered

Require that three points be collinear and enforces the order of these points as provided.

Parameters:

NameTypeType DescriptionDescription
c1ℝⁿVector of RealsFirst point
c2ℝⁿVector of RealsSecond point
c3ℝⁿVector of RealsThird point

onCanvas

Require that shape is on the canvas

Parameters:

NameTypeType DescriptionDescription
shapeShapeAny ShapeShape
canvasWidthReal NumberWidth of canvas
canvasHeightReal NumberHeight of canvas

minSize

Require that a shape have a size greater than some constant minimum, based on the type of the shape.

Parameters:

NameTypeType DescriptionDescription
shapeShapeAny ShapeShape
limitReal NumberMinimum size

maxSize

Require that a shape have a size less than some constant maximum, based on the type of the shape.

Parameters:

NameTypeType DescriptionDescription
shapeShapeAny ShapeShape
limitReal NumberMaximum size

overlapping

Require that shape s1 overlaps shape s2 with some overlap overlap. based on the type of the shape, and with an optional overlap between them (e.g. if s1 should be overlapping s2 with margin overlap).

Parameters:

NameTypeType DescriptionDescription
s1ShapeAny ShapeShape 1
s2ShapeAny ShapeShape 2
overlapReal NumberOverlap

disjoint

Require that a shape s1 is disjoint from shape s2, based on the type of the shape, and with an optional padding between them (e.g. if s1 should be disjoint from s2 with margin padding).

Parameters:

NameTypeType DescriptionDescription
s1ShapeAny ShapeShape 1
s2ShapeAny ShapeShape 2
paddingReal NumberPadding

touching

Require that shape s1 is touching shape s2 based on the type of the shape, and with an optional padding between them (e.g. if s1 should be touching s2 with margin padding).

Parameters:

NameTypeType DescriptionDescription
s1ShapeAny ShapeShape 1
s2ShapeAny ShapeShape 2
paddingReal NumberPadding

contains

Require that a shape s1 contains another shape s2, based on the type of the shape, and with an optional padding between the sizes of the shapes (e.g. if s1 should contain s2 with margin padding).

Parameters:

NameTypeType DescriptionDescription
s1ShapeAny ShapeShape 1
s2ShapeAny ShapeShape 2
paddingReal NumberPadding

atDist

Require that shape s1 is at a distance of distance from shape s2.

Parameters:

NameTypeType DescriptionDescription
s1ShapeAny ShapeShape 1
s2ShapeAny ShapeShape 2
distanceReal NumberDistance

smallerThan

Require that shape s1 is smaller than s2 with some relative padding relativePadding.

Parameters:

NameTypeType DescriptionDescription
s1ShapeAny ShapeShape 1
s2ShapeAny ShapeShape 2
relativePaddingReal NumberRelative padding

disjointIntervals

Make two intervals disjoint. They must be 1D intervals (line-like shapes) sharing a y-coordinate.

Parameters:

NameTypeType DescriptionDescription
s1LineShapeLine ShapeLine 1
s2LineShapeLine ShapeLine 2

isLocallyConvex

The shape should be locally convex (all angles between consecutive edges would have the same sign)

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectorspoints of polygonal chain
closedtrue | falseBoolean Valuewhether the polygonic chain is closed

isConvex

The enclosed area should be convex

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectorspoints of polygonal chain
closedtrue | falseBoolean Valuewhether the polygonic chain is closed

isEquilateral

All edges should have the same length

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectorspoints of polygonal chain
closedtrue | falseBoolean Valuewhether the polygonic chain is closed

isEquiangular

All angles between consecutive edges should be equal

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectorspoints of polygonal chain
closedtrue | falseBoolean Valuewhether the polygonic chain is closed

Objective Functions

minimal

Encourage the input value to be close to negative infinity

Parameters:

NameTypeType DescriptionDescription
xReal NumberValue

maximal

Encourage the input value to be close to infinity

Parameters:

NameTypeType DescriptionDescription
xReal NumberValue

equal

Encourage the inputs to have the same value: (x - y)^2

Parameters:

NameTypeType DescriptionDescription
xReal NumberFirst value
yReal NumberSecond value

greaterThan

Encourage x to be greater than or equal to y: max(0,y - x)^2

Parameters:

NameTypeType DescriptionDescription
xReal NumberFirst value
yReal NumberSecond value

lessThan

Encourage x to be less than or equal to y: max(0,x - y)^2

Parameters:

NameTypeType DescriptionDescription
xReal NumberFirst value
yReal NumberSecond value

repelPt

Repel point a from another scalar b with weight weight.

Parameters:

NameTypeType DescriptionDescription
weightReal NumberWeight
aℝⁿVector of RealsFirst point
bℝⁿVector of RealsSecond point

repelScalar

Repel scalar c from another scalar d.

Parameters:

NameTypeType DescriptionDescription
cReal NumberFirst scalar
dReal NumberSecond scalar

below

Encourage the center of bottom to be below the center of top.

Parameters:

NameTypeType DescriptionDescription
bottomShapeAny Shapeshape on the bottom
topShapeAny Shapeshape on the top
offsetReal Numberoffset

above

Encourage the center of top to be above the center of bottom.

Parameters:

NameTypeType DescriptionDescription
topShapeAny Shapeshape on the top
bottomShapeAny Shapeshape on the bottom
offsetReal Numberoffset

leftwards

Encourage the center of left to be leftwards to the center of right.

Parameters:

NameTypeType DescriptionDescription
leftShapeAny Shapeshape on the left
rightShapeAny Shapeshape on the right
offsetReal Numberoffset

rightwards

Encourage the center of right to be rightwards to the center of left.

Parameters:

NameTypeType DescriptionDescription
rightShapeAny Shapeshape on the right
leftShapeAny Shapeshape on the left
offsetReal Numberoffset

sameCenter

Encourage shape s1 to have the same center position as shape s2.

Parameters:

NameTypeType DescriptionDescription
s1ShapeAny Shapea shape
s2ShapeAny Shapea shape

notTooClose

Try to repel shapes s1 and s2 with some weight.

Parameters:

NameTypeType DescriptionDescription
s1ShapeAny Shapea shape
s2ShapeAny Shapea shape
weightReal Numberweight of repel

near

Try to place shape s1 near shape s2 (putting their centers at the same place).

Parameters:

NameTypeType DescriptionDescription
s1ShapeAny Shapea shape
s2ShapeAny Shapea shape
offsetReal Numberoffset

nearPt

Try to place shape s1 near a location (x, y).

Parameters:

NameTypeType DescriptionDescription
s1ShapeAny Shapea shape
xReal Number`x`
yReal Number`y`

nonDegenerateAngle

Try to place shape s1 near a location (x, y).

Parameters:

NameTypeType DescriptionDescription
s0ShapeAny Shapea shape
s1ShapeAny Shapea shape
s2ShapeAny Shapea shape
strengthReal Numberstrength
rangeReal Numberrange

centerLabelAbove

Parameters:

NameTypeType DescriptionDescription
s1LineShapeLine Shape
s2EquationShape | ImageShape | RectangleShape | TextShapeany of: Equation Shape, or Image Shape, or Rectangle Shape, or Text Shape
wReal Number

centerLabel

Try to center a label s2 with respect to some shape s1.

Parameters:

NameTypeType DescriptionDescription
s1LineShape | EquationShape | ImageShape | RectangleShape | TextShapeany of: Line Shape, or any of: Equation Shape, or Image Shape, or Rectangle Shape, or Text Shape
s2EquationShape | ImageShape | RectangleShape | TextShapeany of: Equation Shape, or Image Shape, or Rectangle Shape, or Text Shape
wReal Number
paddingReal Number

pointLineDist

Try to make distance between a point and a segment s1 equal to padding.

Parameters:

NameTypeType DescriptionDescription
pointℝ²2d Vector of Reals
s1LineShapeLine Shape
paddingReal Number

isRegular

Try to make the shape regular

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectorspoints of polygonal chain
closedtrue | falseBoolean Valuewhether the polygonic chain is closed

isEquilateral

Try to make the shape equilateral

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectorspoints of polygonal chain
closedtrue | falseBoolean Valuewhether the polygonic chain is closed

isEquiangular

Try to make the shape equiangular

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectorspoints of polygonal chain
closedtrue | falseBoolean Valuewhether the polygonic chain is closed

Computation Functions

makePath

See https://github.com/penrose/penrose/issues/716

Parameters:

NameTypeType DescriptionDescription
startℝ²2d Vector of RealsStart point of the path
endℝ²2d Vector of RealsEnd point of the path
curveHeightReal NumberHeight of the curve
paddingReal NumberPadding between the curve and the labels

Returns: PathCmd (Path Command)

get

Return ith element of list `xs, assuming lists only hold floats.

Parameters:

NameTypeType DescriptionDescription
xsℝⁿVector of RealsList of floats
iNatural NumberIndex of the element to return

Returns: ℝ (Real Number)

rgba

Return a paint color of elements r, g, b, a (red, green, blue, opacity).

Parameters:

NameTypeType DescriptionDescription
r[0,1]Real Number in Unit IntervalRed
g[0,1]Real Number in Unit IntervalGreen
b[0,1]Real Number in Unit IntervalBlue
a[0,1]Real Number in Unit IntervalOpacity

Returns: Color (Color)

selectColor

Parameters:

NameTypeType DescriptionDescription
color1ColorColorFirst color
color2ColorColorSecond color
levelReal NumberLevel

Returns: Color (Color)

hsva

Return a paint color of elements h, s, v, a (hue, saturation, value, opacity).

Parameters:

NameTypeType DescriptionDescription
hReal NumberHue in [0, 360)
sReal NumberSaturation in [0, 100]
vReal NumberValue in [0, 100]
a[0,1]Real Number in Unit IntervalOpacity

Returns: Color (Color)

none

Return a paint of none (no paint)

Returns: Color (Color)

acosh

Return acosh(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

acos

Return acos(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

asin

Return asin(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

asinh

Return asinh(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

atan

Return atan(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

atan2

Return atan2(x, y).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`
yReal Number`y`

Returns: ℝ (Real Number)

atanh

Return atanh(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

cbrt

Return cbrt(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

ceil

Return ceil(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

cos

Return cos(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

cosh

Return cosh(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

exp

Return exp(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

expm1

Return expm1(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

floor

Return floor(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

log

Return log(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

log2

Return log2(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

log10

Return log10(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

log1p

Return log1p(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

pow

Return pow(x, y).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`
yReal Number`y`

Returns: ℝ (Real Number)

round

Return round(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

sign

Return sign(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

sin

Return sin(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

sinh

Return sinh(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

tan

Return tan(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

tanh

Return tanh(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

trunc

Return trunc(x).

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

sum

Return the sum of elements in a vector.

Parameters:

NameTypeType DescriptionDescription
xsℝⁿVector of Realselements

Returns: ℝ (Real Number)

sumVectors

Return the sum of vectors in a list of vectors.

Parameters:

NameTypeType DescriptionDescription
vecs(ℝⁿ)ᵐList of Real Vectorsvectors

Returns: ℝⁿ (Vector of Reals)

maxList

Return the maximum of the elements in a vector.

Parameters:

NameTypeType DescriptionDescription
xsℝⁿVector of Realselements

Returns: ℝ (Real Number)

minList

Return the minimum of the elements in a vector.

Parameters:

NameTypeType DescriptionDescription
xsℝⁿVector of Realselements

Returns: ℝ (Real Number)

count

Return the number of the elements in a vector.

Parameters:

NameTypeType DescriptionDescription
xsℝⁿVector of Realselements

Returns: ℝ (Real Number)

dot

Return the dot product of v and w.

Parameters:

NameTypeType DescriptionDescription
vℝⁿVector of RealsVector `v`
wℝⁿVector of RealsVector `w`

Returns: ℝ (Real Number)

outerProduct

Return the outer product of v and w.

Parameters:

NameTypeType DescriptionDescription
vℝⁿVector of RealsVector `v`
wℝⁿVector of RealsVector `w`

Returns: (ℝⁿ)ᵐ (List of Real Vectors)

length

Return the length of the Line shape.

Parameters:

NameTypeType DescriptionDescription
lLineShapeLine ShapeA line

Returns: ℝ (Real Number)

normalize

Return the normalized version of vector v.

Parameters:

NameTypeType DescriptionDescription
vℝⁿVector of RealsVector `v`

Returns: ℝⁿ (Vector of Reals)

pathFromPoints

Given a list of points pts, returns a PathData that can be used as input to the Path shape's pathData attribute to be drawn on the screen.

Parameters:

NameTypeType DescriptionDescription
pathType"open" | "closed"Path TypePath Type
pts(ℝ²)ⁿList of 2d Real VectorsList of points

Returns: PathCmd (Path Command)

quadraticCurveFromPoints

Given a list of points pts, returns a PathData that can be used as input to the Path shape's pathData attribute to be drawn on the screen.

Parameters:

NameTypeType DescriptionDescription
pathType"open" | "closed"Path TypePath Type
pts(ℝ²)ⁿList of 2d Real VectorsList of points

Returns: PathCmd (Path Command)

interpolateQuadraticFromPoints

Draw a curve interpolating three given points. (Note that this is different from specifying the three control points of a quadratic Bézier curve, since a Bézier does not interpolate the middle control point.)

Parameters:

NameTypeType DescriptionDescription
pathType"open" | "closed"Path TypePath Type
p0ℝ²2d Vector of RealsFirst point
p1ℝ²2d Vector of RealsSecond point
p2ℝ²2d Vector of RealsThird point

Returns: PathCmd (Path Command)

cubicCurveFromPoints

Given a list of points pts, returns a PathData that can be used as input to the Path shape's pathData attribute to be drawn on the screen.

Parameters:

NameTypeType DescriptionDescription
pathType"open" | "closed"Path TypePath type
pts(ℝ²)ⁿList of 2d Real VectorsList of points

Returns: PathCmd (Path Command)

unitMark

Return two points parallel to line s1 using its normal line s2.

Parameters:

NameTypeType DescriptionDescription
s1LineShapeLine Shape
s2LineShapeLine Shape
paddingReal Number

Returns: (ℝ²)ⁿ (List of 2d Real Vectors)

unitMark2

Return two points to "cap off" the line made in unitMark.

Parameters:

NameTypeType DescriptionDescription
[start, end](ℝ²)ⁿList of 2d Real Vectors
tStringString
sizeReal Number

Returns: (ℝ²)ⁿ (List of 2d Real Vectors)

arc

Return series of elements that can render an arc SVG. See: https://css-tricks.com/svg-path-syntax-illustrated-guide/ for the "A" spec. Returns elements that can be passed to Path shape spec to render an SVG arc.

Parameters:

NameTypeType DescriptionDescription
pathType"open" | "closed"Path TypeThe path type: either "open" or "closed." whether the SVG should automatically draw a line between the final point and the start point
startℝ²2d Vector of Realscoordinate to start drawing the arc
endℝ²2d Vector of Realscoordinate to finish drawing the arc
[width, height]ℝ²2d Vector of Realswidth and height of the ellipse to draw the arc along
rotationReal Numberangle in degrees to rotate ellipse about its center
largeArcReal Number0 to draw shorter of 2 arcs, 1 to draw longer
arcSweepReal Number0 to rotate CCW, 1 to rotate CW

Returns: PathCmd (Path Command)

repeatedArcs

Generate multiple concentric arcs. Useful for denoting equal angles.

Parameters:

NameTypeType DescriptionDescription
innerStartℝ²2d Vector of Realscoordinate to start drawing the inner arc
innerEndℝ²2d Vector of Realscoordinate to end the inner arc
outerStartℝ²2d Vector of Realscoordinate to start drawing the outer arc
outerEndℝ²2d Vector of Realscoordinate to end the outer arc
innerRadiusℝ²2d Vector of Realsradii of the ellipse to draw the inner arc along (width, height)
repeatℤ⁺Positive Integernumber of times to repeat the arc
spacingReal Numberspacing between arcs
arcSweepReal Numberarc length to sweep

Returns: PathCmd (Path Command)

wedge

Return series of elements that render a "wedge", which is the same as the arc above except that it's connected to the circle center and filled. Returns elements that can be passed to Path shape spec to render an SVG arc.

Parameters:

NameTypeType DescriptionDescription
centerℝ²2d Vector of Realscenter of the circle on which the arc sits
startℝ²2d Vector of Realscoordinate to start drawing the arc
endℝ²2d Vector of Realscoordinate to finish drawing the arc
radiusℝ²2d Vector of Realswidth and height of the ellipse to draw the arc along (i.e. [width, height])
rotationReal Numberangle in degrees to rotate ellipse about its center
largeArcReal Number0 to draw shorter of 2 arcs, 1 to draw longer
arcSweepReal Number0 to rotate CCW, 1 to rotate CW

Returns: PathCmd (Path Command)

ptOnLine

Find the point that is located at dist r along a line between p1 and p2. Returns vector representation of the point of intersection.

Parameters:

NameTypeType DescriptionDescription
p1ℝⁿVector of Realsstart point of line segment
p2ℝⁿVector of Realsendpoint of line segment
rReal Numberdistance from p1 to travel along the line

Returns: ℝⁿ (Vector of Reals)

arcSweepFlag

Return 0 if direction of rotation is CCW, 1 if direction of rotation is CW.

Parameters:

NameTypeType DescriptionDescription
[x1, y1]ℝ²2d Vector of Realsx, y coordinates of the circle/ellipse that the arc is drawn on
startℝ²2d Vector of Realsstart point of the arc
endℝ²2d Vector of Realsend point of the arc

Returns: ℝ (Real Number)

angleBetween

Return the unsigned angle between vectors u, v, in radians. Assumes that both u and v have nonzero magnitude. The returned value will be in the range [0,pi].

Parameters:

NameTypeType DescriptionDescription
uℝⁿVector of RealsA vector
vℝⁿVector of RealsA vector

Returns: ℝ (Real Number)

angleFrom

Return the signed angle from vector u to vector v, in radians. Assumes that both u and v are 2D vectors and have nonzero magnitude. The returned value will be in the range [-pi,pi].

Parameters:

NameTypeType DescriptionDescription
uℝⁿVector of RealsA vector
vℝⁿVector of RealsA vector

Returns: ℝ (Real Number)

cross2D

Return the 2D cross product of u and v, equal to the determinant of the 2x2 matrix [u v]

Parameters:

NameTypeType DescriptionDescription
uℝ²2d Vector of RealsA vector
vℝ²2d Vector of RealsA vector

Returns: ℝ (Real Number)

cross

Return the 3D cross product of 3D vectors u and v.

Parameters:

NameTypeType DescriptionDescription
uℝ³3d Vector of RealsA vector
vℝ³3d Vector of RealsA vector

Returns: ℝ³ (3d Vector of Reals)

lineLineIntersection

Return the intersection of a line passing through a0 and a1 with a line passing through b0 and b1.

Parameters:

NameTypeType DescriptionDescription
a0ℝ²2d Vector of RealsFirst point of first line
a1ℝ²2d Vector of RealsSecond point of first line
b0ℝ²2d Vector of RealsFirst point of second line
b1ℝ²2d Vector of RealsSecond point of second line

Returns: ℝ² (2d Vector of Reals)

midpoint

Return a point located at the midpoint between pts start and end

Parameters:

NameTypeType DescriptionDescription
startℝⁿVector of RealsFirst point
endℝⁿVector of RealsSecond point

Returns: ℝⁿ (Vector of Reals)

midpointOffset

Return a point located at the midpoint of a line s1 but offset by padding in its normal direction (for labeling).

Parameters:

NameTypeType DescriptionDescription
s1LineShapeLine ShapeA line
paddingReal NumberPadding between midpoint and label

Returns: ℝ² (2d Vector of Reals)

chevron

Return a list of points for a chevron shape comprised of two line segments intersecting at a right angle at the midpoint of s1, which can then be passed to pathFromPoints to draw the chevron.

Parameters:

NameTypeType DescriptionDescription
s1LineShapeLine ShapeA line
paddingReal NumberLength of each line segment

Returns: (ℝ²)ⁿ (List of 2d Real Vectors)

innerPointOffset

Return a point located at padding of a line s1 offset by padding in its normal direction (for making right angle markers).

Parameters:

NameTypeType DescriptionDescription
pt1ℝ²2d Vector of RealsFirst point
pt2ℝ²2d Vector of RealsSecond point
pt3ℝ²2d Vector of RealsThird point
paddingReal NumberOffset from line to returned point

Returns: ℝ² (2d Vector of Reals)

ticksOnLine

Create equally spaced tick marks centered at the midpoint of a line

Parameters:

NameTypeType DescriptionDescription
pt1ℝ²2d Vector of Realsstarting point of a line
pt2ℝ²2d Vector of Realsending point of a line
spacingReal Numberspace in px between each tick
numTicksℤ⁺Positive Integernumber of tick marks to create
tickLengthReal Number1/2 length of each tick

Returns: PathCmd (Path Command)

orientedSquare

Given two orthogonal segments that intersect at intersection, and a size len return a path comprised of three points that describe a perpendicular mark at the angle where the segments intersect.

Parameters:

NameTypeType DescriptionDescription
s1LineShapeLine ShapeFirst line segment
s2LineShapeLine ShapeSecond line segment
intersectionℝ²2d Vector of RealsPoint of intersection
lenReal NumberSide length of square marker

Returns: PathCmd (Path Command)

triangle

Given three lines l1, l2, l3 that already form a triangle, return a path that describes the triangle (which can then be filled, etc.).

Parameters:

NameTypeType DescriptionDescription
l1LineShapeLine ShapeFirst line
l2LineShapeLine ShapeSecond line
l3LineShapeLine ShapeThird line

Returns: PathCmd (Path Command)

average2

Return the average of floats x and y.

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`
yReal Number`y`

Returns: ℝ (Real Number)

average

Return the average of the floats in the list xs.

Parameters:

NameTypeType DescriptionDescription
xsℝⁿVector of Reals`xs`

Returns: ℝ (Real Number)

unit

Return the normalized version of vector v.

Parameters:

NameTypeType DescriptionDescription
vℝⁿVector of Reals`v`

Returns: ℝⁿ (Vector of Reals)

random

Uniformly sample a random value in the range from minVal to maxVal.

Parameters:

NameTypeType DescriptionDescription
minValReal Numberminimum value
maxValReal Numbermaximum value

Returns: ℝ (Real Number)

unitRandom

Uniformly sample a random value in the range [0,1).

Returns: ℝ (Real Number)

diskRandom

Sample the uniform distribution on the unit disk.

Returns: ℝⁿ (Vector of Reals)

circleRandom

Sample the uniform distribution on the unit circle.

Returns: ℝⁿ (Vector of Reals)

sphereRandom

Sample the uniform distribution on the unit sphere.

Returns: ℝⁿ (Vector of Reals)

normalRandom

Sample a normal distribution with mean 0 and standard deviation 1.

Returns: ℝ (Real Number)

triangleRandom

Sample a point from the uniform distribution over a triangle with vertices a, b, and c.

Parameters:

NameTypeType DescriptionDescription
aℝ²2d Vector of RealsFirst vertex
bℝ²2d Vector of RealsSecond vertex
cℝ²2d Vector of RealsThird vertex

Returns: ℝⁿ (Vector of Reals)

sampleColor

Sample a random color once, with opacity alpha and color type colorType ("rgb" or "hsv").

Parameters:

NameTypeType DescriptionDescription
alpha[0,1]Real Number in Unit IntervalOpacity
colorType"rgb" | "hsv"Color TypeColor model

Returns: Color (Color)

setOpacity

Set the opacity of a color color to frac.

Parameters:

NameTypeType DescriptionDescription
colorColorColorColor
frac[0,1]Real Number in Unit IntervalOpacity

Returns: Color (Color)

mul

Multiply a matrix m and a vector v (where v is implicitly treated as a column vector).

Parameters:

NameTypeType DescriptionDescription
m(ℝⁿ)ᵐList of Real VectorsA matrix
vℝⁿVector of RealsA vector

Returns: ℝⁿ (Vector of Reals)

barycenter

Return the barycenter of the triangle with vertices a, b, c.

Parameters:

NameTypeType DescriptionDescription
aℝ²2d Vector of RealsFirst vertex
bℝ²2d Vector of RealsSecond vertex
cℝ²2d Vector of RealsThird vertex

Returns: ℝ² (2d Vector of Reals)

circumcenter

Return the circumcenter of the triangle with vertices p, q, r.

Parameters:

NameTypeType DescriptionDescription
pℝ²2d Vector of RealsFirst vertex
qℝ²2d Vector of RealsSecond vertex
rℝ²2d Vector of RealsThird vertex

Returns: ℝ² (2d Vector of Reals)

circumradius

Return the circumradius of the triangle with vertices p, q, r.

Parameters:

NameTypeType DescriptionDescription
pℝ²2d Vector of RealsFirst vertex
qℝ²2d Vector of RealsSecond vertex
rℝ²2d Vector of RealsThird vertex

Returns: ℝ (Real Number)

incenter

Return the incenter of the triangle with vertices p, q, r.

Parameters:

NameTypeType DescriptionDescription
pℝ²2d Vector of RealsFirst vertex
qℝ²2d Vector of RealsSecond vertex
rℝ²2d Vector of RealsThird vertex

Returns: ℝ² (2d Vector of Reals)

inradius

Return the inradius of the triangle with vertices p, q, r.

Parameters:

NameTypeType DescriptionDescription
pℝ²2d Vector of RealsFirst vertex
qℝ²2d Vector of RealsSecond vertex
rℝ²2d Vector of RealsThird vertex

Returns: ℝ (Real Number)

sqr

Return the square of the number x.

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

sqrt

Return the square root of number x. (Note: if x < 0 you may get NaNs)

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

max

Return the max of the numbers x, y.

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`
yReal Number`y`

Returns: ℝ (Real Number)

min

Return the min of the numbers x, y.

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`
yReal Number`y`

Returns: ℝ (Real Number)

abs

Return the absolute value of the number x.

Parameters:

NameTypeType DescriptionDescription
xReal Number`x`

Returns: ℝ (Real Number)

toRadians

Convert the angle theta from degrees to radians.

Parameters:

NameTypeType DescriptionDescription
thetaReal Number`theta`

Returns: ℝ (Real Number)

toDegrees

Convert the angle theta from radians to degrees.

Parameters:

NameTypeType DescriptionDescription
thetaReal Number`theta`

Returns: ℝ (Real Number)

norm

Return the Euclidean norm of the vector v.

Parameters:

NameTypeType DescriptionDescription
vℝⁿVector of RealsA vector

Returns: ℝ (Real Number)

normsq

Return the Euclidean norm squared of the vector v.

Parameters:

NameTypeType DescriptionDescription
vℝⁿVector of RealsA vector

Returns: ℝ (Real Number)

vdist

Return the Euclidean distance between the vectors v and w.

Parameters:

NameTypeType DescriptionDescription
vℝⁿVector of RealsA vector
wℝⁿVector of RealsA vector

Returns: ℝ (Real Number)

vmul

Returns the scalar-vector product.

Parameters:

NameTypeType DescriptionDescription
sReal NumberA scalar
vℝⁿVector of RealsA vector

Returns: ℝⁿ (Vector of Reals)

vdistsq

Return the Euclidean distance squared between the vectors v and w.

Parameters:

NameTypeType DescriptionDescription
vℝⁿVector of RealsA vector
wℝⁿVector of RealsA vector

Returns: ℝ (Real Number)

angleOf

Return the angle made by the vector v with the positive x-axis.

Parameters:

NameTypeType DescriptionDescription
vℝⁿVector of RealsA vector

Returns: ℝ (Real Number)

MathE

Base e of the natural logarithm.

Returns: ℝ (Real Number)

MathPI

Ratio of the circumference of a circle to its diameter.

Returns: ℝ (Real Number)

rot90

Rotate a 2D vector v by 90 degrees counterclockwise.

Parameters:

NameTypeType DescriptionDescription
vℝ²2d Vector of RealsA vector

Returns: ℝ² (2d Vector of Reals)

rotateBy

Rotate a 2D vector v by theta degrees counterclockwise.

Parameters:

NameTypeType DescriptionDescription
vℝ²2d Vector of RealsA vector
thetaReal Numberdegrees to rotate counterclockwise

Returns: ℝ² (2d Vector of Reals)

signedDistance

Return the signed distance between a shape and a point

Parameters:

NameTypeType DescriptionDescription
sEquationShape | ImageShape | RectangleShape | TextShape | CircleShape | PolygonShape | LineShape | PolylineShapeany of: any of: Equation Shape, or Image Shape, or Rectangle Shape, or Text Shape, or Circle Shape, or Polygon Shape, or Line Shape, or Polyline ShapeA shape
pℝ²2d Vector of RealsA point

Returns: ℝ (Real Number)

unitVector

Construct a unit vector u in the direction of the given angle theta (in radians).

Parameters:

NameTypeType DescriptionDescription
thetaReal Numberdirection

Returns: ℝ² (2d Vector of Reals)

rayIntersect

Parameters:

NameTypeType DescriptionDescription
SEquationShape | ImageShape | RectangleShape | TextShape | CircleShape | PolygonShape | LineShape | PolylineShape | EllipseShape | GroupShapeany of: any of: Equation Shape, or Image Shape, or Rectangle Shape, or Text Shape, or Circle Shape, or Polygon Shape, or Line Shape, or Polyline Shape, or Ellipse Shape, or Group ShapeA shape
pℝ²2d Vector of RealsA point
vℝ²2d Vector of RealsA vector

Returns: ℝ² (2d Vector of Reals)

rayIntersectNormal

Parameters:

NameTypeType DescriptionDescription
SEquationShape | ImageShape | RectangleShape | TextShape | CircleShape | PolygonShape | LineShape | PolylineShape | EllipseShape | GroupShapeany of: any of: Equation Shape, or Image Shape, or Rectangle Shape, or Text Shape, or Circle Shape, or Polygon Shape, or Line Shape, or Polyline Shape, or Ellipse Shape, or Group ShapeA shape
pℝ²2d Vector of RealsA point
vℝ²2d Vector of RealsA vector

Returns: ℝ² (2d Vector of Reals)

closestPoint

Parameters:

NameTypeType DescriptionDescription
sEquationShape | ImageShape | RectangleShape | TextShape | CircleShape | PolygonShape | LineShape | PolylineShape | EllipseShape | GroupShapeany of: any of: Equation Shape, or Image Shape, or Rectangle Shape, or Text Shape, or Circle Shape, or Polygon Shape, or Line Shape, or Polyline Shape, or Ellipse Shape, or Group ShapeA shape
pℝ²2d Vector of RealsA point

Returns: ℝ² (2d Vector of Reals)

closestSilhouettePoint

Parameters:

NameTypeType DescriptionDescription
sEquationShape | ImageShape | RectangleShape | TextShape | CircleShape | PolygonShape | LineShape | PolylineShape | EllipseShape | GroupShapeany of: any of: Equation Shape, or Image Shape, or Rectangle Shape, or Text Shape, or Circle Shape, or Polygon Shape, or Line Shape, or Polyline Shape, or Ellipse Shape, or Group ShapeA shape
pℝ²2d Vector of RealsA point

Returns: ℝ² (2d Vector of Reals)

rectLineDist

Return the distance between a rectangle (defined using the bottom-left and top-right points) and a line (defined using start and end points)

Parameters:

NameTypeType DescriptionDescription
bottomLeftℝ²2d Vector of Realsbottom-left point of rectangle
topRightℝ²2d Vector of Realstop-right point of rectangle
startℝ²2d Vector of Realsstart point of line
endℝ²2d Vector of Realsend point of line

Returns: ℝ (Real Number)

shapeDistance

Return the distance between two shapes.

Parameters:

NameTypeType DescriptionDescription
s1ShapeAny Shapea shape
s2ShapeAny Shapea shape

Returns: ℝ (Real Number)

signedArea

Returns the signed area enclosed by a polygonal chain given its nodes

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectorspoints of polygonal chain
closedtrue | falseBoolean Valuewhether the polygonic chain is closed

Returns: ℝ (Real Number)

turningNumber

Returns the turning number of polygonal chain given its nodes

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectorspoints of polygonal chain
closedtrue | falseBoolean Valuewhether the polygonic chain is closed

Returns: ℝ (Real Number)

perimeter

Returns the total length of polygonal chain given its nodes

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectorspoints of polygonal chain
closedtrue | falseBoolean Valuewhether the polygonic chain is closed

Returns: ℝ (Real Number)

isoperimetricRatio

Returns the isoperimetric ratio (perimeter squared divided by enclosed area)

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectorspoints of curve
closedtrue | falseBoolean Valuewhether the curve is closed

Returns: ℝ (Real Number)

elasticEnergy

Returns integral of curvature squared along the curve

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectorspoints of curve
closedtrue | falseBoolean Valuewhether curve is closed

Returns: ℝ (Real Number)

totalCurvature

Returns integral of curvature along the curve

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectorspoints of curve
closedtrue | falseBoolean Valuewhether curve is closed
signedtrue | falseBoolean Valuewhether curvature is signed

Returns: ℝ (Real Number)

lengthK

Returns the sum of all line segment lengths raised to k

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectorspoints of curve
closedtrue | falseBoolean Valuewhether curve is closed
kReal Numberexponent for line segments

Returns: ℝ (Real Number)

maxCurvature

Returns the maximum value of curvature along the curve

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectorspoints of curve
closedtrue | falseBoolean Valuewhether curve is closed

Returns: ℝ (Real Number)

pElasticEnergy

Returns integral of curvature raised to p along the curve

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectorspoints of curve
closedtrue | falseBoolean Valuewhether curve is closed
pReal Numberexponent for curvature

Returns: ℝ (Real Number)

inflectionEnergy

Returns integral of curvature derivative raised to p along the curve

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectorspoints of curve
closedtrue | falseBoolean Valuewhether curve is closed
pReal Numberexponent for curvature derivative

Returns: ℝ (Real Number)

centerOfMass

Returns center of mass for a 2D point cloud

Parameters:

NameTypeType DescriptionDescription
points(ℝ²)ⁿList of 2d Real Vectorspoints of curve

Returns: ℝ² (2d Vector of Reals)

noClip

Describes no shape clipping

Returns: ClipData (Shape clip data)

clip

Describes clipping to a shape

Parameters:

NameTypeType DescriptionDescription
shapeShapeAny Shape

Returns: ClipData (Shape clip data)

bboxPts

Return the top-right, top-left, bottom-left, bottom-right points (in that order) of the axis-aligned bounding box of the shape

Parameters:

NameTypeType DescriptionDescription
shapeShapeAny Shape

Returns: (ℝ²)ⁿ (List of 2d Real Vectors)