Skip to content

Style Functions

Constraint Functions

equal

Parameters:

NameTypeType DescriptionDescription
xReal Number

First value

yReal Number

Second value

lessThan

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

Parameters:

NameTypeType DescriptionDescription
xReal Number

First value

yReal Number

Second value

paddingReal Number

Padding

greaterThan

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

Parameters:

NameTypeType DescriptionDescription
xReal Number

First value

yReal Number

Second value

paddingReal Number

Padding

lessThanSq

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

Parameters:

NameTypeType DescriptionDescription
xReal Number

First value

yReal Number

Second value

greaterThanSq

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

Parameters:

NameTypeType DescriptionDescription
xReal Number

First value

yReal Number

Second value

inRange

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

Parameters:

NameTypeType DescriptionDescription
xReal Number

Value

x0Real Number

Lower bound

x1Real Number

Upper 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 Reals

First interval

[l2, r2]ℝ²2d Vector of Reals

Second interval

disjointScalar

Make scalar c disjoint from a range left, right.

Parameters:

NameTypeType DescriptionDescription
cReal Number

Scalar

leftReal Number

Left bound

rightReal Number

Right 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 Reals

First point

pℝⁿVector of Reals

Second point

rℝⁿVector of Reals

Third 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 Reals

First point

c2ℝⁿVector of Reals

Second point

c3ℝⁿVector of Reals

Third point

collinearOrdered

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

Parameters:

NameTypeType DescriptionDescription
c1ℝⁿVector of Reals

First point

c2ℝⁿVector of Reals

Second point

c3ℝⁿVector of Reals

Third point

onCanvas

Require that shape is on the canvas

Parameters:

NameTypeType DescriptionDescription
shapeShapeAny Shape

Shape

canvasWidthReal Number

Width of canvas

canvasHeightReal Number

Height of canvas

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 Shape

Shape 1

s2ShapeAny Shape

Shape 2

overlapReal Number

Overlap

overlappingEllipses

Require that ellipse e1 overlaps with ellipse e2 with some overlap overlap.

Parameters:

NameTypeType DescriptionDescription
c1ℝ²2d Vector of Reals

Center of e1

rx1Real Number

Horizontal radius of e1

ry1Real Number

Vertical radius of e1

c2ℝ²2d Vector of Reals

Center of e2

rx2Real Number

Horizontal radius of e2

ry2Real Number

Vertical radius of e2

overlapReal Number

the least amount of overlap

overlappingCircleEllipse

Require that circle c overlaps with ellipse e with some overlap overlap.

Parameters:

NameTypeType DescriptionDescription
c1ℝ²2d Vector of Reals

Center of c

r1Real Number

Radius of c

c2ℝ²2d Vector of Reals

Center of e

rx2Real Number

Horizontal radius of e

ry2Real Number

Vertical radius of e

overlapReal Number

the least amount of overlap

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 Shape

Shape 1

s2ShapeAny Shape

Shape 2

paddingReal Number

Padding

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 Shape

Shape 1

s2ShapeAny Shape

Shape 2

paddingReal Number

Padding

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 Shape

Shape 1

s2ShapeAny Shape

Shape 2

paddingReal Number

Padding

containsCircles

Require that a circle c1 contains another circle c2 with optional margin padding.

Parameters:

NameTypeType DescriptionDescription
c1ℝ²2d Vector of Reals

Center of c1

r1Real Number

Radius of c1

c2ℝ²2d Vector of Reals

Center of c2

r2Real Number

Radius of c2

paddingReal Number

Margin between the circles

containsPolys

Require that a polygon p1 contains another polygon p2 with optional margin padding.

Parameters:

NameTypeType DescriptionDescription
pts1(ℝ²)ⁿList of 2d Real Vectors

List of points for p1

pts2(ℝ²)ⁿList of 2d Real Vectors

List of points for p2

paddingReal Number

Margin between the polygons

containsPolyCircle

Require that a polygon p contains circle c with optional margin padding.

Parameters:

NameTypeType DescriptionDescription
pts(ℝ²)ⁿList of 2d Real Vectors

List of points for p

cℝ²2d Vector of Reals

Center of c

rReal Number

Radius of c

paddingReal Number

Margin between the polygon and the circle

containsPolyPoint

Require that a polygon p contains point pt with optional margin padding.

Parameters:

NameTypeType DescriptionDescription
pts(ℝ²)ⁿList of 2d Real Vectors

List of points for polygon p

ptℝ²2d Vector of Reals

Location of point pt

paddingReal Number

Margin between the polygon and the point

containsCirclePoint

Require that a circle c contains point pt with optional margin padding.

Parameters:

NameTypeType DescriptionDescription
cℝ²2d Vector of Reals

Center of c

rReal Number

Radius of c

ptℝ²2d Vector of Reals

Location of point pt

paddingReal Number

Margin between the polygon and the point

containsCirclePoly

Require that a circle c contains polygon p with optional margin padding.

Parameters:

NameTypeType DescriptionDescription
cℝ²2d Vector of Reals

Center of c

rReal Number

Radius of c

pts(ℝ²)ⁿList of 2d Real Vectors

List of points for polygon p

paddingReal Number

Margin between the polygon and the point

containsCircleRect

Require that a circle c contains rectangle r with optional padding padding.

Parameters:

NameTypeType DescriptionDescription
cℝ²2d Vector of Reals

Center of c

rReal Number

Radius of c

rect(ℝ²)ⁿList of 2d Real Vectors

The top-right, top-left, bottom-left, bottom-right points (in that order) of rectangle rect

paddingReal Number

Margin between the polygon and the point

containsRectCircle

Require that a rectangle r contains a circle c with optional margin padding.

Parameters:

NameTypeType DescriptionDescription
rect(ℝ²)ⁿList of 2d Real Vectors

The top-right, top-left, bottom-left, bottom-right points (in that order) of rectangle rect

cℝ²2d Vector of Reals

Center of c

rReal Number

Radius of c

paddingReal Number

Margin between the polygon and the point

containsRects

Requires that rect1 contains rect2 with some optional margin padding.

Parameters:

NameTypeType DescriptionDescription
rect1(ℝ²)ⁿList of 2d Real Vectors

The top-right, top-left, bottom-left, bottom-right points (in that order) of rectangle rect1

rect2(ℝ²)ⁿList of 2d Real Vectors

The top-right, top-left, bottom-left, bottom-right points (in that order) points of rectangle rect2

paddingReal Number

Margin between the polygon and the point

disjointIntervals

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

Parameters:

NameTypeType DescriptionDescription
s1LineShapeLine Shape

Line 1

s2LineShapeLine Shape

Line 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 Vectors

points of polygonal chain

closedtrue | falseBoolean Value

whether the polygonic chain is closed

isConvex

The enclosed area should be convex

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectors

points of polygonal chain

closedtrue | falseBoolean Value

whether the polygonic chain is closed

isEquilateral

All edges should have the same length

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectors

points of polygonal chain

closedtrue | falseBoolean Value

whether the polygonic chain is closed

isEquiangular

All angles between consecutive edges should be equal

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectors

points of polygonal chain

closedtrue | falseBoolean Value

whether the polygonic chain is closed

Objective Functions

minimal

Encourage the input value to be close to negative infinity

Parameters:

NameTypeType DescriptionDescription
xReal Number

Value

maximal

Encourage the input value to be close to infinity

Parameters:

NameTypeType DescriptionDescription
xReal Number

Value

equal

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

Parameters:

NameTypeType DescriptionDescription
xReal Number

First value

yReal Number

Second value

nearVec

Encourage two vectors v1 and v2 to be near each other with distance offset.

Parameters:

NameTypeType DescriptionDescription
v1ℝⁿVector of Reals

a vector

v2ℝⁿVector of Reals

a vector

offsetReal Number

distance between two vectors

greaterThan

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

Parameters:

NameTypeType DescriptionDescription
xReal Number

First value

yReal Number

Second value

lessThan

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

Parameters:

NameTypeType DescriptionDescription
xReal Number

First value

yReal Number

Second value

repelPt

Repel point a from another scalar b with weight weight.

Parameters:

NameTypeType DescriptionDescription
weightReal Number

Weight

aℝⁿVector of Reals

First point

bℝⁿVector of Reals

Second point

repelScalar

Repel scalar c from another scalar d.

Parameters:

NameTypeType DescriptionDescription
cReal Number

First scalar

dReal Number

Second scalar

inDirection

Encourage the point p to be in the direction direction with respect to point pRef. The direction vector does not need to be normalized. The offset parameter is the shortest allowed distance between the points.

Parameters:

NameTypeType DescriptionDescription
pℝ²2d Vector of Reals
pRefℝ²2d Vector of Reals
directionℝ²2d Vector of Reals
offsetReal Number

below

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

Parameters:

NameTypeType DescriptionDescription Default Value
bottomShapeAny Shape

shape on the bottom

topShapeAny Shape

shape on the top

offsetReal Number

distance between the two centers

100

above

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

Parameters:

NameTypeType DescriptionDescription Default Value
topShapeAny Shape

shape on the top

bottomShapeAny Shape

shape on the bottom

offsetReal Number

distance between the two centers

100

leftwards

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

Parameters:

NameTypeType DescriptionDescription Default Value
leftShapeAny Shape

shape on the left

rightShapeAny Shape

shape on the right

offsetReal Number

distance between the two centers

100

rightwards

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

Parameters:

NameTypeType DescriptionDescription Default Value
rightShapeAny Shape

shape on the right

leftShapeAny Shape

shape on the left

offsetReal Number

distance between the two centers

100

sameCenter

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

Parameters:

NameTypeType DescriptionDescription
s1ShapeAny Shape

a shape

s2ShapeAny Shape

a shape

notTooClose

Try to repel shapes s1 and s2 with some weight.

Parameters:

NameTypeType DescriptionDescription Default Value
s1ShapeAny Shape

a shape

s2ShapeAny Shape

a shape

weightReal Number

weight of repel

10

near

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

Parameters:

NameTypeType DescriptionDescription Default Value
s1ShapeAny Shape

a shape

s2ShapeAny Shape

a shape

offsetReal Number

offset

10

nearPt

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

Parameters:

NameTypeType DescriptionDescription
s1ShapeAny Shape

a shape

xReal Number

x

yReal Number

y

nonDegenerateAngle

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

Parameters:

NameTypeType DescriptionDescription Default Value
s0ShapeAny Shape

a shape

s1ShapeAny Shape

a shape

s2ShapeAny Shape

a shape

strengthReal Number

strength

20
rangeReal Number

range

10

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 Default Value
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 Number10

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 Vectors

points of polygonal chain

closedtrue | falseBoolean Value

whether the polygonic chain is closed

isEquilateral

Try to make the shape equilateral

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectors

points of polygonal chain

closedtrue | falseBoolean Value

whether the polygonic chain is closed

isEquiangular

Try to make the shape equiangular

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectors

points of polygonal chain

closedtrue | falseBoolean Value

whether the polygonic chain is closed

Computation Functions

makePath

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

Parameters:

NameTypeType DescriptionDescription
startℝ²2d Vector of Reals

Start point of the path

endℝ²2d Vector of Reals

End point of the path

curveHeightReal Number

Height of the curve

paddingReal Number

Padding 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 Reals

List of floats

iNatural Number

Index 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 Interval

Red

g[0,1]Real Number in Unit Interval

Green

b[0,1]Real Number in Unit Interval

Blue

a[0,1]Real Number in Unit Interval

Opacity

Returns: Color (Color)

selectColor

Parameters:

NameTypeType DescriptionDescription
color1ColorColor

First color

color2ColorColor

Second color

levelReal Number

Level

Returns: Color (Color)

hsva

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

Parameters:

NameTypeType DescriptionDescription
hReal Number

Hue in [0, 360)

sReal Number

Saturation in [0, 100]

vReal Number

Value in [0, 100]

a[0,1]Real Number in Unit Interval

Opacity

Returns: Color (Color)

none

Return a paint of none (no paint)

Returns: Color (Color)

oneBasedElement

Index a point list using 1-based indexing.

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectors

list of points

iℤ⁺Positive Integer

1-based index

Returns: ℝ² (2d Vector of Reals)

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)

mod

Return mod(a, n).

Parameters:

NameTypeType DescriptionDescription
aReal Number

a

nReal Number

n

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 Reals

elements

Returns: ℝ (Real Number)

sumVectors

Return the sum of vectors in a list of vectors.

Parameters:

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

vectors

Returns: ℝⁿ (Vector of Reals)

maxList

Return the maximum of the elements in a vector.

Parameters:

NameTypeType DescriptionDescription
xsℝⁿVector of Reals

elements

Returns: ℝ (Real Number)

minList

Return the minimum of the elements in a vector.

Parameters:

NameTypeType DescriptionDescription
xsℝⁿVector of Reals

elements

Returns: ℝ (Real Number)

count

Return the number of the elements in a vector.

Parameters:

NameTypeType DescriptionDescription
xsℝⁿVector of Reals

elements

Returns: ℝ (Real Number)

dot

Return the dot product of v and w.

Parameters:

NameTypeType DescriptionDescription
vℝⁿVector of Reals

Vector v

wℝⁿVector of Reals

Vector w

Returns: ℝ (Real Number)

identity

identity(n) returns the n×nn \times n identity matrix

I=[100010001].I = \left[ \begin{array}{cccc} 1 & 0 & \cdots & 0 \\ 0 & 1 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & 1 \end{array} \right].

Parameters:

NameTypeType DescriptionDescription
nℤ⁺Positive Integer

dimension

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

diagonal

diagonal(v) takes a vector vv of length nn, and returns the n×nn \times n diagonal matrix

D=[v1000v2000vn].D = \left[ \begin{array}{cccc} v_1 & 0 & \cdots & 0 \\ 0 & v_2 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & v_n \end{array} \right].

Parameters:

NameTypeType DescriptionDescription
vℝⁿVector of Reals

vector of diagonal entries

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

trace

trace(A) takes a square matrix AA, and returns the trace tr(A)\text{tr}(A), equal to the sum of its diagonal entries.

Parameters:

NameTypeType DescriptionDescription
A(ℝⁿ)ᵐList of Real Vectors

a square matrix

Returns: ℝ (Real Number)

determinant

determinant(A) takes a 2×22 \times 2, 3×33 \times 3, or 4×44 \times 4 matrix AA, and returns its determinant det(A)\text{det}(A).

Parameters:

NameTypeType DescriptionDescription
A(ℝⁿ)ᵐList of Real Vectors

a square matrix

Returns: ℝ (Real Number)

inverse

inverse(A) takes a 2×22 \times 2, 3×33 \times 3, or 4×44 \times 4 matrix AA, and returns its inverse A1A^{-1}. If the matrix is not invertible, the result may be numerically invalid (with INF or NaN entries).

Parameters:

NameTypeType DescriptionDescription
A(ℝⁿ)ᵐList of Real Vectors

a 2x2, 3x3, or 4x4 matrix

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

outerProduct

outerProduct(u,v) takes two vectors uu, vv of equal length nn, and returns the n×nn \times n outer product matrix AA, with entries Aij=uivjA_{ij} = u_i v_j.

Parameters:

NameTypeType DescriptionDescription
vℝⁿVector of Reals

Vector v

wℝⁿVector of Reals

Vector w

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

crossProductMatrix

crossProductMatrix(v) takes a 3-vector vv, and returns a 3×33 \times 3 skew symmetric matrix AT=AA^T = -A such that Au=v×uAu = v \times u for any vector uu.

Parameters:

NameTypeType DescriptionDescription
vℝⁿVector of Reals

Vector v

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

matrix

matrix(a,b,c,d,e,f) specifies a transformation matrix

[acebdf001].\left[ \begin{array}{ccc} a & c & e \\ b & d & f \\ 0 & 0 & 1 \end{array} \right].

This function mirrors the SVG/CSS matrix transform function.

Parameters:

NameTypeType DescriptionDescription
aReal Number

top left entry

bReal Number

middle left entry

cReal Number

top center entry

dReal Number

middle center entry

eReal Number

top right entry

fReal Number

middle right entry

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

matrix3d

matrix(a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4) specifies a transformation matrix

[a1a2a3a4b1b2b3b4c1c2c3c4d1d2d3d4].\left[ \begin{array}{cccc} a1 & a2 & a3 & a4 \\ b1 & b2 & b3 & b4 \\ c1 & c2 & c3 & c4 \\ d1 & d2 & d3 & d4 \end{array} \right].

This function mirrors the CSS matrix3d transform function.

Parameters:

NameTypeType DescriptionDescription
a1Real Number

1st column of 1st row

b1Real Number

1st column of 2nd row

c1Real Number

1st column of 3rd row

d1Real Number

1st column of 4th row

a2Real Number

2nd column of 1st row

b2Real Number

2nd column of 2nd row

c2Real Number

2nd column of 3rd row

d2Real Number

2nd column of 4th row

a3Real Number

3rd column of 1st row

b3Real Number

3rd column of 2nd row

c3Real Number

3rd column of 3rd row

d3Real Number

3rd column of 4th row

a4Real Number

4th column of 1st row

b4Real Number

4th column of 2nd row

c4Real Number

4th column of 3rd row

d4Real Number

4th column of 4th row

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

rotate

rotate(theta, [x], [y]) returns a counter-clockwise 2D rotation by an angle θ\theta, optionally around the point (x,y)(x,y). If no point is specified, the rotation is around the origin. Since this transformation is in general an affine transformation, it is encoded in homogeneous coordinates via the 3×33 \times 3 matrix

[cos(θ)sin(θ)0sin(θ)cos(θ)0001].\left[ \begin{array}{rrr} \cos(\theta) & -\sin(\theta) & 0 \\ \sin(\theta) & \cos(\theta) & 0 \\ 0 & 0 & 1 \end{array} \right].

For the 2×22 \times 2 linear version, see rotate2d().)

Parameters:

NameTypeType DescriptionDescription
thetaReal Number

angle of rotation (in radians)

xReal Number

center of rotation (x coordinate)

yReal Number

center of rotation (y coordinate)

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

rotate2d

rotate2d(theta) returns a 2D rotation around the origin by a given angle θ\theta, encoded via the 2×22 \times 2 matrix

[cos(θ)sin(θ)sin(θ)cos(θ)].\left[ \begin{array}{rr} \cos(\theta) & -\sin(\theta) \\ \sin(\theta) & \cos(\theta) \end{array} \right].

This matrix cannot directly be composed with 2D affine transformations; for the 3×33 \times 3 affine version, see rotate().

Parameters:

NameTypeType DescriptionDescription
thetaReal Number

angle of rotation (in radians)

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

rotate3d

rotate3d(theta, v) returns a 3D rotation by an angle θ\theta around a unit axis vv. The matrix is constructed via Rodrigues' rotation formula

I+sin(θ)v^+(1cos(θ))v^2,I + \sin(\theta)\hat{v} + (1-\cos(\theta))\hat{v}^2,

where II is the 3×33 \times 3 identity matrix, and v^\hat{v} is the cross product matrix associated with vv (see crossProductMatrix()). This matrix cannot directly be composed with 3D affine transformations; for the 4×44 \times 4 affine version, see rotate3dh().

Parameters:

NameTypeType DescriptionDescription
thetaReal Number

angle of rotation (in radians)

vℝⁿVector of Reals

axis of rotation (unit vector)

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

rotate3dh

rotate3dh(theta, v) returns a 3D rotation by a given angle θ\theta around a unit axis vv. This transformation is encoded as a 4×44 \times 4 matrix in homogeneous coordinates, so that it can be composed with 3D affine transformations. For the 3×33 \times 3 linear version, see rotate3d().

Parameters:

NameTypeType DescriptionDescription
thetaReal Number

angle of rotation (in radians)

vℝⁿVector of Reals

axis of rotation (unit vector)

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

scale

scale(sx, sy) returns a nonuniform scaling by factors sxs_x, sys_y along xx, yy axes, encoded via the matrix

[sx000sy0001].\left[ \begin{array}{ccc} s_x & 0 & 0 \\ 0 & s_y & 0 \\ 0 & 0 & 1 \end{array} \right].

This transformation is encoded as a 3×33 \times 3 matrix in homogeneous coordinates, so that it can be composed with 2D affine transformations. For the 2×22 \times 2 linear version, see scale2d().

Parameters:

NameTypeType DescriptionDescription
sxReal Number

horizontal scale factor

syReal Number

vertical scale factor

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

scale2d

scale2d(sx,sy) returns a 2×22 \times 2 matrix representing nonuniform scaling by factors sxs_x, sys_y along xx, yy axes, encoded via the matrix

[sx00sy].\left[ \begin{array}{cc} s_x & 0 \\ 0 & s_y \end{array} \right].

This transformation is encoded as a 2×22 \times 2 matrix that cannot directly be composed with 2D affine transformations. For the 3×33 \times 3 affine version, see rotate().

Parameters:

NameTypeType DescriptionDescription
sxReal Number

horizontal scale factor

syReal Number

vertical scale factor

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

scale3d

scale3d(sx, sy, sz) returns a nonuniform scaling by factors sxs_x, sys_y, szs_z along xx, yy, zz axes, via the matrix

[sx000sy000sz].\left[ \begin{array}{ccc} s_x & 0 & 0 \\ 0 & s_y & 0 \\ 0 & 0 & s_z \end{array} \right].

This transformation is encoded as a 3×33 \times 3 matrix that cannot directly be composed with 3D affine transformations. For the 4×44 \times 4 affine version, see scale3dh().

Parameters:

NameTypeType DescriptionDescription
sxReal Number

x scale factor

syReal Number

y scale factor

szReal Number

z scale factor

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

scale3dh

scale3dh(sx, sy, sz) returns a 4×44 \times 4 matrix representing nonuniform scaling by factors sxs_x, sys_y, szs_z along xx, yy, zz axes, via the matrix

[sx0000sy0000sz00001].\left[ \begin{array}{cccc} s_x & 0 & 0 & 0 \\ 0 & s_y & 0 & 0 \\ 0 & 0 & s_z & 0 \\ 0 & 0 & 0 & 1 \end{array} \right].

This transformation is encoded as a 4×44 \times 4 matrix in homogeneous coordinates, so that it can be composed with 3D affine transformations. For the 3×33 \times 3 linear version, see scale3D().

Parameters:

NameTypeType DescriptionDescription
sxReal Number

x scale factor

syReal Number

y scale factor

szReal Number

z scale factor

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

skew

skew(a_x, a_y) takes angles axa_x and aya_y, and returns a 2D skew transformation encoded by the matrix

[1tan(ax)0tan(ay)10001].\left[ \begin{array}{ccc} 1 & \tan(a_x) & 0 \\ \tan(a_y) & 1 & 0 \\ 0 & 0 & 1 \end{array} \right].

If aya_y is not defined, its default value is 0, resulting in a purely horizontal skewing. This transformation is encoded as a 3×33 \times 3 matrix in homogeneous coordinates, so that it can be composed with affine transformations. For the linear version, see skew2d().

Parameters:

NameTypeType DescriptionDescription
axReal Number

horizontal angle

ayReal Number

vertical angle

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

skew2d

skew2d(a_x, a_y) takes angles axa_x and aya_y, and returns a 2D skew transformation encoded via the matrix

[1tan(ax)tan(ay)1].\left[ \begin{array}{cc} 1 & \tan(a_x) \\ \tan(a_y) & 1 \end{array} \right].

If aya_y is not defined, its default value is 0, resulting in a purely horizontal skewing. This transformation is encoded as a 2×22 \times 2 matrix that cannot directly be composed with 2D affine transformations. For the 3×33 \times 3 affine version, see skew().

Parameters:

NameTypeType DescriptionDescription
axReal Number

horizontal angle

ayReal Number

vertical angle

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

shear

shear(u,v) takes two nn-dimensional vectors uu and vv, and returns a transformation that shears any given point xx in the direction uu according to its extent along the direction vv, i.e., that performs the transformation

xx+v,xu.x \mapsto x + \langle v,x \rangle u.

This transformation is encoded as an (n+1)×(n+1)(n+1) \times (n+1) matrix in homogeneous coordinates, so that it can be composed with affine transformations. For the linear version, see shear2d() or shear3d().

Parameters:

NameTypeType DescriptionDescription
uℝⁿVector of Reals

offset direction

vℝⁿVector of Reals

shear axis

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

shear2d

shear2d(u,v) takes two 2-dimensional vectors uu and vv, and returns a transformation that shears any given point xx in the direction uu according to its extent along the direction vv, i.e., that performs the transformation

xx+v,xu.x \mapsto x + \langle v,x \rangle u.

This transformation is encoded as a 2×22 \times 2 matrix that cannot directly be composed with 2-dimensional affine transformations. For the affine version, see shear().

Parameters:

NameTypeType DescriptionDescription
uℝⁿVector of Reals

offset direction

vℝⁿVector of Reals

shear axis

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

shear3d

shear3d(u,v) takes two 3-dimensional vectors uu and vv, returns a transformation that shears any given point xx in the direction uu according to its extent along the direction vv, i.e., that performs the transformation

xx+v,xu.x \mapsto x + \langle v,x \rangle u.

This transformation is encoded as a 3×33 \times 3 matrix that cannot directly be composed with 3-dimensional affine transformations. For the affine version, see shear().

Parameters:

NameTypeType DescriptionDescription
uℝⁿVector of Reals

offset direction

vℝⁿVector of Reals

shear axis

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

translate

translate(x,y) returns a translation by the given offset (x,y)(x,y). If yy is not specified, it is assumed to be 00. Since translation is affine rather than linear, it is encoded as a 3×33 \times 3 matrix in homogeneous coordinates, namely

T=[10x01y001].T = \left[ \begin{array}{ccc} 1 & 0 & x \\ 0 & 1 & y \\ 0 & 0 & 1 \end{array} \right].

Parameters:

NameTypeType DescriptionDescription
xReal Number

horizontal offset

yReal Number

vertical offset

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

translate3dh

translate3dh(x,y,z) returns a translation by (x,y,z)(x,y,z). Since translation is affine rather than linear, it is encoded as a 4×44 \times 4 matrix in homogeneous coordinates, namely

T=[100x010y000z0001].T = \left[ \begin{array}{cccc} 1 & 0 & 0 & x \\ 0 & 1 & 0 & y \\ 0 & 0 & 0 & z \\ 0 & 0 & 0 & 1 \end{array} \right].

Parameters:

NameTypeType DescriptionDescription
xReal Number

x offset

yReal Number

y offset

zReal Number

z offset

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

lookAt

lookAt(eye, center, up) returns a 4×44 \times 4 viewing matrix derived from an eye point ee, a reference point cc indicating the center of the scene, and an up vector uu. The matrix maps the reference point to the negative z axis and the eye point to the origin. When a typical projection matrix is used, the center of the scene therefore maps to the center of the viewport. Similarly, the direction described by the up vector projected onto the viewing plane is mapped to the positive y axis so that it points upward in the viewport. The up vector must not be parallel to the line of sight from the eye point to the reference point. The matrix is given explicitly by V=MTV = MT where TT is a translation by e-e (a la translate3dh), and MM is given by

M=[s1s2s30v1v2v30f1f2f300001],M = \left[ \begin{array}{rrrc} s_1 & s_2 & s_3 & 0 \\ v_1 & v_2 & v_3 & 0 \\ -f_1 & -f_2 & -f_3 & 0 \\ 0 & 0 & 0 & 1 \end{array} \right],

where f:=(ce)/cef := (c-e)/|c-e| is the unit vector from the eye to the center, s=f×us = f \times u is a vector pointing to the side, and v=s×fv = s \times f is a vector in roughly the same direction as uu that completes an orthonormal basis with ss and ff (hence, MM is a rotation matrix).

Parameters:

NameTypeType DescriptionDescription
eyeℝⁿVector of Reals

position of the eye point

centerℝⁿVector of Reals

position of the reference point

upℝⁿVector of Reals

unit vector in the upward direction

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

perspective

perspective(fovy, aspect, [zNear], [zFar]) returns a 4×44 \times 4 perspective projection matrix, given a vertical field of view θy\theta_y, an aspect ratio aa, and optional near/far zz-values, z0z_0 and z1z_1. The aspect ratio should match the aspect ratio of the associated viewport. For example, an aspect ratio of 2 means the viewer's angle of view is twice as wide in xx as it is in yy. Coordinates within [z0,z1][z_0,z_1] will get mapped to depth values in the range [0,1][0,1]. Letting f:=cot(θy/2)f := \cot(\theta_y/2), the perspective matrix is given by

P=[f/a0000f0000z0+z1z0z12z0z1z0z10010].P = \left[ \begin{array}{cccc} f/a & 0 & 0 & 0 \\ 0 & f & 0 & 0 \\ 0 & 0 & \frac{z_0+z_1}{z_0-z_1} & \frac{2 z_0 z_1}{z_0 - z_1} \\ 0 & 0 & -1 & 0 \end{array} \right].

Parameters:

NameTypeType DescriptionDescription Default Value
fovyReal Number

field of view angle, in degrees, in the y direction

aspectReal Number

aspect ratio that determines the field of view in the x direction, equal to the ratio of x (width) to y (height)

zNearReal Number

distance from the viewer to the near clipping plane (always positive), with a default value of 0.1

0.1
zFarReal Number

distance from the viewer to the far clipping plane (always positive), with a default value of 100.0

100

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

ortho

ortho(left, right, bottom, top, [zNear], [zFar]) returns a 4×44 \times 4 transformation that produces a parallel projection, given four horizontal/vertical clipping planes, and an optional near/far clipping plane. Letting ll, rr, bb, and tt denote the left/right/bottom/top clipping planes, respectively, the projection matrix is given by

P=[2rl00ux02tb0uy002z1z0uz0001],P = \left[ \begin{array}{cccc} \frac{2}{r-l} & 0 & 0 & -u_x \\ 0 & \frac{2}{t-b} & 0 & -u_y \\ 0 & 0 & \frac{-2}{z_1-z_0} & -u_z \\ 0 & 0 & 0 & 1 \\ \end{array} \right],

where

ux=(r+l)/(rl),uy=(t+b)/(tb),uz=(z1+z0)/(z1z0).\begin{array}{rcl} u_x &=& (r + l) / (r - l), \\ u_y &=& (t + b) / (t - b), \\ u_z &=& (z_1 + z_0) / (z_1 - z_0). \end{array}

Parameters:

NameTypeType DescriptionDescription Default Value
LeftReal Number

coordinate of the left vertical clipping plane

RightReal Number

coordinate of the right vertical clipping plane

BottomReal Number

coordinate of the bottom horizontal clipping plane

TopReal Number

coordinate of the top horizontal clipping plane

zNearReal Number

distance to the nearer depth clipping plane (negative if the plane is behind the viewer), with a default value of 0.1

0.1
zFarReal Number

distance to the farther depth clipping plane (negative if the plane is behind the viewer), with a default value of 100

100

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

project

project(p, model, proj, view) transforms the specified 3D object coordinates pp into 2D window coordinates qq using a given 4×44 \times 4 model transformation MM, 4×44 \times 4 projection transformation PP, and viewport V=[xywh]V = [ \begin{array}{cccc} x & y & w & h \end{array} ], where xx, yy give the lower-left corner of the canvas, and ww, hh are its width and height. To also recover the depth, see projectDepth(). The projection is performed by first computing r:=PMp^r := PM\hat{p}, where p^:=(p,1)\hat{p} := (p,1) are the homogeneous coordinates for pp. The first two components of q:=r/rwq := r/r_w (where rwr_w is the final component of rr) gives coordinates in the range [1,1]×[1,1][-1,1] \times [-1,1], which are then stretched to the range [x,x+w]×[y,y+h][x,x+w] \times [y,y+h].

Parameters:

NameTypeType DescriptionDescription
pℝⁿVector of Reals

3D object coordinates (x,y,z)

model(ℝⁿ)ᵐList of Real Vectors

4x4 modelview matrix

proj(ℝⁿ)ᵐList of Real Vectors

4x4 projection matrix

viewℝⁿVector of Reals

viewport (x, y, width, height)

Returns: ℝⁿ (Vector of Reals)

projectDepth

projectDepth(p, model, proj, view) transforms the specified 3D object coordinates pp into 2D window coordinates qq using a given 4×44 \times 4 model transformation MM, 4×44 \times 4 projection transformation PP, and viewport V=[xywh]V = [ \begin{array}{cccc} x & y & w & h \end{array} ], where xx, yy give the lower-left corner of the canvas, and ww, hh are its width and height. It returns the projected coordinates, as well as the depth relative to the view. See project() for further information.

Parameters:

NameTypeType DescriptionDescription
pℝⁿVector of Reals

3D object coordinates (x,y,z)

model(ℝⁿ)ᵐList of Real Vectors

4x4 modelview matrix

proj(ℝⁿ)ᵐList of Real Vectors

4x4 projection matrix

viewℝⁿVector of Reals

viewport (x, y, width, height)

Returns: ℝⁿ (Vector of Reals)

projectList

projectList(P, model, proj, view) transforms a list of 3D object coordinates P=p1,,pkP = p_1, \ldots, p_k into window 2D coordinates using a given 4×44 \times 4 model transformation MM, 4×44 \times 4 projection transformation PP, and viewport V=[xywh]V = [ \begin{array}{cccc} x & y & w & h \end{array} ], where xx, yy give the lower-left corner of the canvas, and ww, hh are its width and height. Returns the list of projected 2D coordinates q1,,qkq_1, \ldots, q_k. See project() for further information.

Parameters:

NameTypeType DescriptionDescription
p(ℝⁿ)ᵐList of Real Vectors

list of 3D object coordinates (x,y,z)

model(ℝⁿ)ᵐList of Real Vectors

4x4 modelview matrix

proj(ℝⁿ)ᵐList of Real Vectors

4x4 projection matrix

viewℝⁿVector of Reals

viewport (x, y, width, height)

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

matrixMultiplyList

matrixMultiplyList(A, V) multiplies each vector v1,,vkv_1, \ldots, v_k in the list VV by the given n×nn \times n matrix AA, returning the list of products. List elements must all be vectors of length nn.

Parameters:

NameTypeType DescriptionDescription
A(ℝⁿ)ᵐList of Real Vectors

nxn matrix

V(ℝⁿ)ᵐList of Real Vectors

list of n-dimensional vectors

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

fromHomogeneous

fromHomogeneous(q) takes a vector qq of length n+1n+1, encoding a point in nn-dimensional homogeneous coordinates, and returns a vector pp of length nn, encoding the same point in Cartesian coordinates, i.e,. p=(q1,,qk1)/qkp = (q_1, \ldots, q_{k-1})/q_k.

Parameters:

NameTypeType DescriptionDescription
qℝⁿVector of Reals

homogeneous coordinates

Returns: ℝⁿ (Vector of Reals)

fromHomogeneousList

fromHomogeneousList(Q) takes a list Q=q1,,qkQ = q_1, \ldots, q_k of vectors of length n+1n+1, encoding points in nn-dimensional homogeneous coordinates, and returns a list P=p1,,pkP = p_1, \ldots, p_k of vectors of length nn, encoding the same points in Cartesian coordinates.

Parameters:

NameTypeType DescriptionDescription
Q(ℝⁿ)ᵐList of Real Vectors

list of points in homogeneous coordinates

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

toHomogeneous

toHomogeneous(p) takes a vector pp of length nn, encoding a point in nn-dimensional Cartesian coordinates, and returns a vector qq of length n+1n+1, encoding the same point in homogeneous coordinates, i.e., q=(p,1)q = (p,1).

Parameters:

NameTypeType DescriptionDescription
pℝⁿVector of Reals

Cartesian coordinates

Returns: ℝⁿ (Vector of Reals)

toHomogeneousList

toHomogeneousList(P) takes a list P=p1,,pkP = p_1, \ldots, p_k of vectors of length nn, encoding points in nn-dimensional Cartesian coordinates, and returns a list Q=q1,,qkQ = q_1, \ldots, q_k of vectors of length n+1n+1, encoding the same points in homogeneous coordinates.

Parameters:

NameTypeType DescriptionDescription
P(ℝⁿ)ᵐList of Real Vectors

list of points in Cartesian coordinates

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

toHomogeneousMatrix

toHomogeneousMatrix(A) takes a square n×nn \times n matrix AA representing a spatial transformation in AA dimensions, and returns an (n+1)×(n+1)(n+1) \times (n+1) matrix representing the same transformation in homogeneous coordinates.

Parameters:

NameTypeType DescriptionDescription
A(ℝⁿ)ᵐList of Real Vectors

matrix encoding linear transformation

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

length

Return the length of the Line shape.

Parameters:

NameTypeType DescriptionDescription
lLineShapeLine Shape

A line

Returns: ℝ (Real Number)

normalize

Return the normalized version of vector v.

Parameters:

NameTypeType DescriptionDescription
vℝⁿVector of Reals

Vector 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 Type

Path Type

pts(ℝ²)ⁿList of 2d Real Vectors

List 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 Type

Path Type

pts(ℝ²)ⁿList of 2d Real Vectors

List 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 Type

Path Type

p0ℝ²2d Vector of Reals

First point

p1ℝ²2d Vector of Reals

Second point

p2ℝ²2d Vector of Reals

Third 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 Type

Path type

pts(ℝ²)ⁿList of 2d Real Vectors

List of points

Returns: PathCmd (Path Command)

Penrose

Return path data describing an "impossible polygon."

Parameters:

NameTypeType DescriptionDescription Default Value
centerℝⁿVector of Reals

(x,y) translation

[ 0, 0 ]
radiusReal Number

radius of outer polygon (must be positive)

50
holeSizeReal Number

radius of inner polygon as a fraction of the outer radius (in range (0,1])

0.35
angleReal Number

angle of rotation

0
nSidesℤ⁺Positive Integer

number of sides (integer ≥ 3)

5
chiralityStringString

either "cw" for clockwise, or "ccw" for counterclockwise

ccw

Returns: PathCmd (Path Command)

firstPoint

Returns the first point in a list.

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectors

list of points

Returns: ℝ² (2d Vector of Reals)

lastPoint

Returns the last point in a list.

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectors

list of points

Returns: ℝ² (2d Vector of Reals)

averagePoint

Returns the average (mean) of all points in a list.

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectors

list of points

Returns: ℝⁿ (Vector of Reals)

interpolatingSpline

Returns path data for a curve that smoothly interpolates the given points. Interpolation is performed via a Catmull-Rom spline.

Parameters:

NameTypeType DescriptionDescription Default Value
pathType"open" | "closed"Path Type

either "open" or "closed."

points(ℝⁿ)ᵐList of Real Vectors

points to be interpolated

tensionReal Number

smoothness of curve (0=piecewise linear, .25=default)

0.25

Returns: PathCmd (Path Command)

diffusionProcess

Return n points sampled from a diffusion process starting at X0, with covariance matrix A and constant drift omega. This path approximately integrates the stochastic differential equation dX_t = omega dt + A dW_t, where W_t is a Wiener process.

Parameters:

NameTypeType DescriptionDescription
nℤ⁺Positive Integer

number of points

X0ℝ²2d Vector of Reals

starting location

A(ℝⁿ)ᵐList of Real Vectors

covariance matrix

omegaℝ²2d Vector of Reals

drift direction

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

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 Type

The 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 Reals

coordinate to start drawing the arc

endℝ²2d Vector of Reals

coordinate to finish drawing the arc

[width, height]ℝ²2d Vector of Reals

width and height of the ellipse to draw the arc along

rotationReal Number

angle in degrees to rotate ellipse about its center

largeArcReal Number

0 to draw shorter of 2 arcs, 1 to draw longer

arcSweepReal Number

0 to rotate CCW, 1 to rotate CW

Returns: PathCmd (Path Command)

circularArc

Return path data that describes a circular arc. The arc is equivalent to the parametric curve center + r*(cos(t),sin(t)) for t in the range [theta0,theta1]. More general arcs (e.g., along an ellipse) can be drawn using arc().

Parameters:

NameTypeType DescriptionDescription
pathType"open" | "closed"Path Type

The path type: either "open" or "closed." whether the SVG should automatically draw a line between the final point and the start point

centerℝ²2d Vector of Reals

circle center

rReal Number

circle radius

theta0Real Number

start angle in radians

theta1Real Number

end angle in radians

Returns: PathCmd (Path Command)

repeatedArcs

Generate multiple concentric arcs. Useful for denoting equal angles.

Parameters:

NameTypeType DescriptionDescription
innerStartℝ²2d Vector of Reals

coordinate to start drawing the inner arc

innerEndℝ²2d Vector of Reals

coordinate to end the inner arc

outerStartℝ²2d Vector of Reals

coordinate to start drawing the outer arc

outerEndℝ²2d Vector of Reals

coordinate to end the outer arc

innerRadiusℝ²2d Vector of Reals

radii of the ellipse to draw the inner arc along (width, height)

repeatℤ⁺Positive Integer

number of times to repeat the arc

spacingReal Number

spacing between arcs

arcSweepReal Number

arc 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 Reals

center of the circle on which the arc sits

startℝ²2d Vector of Reals

coordinate to start drawing the arc

endℝ²2d Vector of Reals

coordinate to finish drawing the arc

radiusℝ²2d Vector of Reals

width and height of the ellipse to draw the arc along (i.e. [width, height])

rotationReal Number

angle in degrees to rotate ellipse about its center

largeArcReal Number

0 to draw shorter of 2 arcs, 1 to draw longer

arcSweepReal Number

0 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 Reals

start point of line segment

p2ℝⁿVector of Reals

endpoint of line segment

rReal Number

distance 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 Reals

x, y coordinates of the circle/ellipse that the arc is drawn on

startℝ²2d Vector of Reals

start point of the arc

endℝ²2d Vector of Reals

end 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 Reals

A vector

vℝⁿVector of Reals

A 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 Reals

A vector

vℝⁿVector of Reals

A 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 Reals

A vector

vℝ²2d Vector of Reals

A vector

Returns: ℝ (Real Number)

cross

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

Parameters:

NameTypeType DescriptionDescription
uℝ³3d Vector of Reals

A vector

vℝ³3d Vector of Reals

A 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 Reals

First point of first line

a1ℝ²2d Vector of Reals

Second point of first line

b0ℝ²2d Vector of Reals

First point of second line

b1ℝ²2d Vector of Reals

Second 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 Reals

First point

endℝⁿVector of Reals

Second 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 Shape

A line

paddingReal Number

Padding 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 Shape

A line

paddingReal Number

Length 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 Reals

First point

pt2ℝ²2d Vector of Reals

Second point

pt3ℝ²2d Vector of Reals

Third point

paddingReal Number

Offset 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 Reals

starting point of a line

pt2ℝ²2d Vector of Reals

ending point of a line

spacingReal Number

space in px between each tick

numTicksℤ⁺Positive Integer

number of tick marks to create

tickLengthReal Number

1/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 Shape

First line segment

s2LineShapeLine Shape

Second line segment

intersectionℝ²2d Vector of Reals

Point of intersection

lenReal Number

Side 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 Shape

First line

l2LineShapeLine Shape

Second line

l3LineShapeLine Shape

Third 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 Number

minimum value

maxValReal Number

maximum 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 Reals

First vertex

bℝ²2d Vector of Reals

Second vertex

cℝ²2d Vector of Reals

Third 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 Interval

Opacity

colorType"rgb" | "hsv"Color Type

Color model

Returns: Color (Color)

randomIndex

Uniformly sample a random integer value in the range from minIndex to maxIndex.

Parameters:

NameTypeType DescriptionDescription
minIndexReal Number

minimum index

maxIndexReal Number

maximum index

Returns: ℤ⁺ (Positive Integer)

setOpacity

Set the opacity of a color color to frac.

Parameters:

NameTypeType DescriptionDescription
colorColorColor

Color

frac[0,1]Real Number in Unit Interval

Opacity

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 Vectors

A matrix

vℝⁿVector of Reals

A vector

Returns: ℝⁿ (Vector of Reals)

barycenter

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

Parameters:

NameTypeType DescriptionDescription
aℝ²2d Vector of Reals

First vertex

bℝ²2d Vector of Reals

Second vertex

cℝ²2d Vector of Reals

Third 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 Reals

First vertex

qℝ²2d Vector of Reals

Second vertex

rℝ²2d Vector of Reals

Third 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 Reals

First vertex

qℝ²2d Vector of Reals

Second vertex

rℝ²2d Vector of Reals

Third vertex

Returns: ℝ (Real Number)

incenter

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

Parameters:

NameTypeType DescriptionDescription
pℝ²2d Vector of Reals

First vertex

qℝ²2d Vector of Reals

Second vertex

rℝ²2d Vector of Reals

Third 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 Reals

First vertex

qℝ²2d Vector of Reals

Second vertex

rℝ²2d Vector of Reals

Third 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 Reals

A vector

Returns: ℝ (Real Number)

normsq

Return the Euclidean norm squared of the vector v.

Parameters:

NameTypeType DescriptionDescription
vℝⁿVector of Reals

A vector

Returns: ℝ (Real Number)

vdist

Return the Euclidean distance between the vectors v and w.

Parameters:

NameTypeType DescriptionDescription
vℝⁿVector of Reals

A vector

wℝⁿVector of Reals

A vector

Returns: ℝ (Real Number)

vmul

Returns the scalar-vector product.

Parameters:

NameTypeType DescriptionDescription
sReal Number

A scalar

vℝⁿVector of Reals

A vector

Returns: ℝⁿ (Vector of Reals)

vdistsq

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

Parameters:

NameTypeType DescriptionDescription
vℝⁿVector of Reals

A vector

wℝⁿVector of Reals

A vector

Returns: ℝ (Real Number)

angleOf

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

Parameters:

NameTypeType DescriptionDescription
vℝⁿVector of Reals

A 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 Reals

A vector

Returns: ℝ² (2d Vector of Reals)

rotateBy

Rotate a 2D vector v by theta degrees counterclockwise.

Parameters:

NameTypeType DescriptionDescription
vℝ²2d Vector of Reals

A vector

thetaReal Number

degrees 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 Shape

A shape

pℝ²2d Vector of Reals

A point

Returns: ℝ (Real Number)

signedDistanceRect

Returns the distance between a rect and a point

Parameters:

NameTypeType DescriptionDescription
rect(ℝ²)ⁿList of 2d Real Vectors
ptℝ²2d Vector of Reals

Returns: ℝ (Real Number)

signedDistanceCircle

Returns the distance between a circle and a point

Parameters:

NameTypeType DescriptionDescription
cℝ²2d Vector of Reals

center of circle

rReal Number

radius of circle

ptℝ²2d Vector of Reals

the point

Returns: ℝ (Real Number)

signedDistancePolygon

Returns the distance between a polygon and a point

Parameters:

NameTypeType DescriptionDescription
pts(ℝ²)ⁿList of 2d Real Vectors

points of the polygon

ptℝ²2d Vector of Reals

the point

Returns: ℝ (Real Number)

signedDistanceEllipse

Returns the distance between an ellipse and a point

Parameters:

NameTypeType DescriptionDescription
cℝ²2d Vector of Reals

center of ellipse

rxReal Number

horizontal radius of ellipse

ryReal Number

vertical radius of ellipse

ptℝ²2d Vector of Reals

the point

Returns: ℝ (Real Number)

signedDistanceLine

Returns the distance between a line and a point

Parameters:

NameTypeType DescriptionDescription
startℝ²2d Vector of Reals

start of line

endℝ²2d Vector of Reals

end of line

ptℝ²2d Vector of Reals

the point

Returns: ℝ (Real Number)

signedDistancePolyline

Returns the distance between a line and a polyline

Parameters:

NameTypeType DescriptionDescription
pts(ℝ²)ⁿList of 2d Real Vectors

points of the polyline

ptℝ²2d Vector of Reals

the point

Returns: ℝ (Real Number)

signedDistanceGroup

Returns the signed distance between a group of shapes and a point

Parameters:

NameTypeType DescriptionDescription
shapesShape[]List of shapes
ptℝ²2d Vector of Reals

Returns: ℝ (Real Number)

unitVector

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

Parameters:

NameTypeType DescriptionDescription
thetaReal Number

direction

Returns: ℝ² (2d Vector of Reals)

rayIntersect

Given a point p and vector v, find the first point where the ray r(t)=p+tv intersects the given shape S. If there are no intersections, returns p.

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 Shape

A shape

pℝ²2d Vector of Reals

A point

vℝ²2d Vector of Reals

A vector

Returns: ℝ² (2d Vector of Reals)

rayIntersectDistance

Given a point p and vector v, returns the distance to the first point where the ray r(t)=p+tv intersects the shape S. If there are no intersections, returns Infinity.

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 Shape

A shape

pℝ²2d Vector of Reals

A point

vℝ²2d Vector of Reals

A vector

Returns: ℝ (Real Number)

rayIntersectCircle

Parameters:

NameTypeType DescriptionDescription
cℝ²2d Vector of Reals

center of circle

rReal Number

radius of circle

pℝ²2d Vector of Reals

A point

vℝ²2d Vector of Reals

A vector

Returns: ℝ² (2d Vector of Reals)

rayIntersectCircleDistance

Parameters:

NameTypeType DescriptionDescription
cℝ²2d Vector of Reals

center of circle

rReal Number

radius of circle

pℝ²2d Vector of Reals

A point

vℝ²2d Vector of Reals

A vector

Returns: ℝ (Real Number)

rayIntersectEllipse

Parameters:

NameTypeType DescriptionDescription
cℝ²2d Vector of Reals
rxReal Number
ryReal Number
pℝ²2d Vector of Reals

A point

vℝ²2d Vector of Reals

A vector

Returns: ℝ² (2d Vector of Reals)

rayIntersectEllipseDistance

Parameters:

NameTypeType DescriptionDescription
cℝ²2d Vector of Reals
rxReal Number
ryReal Number
pℝ²2d Vector of Reals

A point

vℝ²2d Vector of Reals

A vector

Returns: ℝ (Real Number)

rayIntersectLine

Parameters:

NameTypeType DescriptionDescription
startℝ²2d Vector of Reals
endℝ²2d Vector of Reals
pℝ²2d Vector of Reals

A point

vℝ²2d Vector of Reals

A vector

Returns: ℝ² (2d Vector of Reals)

rayIntersectLineDistance

Parameters:

NameTypeType DescriptionDescription
startℝ²2d Vector of Reals
endℝ²2d Vector of Reals
pℝ²2d Vector of Reals

A point

vℝ²2d Vector of Reals

A vector

Returns: ℝ (Real Number)

rayIntersectRect

Parameters:

NameTypeType DescriptionDescription
rect(ℝ²)ⁿList of 2d Real Vectors

The top-right, top-left, bottom-left, bottom-right points (in that order) of the rectangle

pℝ²2d Vector of Reals

A point

vℝ²2d Vector of Reals

A vector

Returns: ℝ² (2d Vector of Reals)

rayIntersectRectDistance

Parameters:

NameTypeType DescriptionDescription
rect(ℝ²)ⁿList of 2d Real Vectors

The top-right, top-left, bottom-left, bottom-right points (in that order) of the rectangle

pℝ²2d Vector of Reals

A point

vℝ²2d Vector of Reals

A vector

Returns: ℝ (Real Number)

rayIntersectPoly

Parameters:

NameTypeType DescriptionDescription
pts(ℝ²)ⁿList of 2d Real Vectors
closedtrue | falseBoolean Value
pℝ²2d Vector of Reals

A point

vℝ²2d Vector of Reals

A vector

Returns: ℝ² (2d Vector of Reals)

rayIntersectPolyDistance

Parameters:

NameTypeType DescriptionDescription
pts(ℝ²)ⁿList of 2d Real Vectors
closedtrue | falseBoolean Value
pℝ²2d Vector of Reals

A point

vℝ²2d Vector of Reals

A vector

Returns: ℝ (Real Number)

rayIntersectGroup

Parameters:

NameTypeType DescriptionDescription
shapesShape[]List of shapes
pℝ²2d Vector of Reals

A point

vℝ²2d Vector of Reals

A vector

Returns: ℝ² (2d Vector of Reals)

rayIntersectGroupDistance

Parameters:

NameTypeType DescriptionDescription
shapesShape[]List of shapes
pℝ²2d Vector of Reals

A point

vℝ²2d Vector of Reals

A vector

Returns: ℝ (Real Number)

rayIntersectNormal

Given a point p and vector v, find the unit normal at the first point where the ray r(t)=p+tv intersects the given shape S. If there are no intersections, returns (0,0).

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 Shape

A shape

pℝ²2d Vector of Reals

A point

vℝ²2d Vector of Reals

A vector

Returns: ℝ² (2d Vector of Reals)

rayIntersectNormalCircle

Parameters:

NameTypeType DescriptionDescription
cℝ²2d Vector of Reals

center of circle

rReal Number

radius of circle

pℝ²2d Vector of Reals

A point

vℝ²2d Vector of Reals

A vector

Returns: ℝ² (2d Vector of Reals)

rayIntersectNormalEllipse

Parameters:

NameTypeType DescriptionDescription
cℝ²2d Vector of Reals
rxReal Number
ryReal Number
pℝ²2d Vector of Reals

A point

vℝ²2d Vector of Reals

A vector

Returns: ℝ² (2d Vector of Reals)

rayIntersectNormalLine

Parameters:

NameTypeType DescriptionDescription
startℝ²2d Vector of Reals
endℝ²2d Vector of Reals
pℝ²2d Vector of Reals

A point

vℝ²2d Vector of Reals

A vector

Returns: ℝ² (2d Vector of Reals)

rayIntersectNormalRect

Parameters:

NameTypeType DescriptionDescription
rect(ℝ²)ⁿList of 2d Real Vectors

The top-right, top-left, bottom-left, bottom-right points (in that order) of the rectangle

pℝ²2d Vector of Reals

A point

vℝ²2d Vector of Reals

A vector

Returns: ℝ² (2d Vector of Reals)

rayIntersectNormalPoly

Parameters:

NameTypeType DescriptionDescription
pts(ℝ²)ⁿList of 2d Real Vectors
closedtrue | falseBoolean Value
pℝ²2d Vector of Reals

A point

vℝ²2d Vector of Reals

A vector

Returns: ℝ² (2d Vector of Reals)

rayIntersectNormalGroup

Parameters:

NameTypeType DescriptionDescription
shapesShape[]List of shapes
pℝ²2d Vector of Reals

A point

vℝ²2d Vector of Reals

A vector

Returns: ℝ² (2d Vector of Reals)

closestPoint

Returns a point on the shape s closest to a query point p. If this point is not unique, an arbitrary choice is made.

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 Shape

A shape

pℝ²2d Vector of Reals

A vector

Returns: ℝ² (2d Vector of Reals)

closestPointCircle

Parameters:

NameTypeType DescriptionDescription
cℝ²2d Vector of Reals

center of circle

rReal Number

radius of circle

ptℝ²2d Vector of Reals

the point

Returns: ℝ² (2d Vector of Reals)

closestPointRect

Parameters:

NameTypeType DescriptionDescription
rect(ℝ²)ⁿList of 2d Real Vectors

The top-right, top-left, bottom-left, bottom-right points (in that order) of the rectangle

ptℝ²2d Vector of Reals

the point

Returns: ℝ² (2d Vector of Reals)

closestPointLine

Parameters:

NameTypeType DescriptionDescription
startℝ²2d Vector of Reals

start point of line

endℝ²2d Vector of Reals

end point of line

ptℝ²2d Vector of Reals

the point

Returns: ℝ² (2d Vector of Reals)

closestPointEllipse

Parameters:

NameTypeType DescriptionDescription
cℝ²2d Vector of Reals

center of ellipse

rxReal Number

horizontal radius of ellipse

ryReal Number

vertical radius of ellipse

ptℝ²2d Vector of Reals

the point

Returns: ℝ² (2d Vector of Reals)

closestPointPoly

Parameters:

NameTypeType DescriptionDescription
pts(ℝ²)ⁿList of 2d Real Vectors

points of the polygon

closedtrue | falseBoolean Value

whether or not the polygon is closed

ptℝ²2d Vector of Reals

the point

Returns: ℝ² (2d Vector of Reals)

closestPointGroup

Parameters:

NameTypeType DescriptionDescription
shapesShape[]List of shapes

shapes of the group

ptℝ²2d Vector of Reals

the point

Returns: ℝ² (2d Vector of Reals)

closestSilhouettePoint

Returns a point on the visibility silhouette of shape s closest to a query point p. If this point is not unique, an arbitrary choice is made. If no such point exists, the query point p is returned.

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 Shape

A shape

pℝ²2d Vector of Reals

A point

Returns: ℝ² (2d Vector of Reals)

closestSilhouettePointCircle

Parameters:

NameTypeType DescriptionDescription
cℝ²2d Vector of Reals

center of circle

rReal Number

radius of circle

pℝ²2d Vector of Reals

A point

Returns: ℝ² (2d Vector of Reals)

closestSilhouettePointEllipse

Parameters:

NameTypeType DescriptionDescription
cℝ²2d Vector of Reals
rxReal Number
ryReal Number
pℝ²2d Vector of Reals

A point

Returns: ℝ² (2d Vector of Reals)

closestSilhouettePointLine

Parameters:

NameTypeType DescriptionDescription
startℝ²2d Vector of Reals
endℝ²2d Vector of Reals
pℝ²2d Vector of Reals

A point

Returns: ℝ² (2d Vector of Reals)

closestSilhouettePointRect

Parameters:

NameTypeType DescriptionDescription
rect(ℝ²)ⁿList of 2d Real Vectors

The top-right, top-left, bottom-left, bottom-right points (in that order) of the rectangle

pℝ²2d Vector of Reals

A point

Returns: ℝ² (2d Vector of Reals)

closestSilhouettePointPolyline

Parameters:

NameTypeType DescriptionDescription
points(ℝ²)ⁿList of 2d Real Vectors
pℝ²2d Vector of Reals

A point

Returns: ℝ² (2d Vector of Reals)

closestSilhouettePointPolygon

Parameters:

NameTypeType DescriptionDescription
points(ℝ²)ⁿList of 2d Real Vectors
pℝ²2d Vector of Reals

A point

Returns: ℝ² (2d Vector of Reals)

closestSilhouettePointGroup

Parameters:

NameTypeType DescriptionDescription
shapesShape[]List of shapes
pℝ²2d Vector of Reals

A point

Returns: ℝ² (2d Vector of Reals)

closestSilhouetteDistance

Returns the distance to the closest point on the visibility silhouette of shape s relative to query point p. If no such point exists, returns Infinity.

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 Shape

A shape

pℝ²2d Vector of Reals

A point

Returns: ℝ (Real Number)

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 Reals

bottom-left point of rectangle

topRightℝ²2d Vector of Reals

top-right point of rectangle

startℝ²2d Vector of Reals

start point of line

endℝ²2d Vector of Reals

end point of line

Returns: ℝ (Real Number)

shapeDistance

Return the distance between two shapes.

Parameters:

NameTypeType DescriptionDescription
s1ShapeAny Shape

a shape

s2ShapeAny Shape

a shape

Returns: ℝ (Real Number)

shapeDistanceCircles

Return the distance between two circles.

Parameters:

NameTypeType DescriptionDescription
c1ℝ²2d Vector of Reals

center of first circle

r1Real Number

radius of first circle

c2ℝ²2d Vector of Reals

center of second circle

r2Real Number

radius of second circle

Returns: ℝ (Real Number)

shapeDistanceRects

Return the distance between two rectangles.

Parameters:

NameTypeType DescriptionDescription
rect1(ℝ²)ⁿList of 2d Real Vectors

The top-right, top-left, bottom-left, bottom-right points (in that order) of the first rectangle.

rect2(ℝ²)ⁿList of 2d Real Vectors

The top-right, top-left, bottom-left, bottom-right points (in that order) of the second rectangle.

Returns: ℝ (Real Number)

shapeDistanceRectLine

Returns the distance between a rectangle and a line.

Parameters:

NameTypeType DescriptionDescription
rect(ℝ²)ⁿList of 2d Real Vectors

The top-right, top-left, bottom-left, bottom-right points (in that order) of the rectangle.

startℝ²2d Vector of Reals

The start point of the line

endℝ²2d Vector of Reals

The end point of the line

Returns: ℝ (Real Number)

shapeDistanceRectlikePolyline

Returns the distance between a rectangle and a polyline.

Parameters:

NameTypeType DescriptionDescription
rect(ℝ²)ⁿList of 2d Real Vectors

The top-right, top-left, bottom-left, bottom-right points (in that order) of the rectangle.

points(ℝⁿ)ᵐList of Real Vectors

points of polyline

Returns: ℝ (Real Number)

shapeDistancePolys

Returns the distance between two polygons.

Parameters:

NameTypeType DescriptionDescription
pts1(ℝ²)ⁿList of 2d Real Vectors

The list of points for the first polygon

pts2(ℝ²)ⁿList of 2d Real Vectors

The list of points for the second polygon

Returns: ℝ (Real Number)

shapeDistanceRectCircle

Returns the distance between a rectangle and a circle.

Parameters:

NameTypeType DescriptionDescription
rect(ℝ²)ⁿList of 2d Real Vectors

The top-right, top-left, bottom-left, bottom-right points (in that order) of the rectangle.

cℝ²2d Vector of Reals

center of the circle

rReal Number

radius of the circle

Returns: ℝ (Real Number)

shapeDistancePolyEllipse

Returns the distance between a polygon and an ellipse.

Parameters:

NameTypeType DescriptionDescription
pts(ℝ²)ⁿList of 2d Real Vectors

The list of points for the polygon

cℝ²2d Vector of Reals

center of the ellipse

rxReal Number

horizontal radius of ellipse

ryReal Number

vertical radius of ellipse

Returns: ℝ (Real Number)

shapeDistanceCircleLine

Returns the distance between a circle and a line.

Parameters:

NameTypeType DescriptionDescription
cℝ²2d Vector of Reals

center of the circle

rReal Number

radius of the circle

startℝ²2d Vector of Reals

start point of line

endℝ²2d Vector of Reals

end point of line

Returns: ℝ (Real Number)

shapeDistanceLines

Returns the distance between two lines.

Parameters:

NameTypeType DescriptionDescription
start1ℝ²2d Vector of Reals

start point of line

end1ℝ²2d Vector of Reals

end point of line

start2ℝ²2d Vector of Reals

start point of line

end2ℝ²2d Vector of Reals

end point of line

Returns: ℝ (Real Number)

signedArea

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

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectors

points of polygonal chain

closedtrue | falseBoolean Value

whether 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 Vectors

points of polygonal chain

closedtrue | falseBoolean Value

whether 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 Vectors

points of polygonal chain

closedtrue | falseBoolean Value

whether 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 Vectors

points of curve

closedtrue | falseBoolean Value

whether the curve is closed

Returns: ℝ (Real Number)

elasticEnergy

Returns integral of curvature squared along the curve

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectors

points of curve

closedtrue | falseBoolean Value

whether curve is closed

Returns: ℝ (Real Number)

totalCurvature

Returns integral of curvature along the curve

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectors

points of curve

closedtrue | falseBoolean Value

whether curve is closed

signedtrue | falseBoolean Value

whether 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 Vectors

points of curve

closedtrue | falseBoolean Value

whether curve is closed

kReal Number

exponent for line segments

Returns: ℝ (Real Number)

maxCurvature

Returns the maximum value of curvature along the curve

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectors

points of curve

closedtrue | falseBoolean Value

whether curve is closed

Returns: ℝ (Real Number)

pElasticEnergy

Returns integral of curvature raised to p along the curve

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectors

points of curve

closedtrue | falseBoolean Value

whether curve is closed

pReal Number

exponent for curvature

Returns: ℝ (Real Number)

inflectionEnergy

Returns integral of curvature derivative raised to p along the curve

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectors

points of curve

closedtrue | falseBoolean Value

whether curve is closed

pReal Number

exponent for curvature derivative

Returns: ℝ (Real Number)

tangentVectors

Returns list of n tangent vectors given a list of n points.

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectors

points of curve

closedtrue | falseBoolean Value

whether curve is closed

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

normalVectors

Returns list of n normal vectors given a list of n points.

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectors

points of curve

closedtrue | falseBoolean Value

whether curve is closed

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

binormalVectors

Returns list of n binormal vectors given a list of n points.

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectors

points of curve

closedtrue | falseBoolean Value

whether curve is closed

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

evoluteCurve

Returns evolute curve from a list of n points.

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectors

points of curve

closedtrue | falseBoolean Value

whether curve is closed

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

offsetCurve

Returns an offset version of the input curve.

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectors

points of curve

closedtrue | falseBoolean Value

whether curve is closed

magnitudeReal Number

magnitude of the offset

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

curvatures

Returns list of n curvature values given a list of n points.

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectors

points of curve

closedtrue | falseBoolean Value

whether curve is closed

Returns: ℝⁿ (Vector of Reals)

centerOfMass

Returns center of mass for a 2D point cloud

Parameters:

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

points 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

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

Parameters:

NameTypeType DescriptionDescription
sShapeAny Shape

a shape

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

tsneEnergy

Returns T-SNE energy

Parameters:

NameTypeType DescriptionDescription
points(ℝⁿ)ᵐList of Real Vectors

high dimensional points

projectedPoints(ℝⁿ)ᵐList of Real Vectors

projected, low dimensional points

Returns: ℝ (Real Number)

rectPts

Returns the top-left, top-right, bottom-right, bottom-left points of a rect-like shape. This takes into account rotation.

Parameters:

NameTypeType DescriptionDescription
sEquationShape | ImageShape | RectangleShape | TextShapeany of: Equation Shape, or Image Shape, or Rectangle Shape, or Text Shape

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

TeXify

Returns the TeX-fied version of a string where subscripts are handled in a way suitable for equation rendering. For example, "hello_world" becomes "{hello}_{world}".

Parameters:

NameTypeType DescriptionDescription
strStringString

Returns: String (String)

repeat

Returns a vector of n elements of K

Parameters:

NameTypeType DescriptionDescription
nNatural Number
kReal Number

Returns: ℝⁿ (Vector of Reals)

Released under the MIT License.