Skip to content

Geometry in the plane ​

Geometry classes are exported by name, and grouped under PiMath.Geometry on the default export.

js
import {Point, Vector, Line, Circle, Triangle} from 'pimath'

or, with the default export:

js
const {Point, Vector, Line, Circle, Triangle} = PiMath.Geometry

All the coordinates are exact fractions. The same rules apply as everywhere else: operations modify the object and return it, and clone() keeps the original. For space geometry (Line3, Plane3, Sphere3), see geometry in space.

Points ​

A Point is built from numbers, from a string ((1;2), 1,2 or 1 2), or from another point.

js
const A = new Point(1, 2)

A.tex // \left(1;2\right)
A.display // (1;2)
A.x.display // 1
new Point('(3/2;-1)').display // (3/2;-1)
new Point(1, 2, 3).dimension // 3

The coordinates x, y and z are fractions, and array gives all of them as copies. Reading z of a plane point throws a DimensionError.

js
new Point(1, 2).z // throws DimensionError

Distance and midpoint ​

The distance is an exact Root, so distanceTo keeps a radical.

js
const A = new Point(0, 0)
const B = new Point(1, 1)

A.distanceTo(B).display // sqrt(2)
A.distanceTo(new Point(3, 4)).display // 5
Point.middleOf(A, new Point(3, 4)).display // (3/2;2)
A.isEqual(new Point(0, 0)) // true
A.isEqualXY(0, 0) // true

Vectors ​

A Vector is built from numbers, from a string, or from two points: new Vector(A, B) is the vector AB.

js
const v = new Vector(new Point(1, 2), new Point(4, 6))

v.display // ((3,4))
v.tex // \begin{pmatrix} 3 \\ 4 \end{pmatrix}
v.norm // 5
v.normSquare.display // 25
new Vector(3, 4).isEqual(v) // true

Operations ​

js
const u = new Vector(1, 2)
const w = new Vector(3, 4)

u.clone().add(w).display // ((4,6))
u.clone().subtract(w).display // ((-2,-2))
u.clone().multiplyByScalar(3).display // ((3,6))
u.clone().divideByScalar(2).display // ((1/2,1))
u.clone().opposite().display // ((-1,-2))
u.dot(w).display // 11
u.angle(w, false, false).toFixed(2) // 10.30

normal() turns a plane vector by 90 degrees, simplify() gives the smallest integer coordinates, and unit() divides by the norm, which is a decimal number.

js
new Vector(1, 2).normal().display // ((2,-1))
new Vector('(1/2;3/2)').simplify().display // ((1,3))
new Vector(3, 4).unit().display // ((3/5,4/5))

Tests ​

js
new Vector(1, 2).isColinearTo(new Vector(2, 4)) // true
new Vector(1, 2).isNormalTo(new Vector(2, -1)) // true
new Vector(0, 0).isZero() // true

cross is the cross product of two vectors in space, and throws a DimensionError in the plane. Vector.fromPolynom('2a-b', {a: '(1;0)', b: '(0;1)'}) builds a linear combination of named vectors.

Lines ​

A Line is stored as ax + by + c = 0. It is built from an equation, from two points, from a point and a direction vector, or from three coefficients.

js
const d = new Line('2x+3y-6=0')

d.tex // 2x+3y-6=0
d.slope.display // -2/3
d.height.display // 2
d.d.display // ((3,-2))
d.normal.display // ((2,3))
new Line(new Point(0, 0), new Point(2, 4)).tex // 2x-y=0
new Line(new Point(0, 0), new Vector(1, 2)).tex // 2x-y=0
new Line(2, 3, -6).tex // 2x+3y-6=0

slope and height are the m and h of y = mx + h. A vertical line has an infinite slope.

Output forms ​

asCartesian, asMxh, asParametric and asSystem select a form for the next tex or display only. The default form comes back afterwards.

js
const d = new Line('2x+3y-6=0')

d.asMxh.display // y=-2/3x+2
d.asCartesian.display // 2x+3y=6
d.asParametric.display // ((x,y))=((0,2))+k((3,-2))
d.display // 2x+3y-6=0
d.withDigits(1).asMxh.display // y=-0.7x+2.0

Relations ​

js
const d1 = new Line('2x+3y-6=0')
const d2 = new Line('4x+6y+1=0')

d1.isParallelTo(d2) // true
d1.isPerpendicularTo(new Line('3x-2y=0')) // true
d1.isEqual(new Line('4x+6y-12=0')) // true
d1.isPointOnLine(new Point(0, 2)) // true
d1.intersection(new Line('x-y=0')).point.display // (6/5;6/5)
d1.intersection(d2).isParallel // true
d1.distanceTo(new Point(0, 0)).display // (6sqrt(13))/13

intersection returns {point, hasIntersection, isParallel, isSame}, and point is null when there is no single intersection.

Build one line from another ​

js
const d = new Line('2x+3y-6=0')
const P = new Point(1, 1)

Line.fromParallel(d, P).tex // 2x+3y-5=0
Line.fromPerpendicular(d, P).tex // 3x-2y-1=0
Line.fromPointAndNormal(P, new Vector(2, 3)).tex // 2x+3y-5=0
Line.fromPointAndLine(P, d, Line.PERPENDICULAR).tex // 3x-2y-1=0
d.project(new Point(0, 0)).display // (12/13;18/13)
d.reflect(new Point(0, 0)).display // (24/13;36/13)
d.getValueAtX(3).display // 0

getValueAtX and getValueAtY give an invalid fraction when the line is vertical or horizontal respectively. randomPoint(k) and randomNearPoint(k) give a point on the line, or close to it, for exercises.

Circles ​

A Circle is stored by its center and the square of its radius, which keeps everything exact. It is built from an equation, from a center and a radius, from a center and a point, or from three points.

js
const c = new Circle('(x-1)^2+(y+2)^2=9')

c.center.display // (1;-2)
c.radius.display // 3
c.squareRadius.display // 9
c.tex // \left(x-1\right)^2+\left(y+2\right)^2=9
c.asDeveloped.display // x^(2)-2x+y^(2)+4y-4=0
new Circle(new Point(0, 0), 5).display // x^2+y^2=25
new Circle(new Point(1, 1), new Point(4, 5)).squareRadius.display // 25
Circle.fromPoints(new Point(0, 0), new Point(4, 0), new Point(0, 4)).center.display // (2;2)

An equation that is not the one of a circle throws a MathError.

js
new Circle('x^2+2y^2=9') // throws MathError

Points, tangents and intersections ​

js
const c = new Circle(new Point(0, 0), 5)

c.isPointOnCircle(new Point(3, 4)) // true
c.getPointsOnCircle().length // 12
c.tangents(new Point(3, 4)).map(t => t.tex) // [ '3x+4y-25=0' ]
c.tangents(new Point(1, 1)).length // 0
c.intersection(new Line('y=0')).map(p => p.display) // [ '(-5;0)', '(5;0)' ]
c.relativePosition(new Line('y=5')) // 1
c.relativePosition(new Circle(new Point(3, 0), 2)) === Circle.RELATIVE_POSITION.TANGENT_INSIDE // true

getPointsOnCircle lists the points with integer coordinates around the center, and is empty when the square of the radius is not an integer. tangents takes a point (one tangent on the circle, two outside, none inside) or a slope. relativePosition returns 0, 1 or 2 intersections for a line, and a Circle.RELATIVE_POSITION value for another circle.

Triangles ​

A Triangle is built from three points, three lines, or six coordinates, and it throws a MathError when the vertices are collinear.

js
const T = new Triangle(new Point(0, 0), new Point(4, 0), new Point(0, 3))

T.isValid // true
T.isRectangle() // true
T.isIsocele() // false
T.AB.display // ((4,0))
T.lines.AB.tex // y=0
T.getMiddles().BC.display // (2;3/2)
T.getAngle('A') // 1.5707963267948966
T.asDegree.getAngle('B') // 36.87

The remarkable lines come with their common point.

js
const T = new Triangle(new Point(0, 0), new Point(4, 0), new Point(0, 3))

T.getMedians().intersection.display // (4/3;1)
T.getHeights().intersection.display // (0;0)
T.getMediators().intersection.display // (2;3/2)
T.getBisectors().intersection.display // (1;1)

tex and display are not available on a triangle: they throw a NotImplementedError. Describe it with its vertices (A, B, C) or its lines. Setting a vertex refreshes the validity and the remarkable lines.

Random geometry ​

js
PiMath.Random.point({quadrant: 1}).tex // e.g. \left(8;5\right)
PiMath.Random.line().tex // e.g. 2x-3y+4=0
PiMath.Random.circle().tex // e.g. \left(x-1\right)^2+y^2=25

See random generators for the options.

Members ​

Point ​

Constructors

  • new Point(...values: (Point \| Vector)[] \| InputValue<Fraction>[])

Static members

MemberDescription
fromString(value: string): PointBuild a point from a string such as "(1;2)", "1,2" or "1 2 3": at least two coordinates, separated by ,, ; or a space. Throws: {ParseError} if fewer than 2 coordinates are found.
middleOf(V1: Point, V2: Point): PointThe midpoint of two points, as a new point. Throws: {DimensionError} if the points have different dimensions.

Properties and getters

MemberDescription
tex: stringLaTeX rendering of the current state (terminal output, not chainable).
display: stringASCIIMath rendering of the current state (terminal output, not chainable).
array: Fraction[]The coordinates, as copies. Setting the property replaces them.
dimension: numberNumber of coordinates: 2 in the plane, 3 in space.
onChange: (() => void) | undefinedFunction called when a coordinate is set through x, y or z, or when the tuple is zeroed. Triangle uses it to refresh its remarkable lines.
x: FractionFirst coordinate. Setting it accepts a fraction, a number or a string.
y: FractionSecond coordinate. Setting it accepts a fraction, a number or a string.
z: FractionThird coordinate. Setting it accepts a fraction, a number or a string. Throws: {DimensionError} if the tuple has fewer than 3 coordinates.; {DimensionError} if dimension < 3
norm: numberEuclidean norm, as a decimal number.
normSquare: FractionSquare of the norm, as an exact fraction.

Methods

MemberDescription
parse(...values: (Point | Vector)[] | InputValue<Fraction>[]): PointReplace the coordinates with numbers, a string, a point or a vector. Throws: {InvalidArgumentError} if several arguments are given and one of them is a point or a vector.; {ParseError} if a value is not a number.
clone(): PointFull duplicate of this instance, including display state (selected form and options set via as*** / with***). Distinct from copy.
distanceTo(B: Point): RootDistance to another point, as an exact reduced Root. Throws: {DimensionError} if the points have different dimensions.
isEqual(pt: Point): booleanTrue when both points have the same dimension and the same coordinates.
isEqualXY(x: InputValue<Fraction>, y: InputValue<Fraction>): booleanTrue when the point is (x, y).
middleOf(V1: Point, V2: Point): PointSet this point to the midpoint of two points. Throws: {DimensionError} if the points have different dimensions.
cloneCoordinates(): Fraction[]Returns a deep copy of the raw coordinate array. Unlike clone(), returns a Fraction[], not a TupleN instance.
withDigits(digits: number | null): PointShow every numeric value as a decimal with digits digits after the point (exact values included: 3/2 becomes 1.50 with 2 digits).
setDimension(value?: number): PointChange the number of coordinates: new ones are zero, extra ones are removed. Throws: {DimensionError} if value is less than 2.
copy(value: TupleN): PointCopy the mathematical state of another instance into this (display state is NOT transferred — the receiver keeps its own formatting). Entry point used when constructing/parsing from a same-type input. Distinct from clone. Classes without a real implementation throw NotImplementedError.
isZero(): booleanTrue when every coordinate is zero.
opposite(): PointChange the sign of every coordinate.
zero(): PointSet every coordinate to zero.

Vector ​

Constructors

  • new Vector(...values: (Vector \| Point)[] \| InputValue<Fraction>[])

Static members

MemberDescription
asDisplay(...values: string[]): stringText form of a vector from already written coordinates: asDisplay("x", "y") is ((x,y)).
asTex(...values: string[]): stringLaTeX form of a vector from already written coordinates.
fromString(value: string): VectorAccepts ((x,y,...)), (x;y;...), or x,y,... format. Throws: {ParseError} if fewer than 2 components are found
fromPolynom(expr: InputAlgebra<Polynom>, vectors: Record<string, Vector | string>): VectorBuild the linear combination written by a polynom: fromPolynom("2a-b", {a: "(1;0)", b: "(0;1)"}) is (2;-1). Throws: {InvalidArgumentError} if the polynom has a constant term, a term that is not linear, or a variable without vector.; {DimensionError} if the vectors have different dimensions.

Properties and getters

MemberDescription
tex: stringLaTeX rendering of the current state (terminal output, not chainable).
display: stringASCIIMath rendering of the current state (terminal output, not chainable).
array: Fraction[]The coordinates, as copies. Setting the property replaces them.
dimension: numberNumber of coordinates: 2 in the plane, 3 in space.
onChange: (() => void) | undefinedFunction called when a coordinate is set through x, y or z, or when the tuple is zeroed. Triangle uses it to refresh its remarkable lines.
x: FractionFirst coordinate. Setting it accepts a fraction, a number or a string.
y: FractionSecond coordinate. Setting it accepts a fraction, a number or a string.
z: FractionThird coordinate. Setting it accepts a fraction, a number or a string. Throws: {DimensionError} if the tuple has fewer than 3 coordinates.; {DimensionError} if dimension < 3
norm: numberEuclidean norm, as a decimal number.
normSquare: FractionSquare of the norm, as an exact fraction.

Methods

MemberDescription
parse(...values: (Vector | Point)[] | InputValue<Fraction>[]): VectorReplace the coordinates with numbers, a string, a vector or a point, or with the vector from one point to another. Throws: {InvalidArgumentError} if the arguments are not valid.; {DimensionError} if two points have different dimensions.; {ParseError} if a value is not a number.
clone(): VectorFull duplicate of this instance, including display state (selected form and options set via as*** / with***). Distinct from copy.
add(V: Vector): VectorAdd a vector of the same dimension.
angle(V: Vector, sharp?: boolean, radian?: boolean): numberAngle between two vectors, in degrees by default. Throws: {MathError} if one of the vectors is the zero vector (the angle is undefined)
cross(value: Vector): VectorCross product, as a new vector. Throws: {DimensionError} if either vector is not 3-dimensional.
divideByScalar(k: InputValue<Fraction>): VectorDivide every coordinate by a number.
dot(V: Vector | Point): FractionDot product, as an exact fraction.
isColinearTo(v: Vector): booleanTrue when both vectors are parallel (one is a multiple of the other).
isEqual(v: Vector): booleanTrue when both vectors have the same coordinates.
isNormalTo(v: Vector): booleanTrue when the vectors are perpendicular: their dot product is zero.
isOne(): booleanTrue for the vector (1, 0, ...), which one produces.
multiplyByScalar(k: InputValue<Fraction>): VectorMultiply every coordinate by a number.
normal(): VectorRotates 90° to obtain a perpendicular vector: (x, y) → (y, −x). Throws: {DimensionError} if the vector is not 2-dimensional
one(): VectorSet the vector to (1, 0, ...).
simplify(): VectorScale the vector to the smallest integer coordinates with no common divisor, and make the first coordinate positive. The direction is kept.
subtract(V: Vector): VectorSubtract a vector of the same dimension.
translate(...values: Fraction[]): VectorAdd the given values to the coordinates, one per coordinate.
unit(): VectorDivide by the norm. The norm is a decimal number, so the result is exact only when it is rational. The zero vector is left as it is.
cloneCoordinates(): Fraction[]Returns a deep copy of the raw coordinate array. Unlike clone(), returns a Fraction[], not a TupleN instance.
withDigits(digits: number | null): VectorShow every numeric value as a decimal with digits digits after the point (exact values included: 3/2 becomes 1.50 with 2 digits).
setDimension(value?: number): VectorChange the number of coordinates: new ones are zero, extra ones are removed. Throws: {DimensionError} if value is less than 2.
copy(value: TupleN): VectorCopy the mathematical state of another instance into this (display state is NOT transferred — the receiver keeps its own formatting). Entry point used when constructing/parsing from a same-type input. Distinct from clone. Classes without a real implementation throw NotImplementedError.
isZero(): booleanTrue when every coordinate is zero.
opposite(): VectorChange the sign of every coordinate.
zero(): VectorSet every coordinate to zero.

Line ​

Constructors

  • new Line(...values: unknown[])

Static members

MemberDescription
PARALLEL: LinePropertyConstant to give to fromPointAndLine: build the parallel line.
PERPENDICULAR: LinePropertyConstant to give to fromPointAndLine: build the perpendicular line.
fromCoefficient(a: InputValue<Fraction>, b: InputValue<Fraction>, c: InputValue<Fraction>): LineBuild the line ax + by + c = 0. Fractional coefficients are multiplied to become integers.
fromEquation(value: InputAlgebra<Equation>): LineBuild a line from an equation in x and y of the first degree. Throws: {ParseError} if the equation has no x or y, has another variable, or is not linear.
fromParallel(parallel: Line, point: Point): LineThe line through point parallel to parallel.
fromPerpendicular(perpendicular: Line, point: Point): LineThe line through point perpendicular to perpendicular.
fromPointAndDirection(P: Point | Vector, d: Vector): LineThe line through a point with a direction vector. Throws: {ParseError} if the vector is zero.
fromPointAndLine(P: Point | Vector, L: Line, orientation?: LineProperty): LineThe line through a point, parallel (default) or perpendicular to a line.
fromPointAndNormal(P: Point | Vector, n: Vector): LineThe line through a point with a normal vector. Throws: {ParseError} if the normal vector is zero.
fromPoints(A: Point, B: Point): LineThe line through two points. Throws: {ParseError} if the points are the same.

Properties and getters

MemberDescription
tex: stringLaTeX rendering of the current state (terminal output, not chainable).
display: stringASCIIMath rendering of the current state (terminal output, not chainable).
OA: VectorA point of the line, as a vector. Setting it moves the line through that point and keeps its direction.
a: FractionCoefficient of x in ax + by + c = 0. Setting it does not update the reference point OA.
asCanonical: LineOutput option for the next tex or display: ax+by+c=0 (default). Chainable.
asCartesian: LineOutput option for the next tex or display: ax+by=-c. Chainable.
asMxh: LineOutput option for the next tex or display: y=mx+h, or x=k for a vertical line. Chainable.
asParametric: LineOutput option for the next tex or display: a point and a direction vector. Chainable.
asSystem: LineOutput option for the next tex or display: the parametric system of x and y. Chainable.
b: FractionCoefficient of y in ax + by + c = 0. Setting it does not update the reference point OA.
c: FractionConstant term in ax + by + c = 0. Setting it does not update the reference point OA.
d: VectorDirection vector (b, -a), oriented to the right unless the line was built from a direction pointing to the left. Setting it keeps the point OA and changes the direction.
director: VectorSame as d.
height: FractionIntercept h of y = mx + h: -c/b. Infinite for a vertical line.
n: VectorNormal vector computed from the direction (the direction turned by 90 degrees). It can be the opposite of normal.
normal: VectorNormal vector (a, b).
slope: FractionSlope m of y = mx + h: -a/b. Infinite for a vertical line.

Methods

MemberDescription
parse(...values: unknown[]): LineReplace the line with an equation, another line, two points, a point and a vector, or three coefficients. Throws: {ParseError} if the arguments do not describe a line.
copy(value: Line): LineCopy the mathematical state of another instance into this (display state is NOT transferred — the receiver keeps its own formatting). Entry point used when constructing/parsing from a same-type input. Distinct from clone. Classes without a real implementation throw NotImplementedError.
clone(): LineFull duplicate of this instance, including display state (selected form and options set via as*** / with***). Distinct from copy.
withDigits(digits: number | null): LineShow the coefficients as decimals with digits digits, in every output mode. Persistent (copied by clone()); null goes back to the exact output. Throws: {InvalidArgumentError} if digits is neither null nor an integer from 0 to 100.
distanceTo(pt: Point): RootDistance from a point to the line, as an exact reduced Root.
getEquation(): EquationThe equation ax + by + c = 0 with integer coefficients, as an Equation.
getValueAtX(value: Fraction | number): FractionReturns an invalid (NaN) Fraction if the line is vertical (no y term).
getValueAtY(value: Fraction | number): FractionReturns an invalid (NaN) Fraction if the line is horizontal (no x term).
hitSegment(A: Point, B: Point): booleanTrue when the line crosses the segment [AB], ends included.
intersection(line: Line): LineIntersectionIntersection with another line, as {point, hasIntersection, isParallel, isSame}. The point is null when the lines are parallel or the same.
isHorizontal(): booleanTrue when the slope is zero.
isPointOnLine(pt: Point): booleanTrue when the point satisfies the equation of the line.
isParallelTo(line: Line): booleanTrue when the lines have the same direction but are not the same line.
isPerpendicularTo(line: Line): booleanTrue when the directions are perpendicular.
isEqual(line: Line): booleanTrue when both lines are the same line, whatever their coefficients.
isVertical(): booleanTrue when the slope is infinite.
randomNearPoint(k?: number): PointA random point close to the line but not on it.
randomPoint(k?: number): PointA random point of the line: the point OA moved along the direction vector by a non-zero integer between -k and k.
simplify(): LineGive the equation the smallest integer coefficients with no common divisor.
project(pt: Point): PointOrthogonal projection of pt onto this line.
reflect(pt: Point): PointReflection of pt through this line (proj is the midpoint of [pt, reflect(pt)]).

Circle ​

Constructors

  • new Circle()
  • new Circle(equation: string \| Equation)
  • new Circle(circle: Circle)
  • new Circle(center: Point, radius: Fraction \| number, square?: boolean)
  • new Circle(center: Point, pointThrough: Point)
  • new Circle(A: Point, B: Point, C: Point)

Static members

MemberDescription
fromCenterPoint(center: Point, pointThrough: Point): CircleThe circle with the given center, through a point.
fromCenterRadius(center: Point, radius: Fraction | number, square?: boolean): CircleThe circle with the given center and radius.
fromEquation(value: InputAlgebra<Equation>): CircleDoes not mutate the input. Throws: {MathError} if the input is not a valid circle equation
fromPoints(A: Point, B: Point, C: Point): CircleThe circle through three points. Throws: {MathError} if the points are collinear or two of them are the same.
fromString(str: string): CircleThe circle of an equation written in a string. Throws: {MathError} if the equation is not the one of a circle.
RELATIVE_POSITION: typeof CircleRelativePositionThe values returned by relativePosition for two circles.

Properties and getters

MemberDescription
tex: stringLaTeX rendering of the current state (terminal output, not chainable).
display: stringASCIIMath rendering of the current state (terminal output, not chainable).
asDeveloped: CircleOutput option: the developed equation x^2+y^2-2x+4y-4=0. Chainable, persistent.
asCenterRadius: CircleOutput option: the form (x-a)^2+(y-b)^2=r^2 (default). Chainable, persistent.
center: PointThe center, as a point.
equation: EquationThe equation (x-a)^2+(y-b)^2-r^2=0, as an Equation (a copy).
radius: RootThe radius, as an exact reduced Root (3, 2sqrt(2)).
squareRadius: FractionThe square of the radius, as an exact fraction. It is -1 for a circle that has not been defined.

Methods

MemberDescription
parse(...values: unknown[]): CircleReplace the circle with an equation, another circle, a center and a radius, a center and a point, or three points. Arguments that do not match any form leave the circle unchanged.
clone(): CircleFull duplicate of this instance, including display state (selected form and options set via as*** / with***). Distinct from copy.
withDigits(digits: number | null): CircleShow every numeric value as a decimal with digits digits after the point (exact values included: 3/2 becomes 1.50 with 2 digits).
copy(circle: Circle): CircleCopy the mathematical state of another instance into this (display state is NOT transferred — the receiver keeps its own formatting). Entry point used when constructing/parsing from a same-type input. Distinct from clone. Classes without a real implementation throw NotImplementedError.
getPointsOnCircle(): Point[]The points of the circle with integer coordinates relative to the center. It is empty when the square of the radius is not an integer.
isPointOnCircle(P: Point): booleanTrue when the point satisfies the equation of the circle.
isEqual(circ: Circle): booleanTrue when both circles have the same center and the same radius.
intersection(L: Line): Point[]Find the intersection points between the circle and a line. It can be 0, 1 or 2 points. The points are sorted depending on the direction vector of the line.
relativePosition(L: Line): 0 | 1 | 2
relativePosition(C: Circle): CircleRelativePosition
Returns the number of intersections between circle and line. Returns the relative position between two circles. Throws: {MathError} if the circle is uninitialized; {MathError} if the circle is uninitialized
setRadius(radius: Fraction | number, square?: boolean): CircleChange the radius.
tangents(P: Point | Fraction): Line[]Returns the tangent line(s) to the circle. - P: Point on the circle → 1 tangent (perpendicular to the radius at P). - P: Point outside the circle → 2 tangents through P. - P: Point inside the circle → [] (no real tangent). - P: Fraction → 2 tangents with slope P.

Triangle ​

Constructors

  • new Triangle(...values: unknown[])

Static members

MemberDescription
fromCoordinates(x1: InputValue<Fraction>, y1: InputValue<Fraction>, x2: InputValue<Fraction>, y2: InputValue<Fraction>, x3: InputValue<Fraction>, y3: InputValue<Fraction>): TriangleBuild a triangle from the coordinates of its three vertices. Throws: {MathError} if the points are collinear or two of them are the same.
fromLines(line1: Line | string, line2: Line | string, line3: Line | string): TriangleBuild a triangle from the lines of its sides AB, BC and AC, given as lines or equation strings. Throws: {MathError} if two lines are parallel or the lines do not form a triangle.
fromPoints(A: Point, B: Point, C: Point): TriangleBuild a triangle from its three vertices. Throws: {MathError} if the points are collinear or two of them are the same.

Properties and getters

MemberDescription
tex: stringNot implemented on purpose: a triangle has no single equation to display. Throws: {NotImplementedError} always. Describe it through its lines or its vertices.
display: stringNot implemented on purpose: see tex. Throws: {NotImplementedError} always.
A: PointVertex A. Setting a vertex refreshes the validity and the remarkable lines.
AB: VectorThe vector from A to B.
AC: VectorThe vector from A to C.
B: PointVertex B. Setting a vertex refreshes the validity and the remarkable lines.
BA: VectorThe vector from B to A.
BC: VectorThe vector from B to C.
C: PointVertex C. Setting a vertex refreshes the validity and the remarkable lines.
CA: VectorThe vector from C to A.
CB: VectorThe vector from C to B.
asDegree: TriangleOutput option: getAngle gives degrees. Chainable, persistent.
asRadians: TriangleOutput option: getAngle gives radians (default). Chainable, persistent.
isValid: booleanFalse when the three vertices are collinear.
lines: Record<TriangleSide, Line>The lines of the sides, as {AB, BC, AC}.
remarquables: RemarquableLinesThe remarkable lines already computed. An entry is null until the matching get*** method is called.

Methods

MemberDescription
parse(...values: unknown[]): TriangleReplace the triangle with a triangle, three lines (objects or equation strings), three points, or six coordinates. Throws: {InvalidArgumentError} if one of six values is not a number.; {MathError} if the points are collinear or the lines do not form a triangle.
clone(): TriangleFull duplicate of this instance, including display state (selected form and options set via as*** / with***). Distinct from copy.
copy(value: Triangle): TriangleCopies the three vertices from value into this instance. Math state only — #radians is not transferred (use clone for a full copy).
getAngle(name: "A" | "B" | "C"): numberAngle at a vertex, as a decimal number: in radians by default, in degrees after asDegree.
getBisectors(internal?: boolean): { "A": Line; "B": Line; "C": Line; "intersection": Point | null; }The bisectors of the angles, as {A, B, C, intersection}, where intersection is their common point. Throws: {MathError} if the triangle is degenerate.
getHeights(): { "A": Line; "B": Line; "C": Line; "intersection": Point | null; }The heights, as {A, B, C, intersection}, where intersection is the orthocenter. Throws: {MathError} if the triangle is degenerate.
getMedians(): { "A": Line; "B": Line; "C": Line; "intersection": Point | null; }The medians, as {A, B, C, intersection}, where intersection is the centroid. Throws: {MathError} if the triangle is degenerate.
getMediators(): { "a": Line; "b": Line; "c": Line; "intersection": Point | null; }The perpendicular bisectors of the sides, as {a, b, c, intersection}, where intersection is the circumcenter. Throws: {MathError} if the triangle is degenerate.
getMiddles(): { AB: Point; AC: Point; BC: Point; }The midpoints of the sides, as {AB, AC, BC}.
getPoints(): Point[]The vertices [A, B, C].
getSortedPoints(): Point[]The vertices sorted by x, then by y.
isEqual(T: Triangle): booleanTrue when both triangles have the same vertices, whatever their order.
isEquilateral(): booleanTrue when the three sides have the same length.
isIsocele(): booleanTrue when two sides have the same length.
isRectangle(): booleanTrue when two sides are perpendicular.
reset(): TriangleRecompute the validity and forget the cached lines and remarkable lines. This is done automatically when a vertex changes through its setter or its x and y coordinates.

Released under the MIT License.