Geometry in the plane
Geometry classes are exported by name, and grouped under PiMath.Geometry on the default export.
import {Point, Vector, Line, Circle, Triangle} from 'pimath'or, with the default export:
const {Point, Vector, Line, Circle, Triangle} = PiMath.GeometryAll 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.
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 // 3The coordinates x, y and z are fractions, and array gives all of them as copies. Reading z of a plane point throws a DimensionError.
new Point(1, 2).z // throws DimensionErrorDistance and midpoint
The distance is an exact Root, so distanceTo keeps a radical.
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) // trueVectors
A Vector is built from numbers, from a string, or from two points: new Vector(A, B) is the vector AB.
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) // trueOperations
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.30normal() turns a plane vector by 90 degrees, simplify() gives the smallest integer coordinates, and unit() divides by the norm, which is a decimal number.
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
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() // truecross 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.
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=0slope 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.
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.0Relations
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))/13intersection returns {point, hasIntersection, isParallel, isSame}, and point is null when there is no single intersection.
Build one line from another
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 // 0getValueAtX 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.
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.
new Circle('x^2+2y^2=9') // throws MathErrorPoints, tangents and intersections
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 // truegetPointsOnCircle 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.
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.87The remarkable lines come with their common point.
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
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=25See random generators for the options.
Members
Point
Constructors
new Point(...values: (Point \| Vector)[] \| InputValue<Fraction>[])
Static members
| Member | Description |
|---|---|
fromString(value: string): Point | Build 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): Point | The midpoint of two points, as a new point. Throws: {DimensionError} if the points have different dimensions. |
Properties and getters
| Member | Description |
|---|---|
tex: string | LaTeX rendering of the current state (terminal output, not chainable). |
display: string | ASCIIMath rendering of the current state (terminal output, not chainable). |
array: Fraction[] | The coordinates, as copies. Setting the property replaces them. |
dimension: number | Number of coordinates: 2 in the plane, 3 in space. |
onChange: (() => void) | undefined | Function 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: Fraction | First coordinate. Setting it accepts a fraction, a number or a string. |
y: Fraction | Second coordinate. Setting it accepts a fraction, a number or a string. |
z: Fraction | Third 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: number | Euclidean norm, as a decimal number. |
normSquare: Fraction | Square of the norm, as an exact fraction. |
Methods
| Member | Description |
|---|---|
parse(...values: (Point | Vector)[] | InputValue<Fraction>[]): Point | Replace 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(): Point | Full duplicate of this instance, including display state (selected form and options set via as*** / with***). Distinct from copy. |
distanceTo(B: Point): Root | Distance to another point, as an exact reduced Root. Throws: {DimensionError} if the points have different dimensions. |
isEqual(pt: Point): boolean | True when both points have the same dimension and the same coordinates. |
isEqualXY(x: InputValue<Fraction>, y: InputValue<Fraction>): boolean | True when the point is (x, y). |
middleOf(V1: Point, V2: Point): Point | Set 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): Point | Show 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): Point | Change the number of coordinates: new ones are zero, extra ones are removed. Throws: {DimensionError} if value is less than 2. |
copy(value: TupleN): Point | Copy 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(): boolean | True when every coordinate is zero. |
opposite(): Point | Change the sign of every coordinate. |
zero(): Point | Set every coordinate to zero. |
Vector
Constructors
new Vector(...values: (Vector \| Point)[] \| InputValue<Fraction>[])
Static members
| Member | Description |
|---|---|
asDisplay(...values: string[]): string | Text form of a vector from already written coordinates: asDisplay("x", "y") is ((x,y)). |
asTex(...values: string[]): string | LaTeX form of a vector from already written coordinates. |
fromString(value: string): Vector | Accepts ((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>): Vector | Build 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
| Member | Description |
|---|---|
tex: string | LaTeX rendering of the current state (terminal output, not chainable). |
display: string | ASCIIMath rendering of the current state (terminal output, not chainable). |
array: Fraction[] | The coordinates, as copies. Setting the property replaces them. |
dimension: number | Number of coordinates: 2 in the plane, 3 in space. |
onChange: (() => void) | undefined | Function 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: Fraction | First coordinate. Setting it accepts a fraction, a number or a string. |
y: Fraction | Second coordinate. Setting it accepts a fraction, a number or a string. |
z: Fraction | Third 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: number | Euclidean norm, as a decimal number. |
normSquare: Fraction | Square of the norm, as an exact fraction. |
Methods
| Member | Description |
|---|---|
parse(...values: (Vector | Point)[] | InputValue<Fraction>[]): Vector | Replace 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(): Vector | Full duplicate of this instance, including display state (selected form and options set via as*** / with***). Distinct from copy. |
add(V: Vector): Vector | Add a vector of the same dimension. |
angle(V: Vector, sharp?: boolean, radian?: boolean): number | Angle 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): Vector | Cross product, as a new vector. Throws: {DimensionError} if either vector is not 3-dimensional. |
divideByScalar(k: InputValue<Fraction>): Vector | Divide every coordinate by a number. |
dot(V: Vector | Point): Fraction | Dot product, as an exact fraction. |
isColinearTo(v: Vector): boolean | True when both vectors are parallel (one is a multiple of the other). |
isEqual(v: Vector): boolean | True when both vectors have the same coordinates. |
isNormalTo(v: Vector): boolean | True when the vectors are perpendicular: their dot product is zero. |
isOne(): boolean | True for the vector (1, 0, ...), which one produces. |
multiplyByScalar(k: InputValue<Fraction>): Vector | Multiply every coordinate by a number. |
normal(): Vector | Rotates 90° to obtain a perpendicular vector: (x, y) → (y, −x). Throws: {DimensionError} if the vector is not 2-dimensional |
one(): Vector | Set the vector to (1, 0, ...). |
simplify(): Vector | Scale the vector to the smallest integer coordinates with no common divisor, and make the first coordinate positive. The direction is kept. |
subtract(V: Vector): Vector | Subtract a vector of the same dimension. |
translate(...values: Fraction[]): Vector | Add the given values to the coordinates, one per coordinate. |
unit(): Vector | Divide 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): Vector | Show 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): Vector | Change the number of coordinates: new ones are zero, extra ones are removed. Throws: {DimensionError} if value is less than 2. |
copy(value: TupleN): Vector | Copy 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(): boolean | True when every coordinate is zero. |
opposite(): Vector | Change the sign of every coordinate. |
zero(): Vector | Set every coordinate to zero. |
Line
Constructors
new Line(...values: unknown[])
Static members
| Member | Description |
|---|---|
PARALLEL: LineProperty | Constant to give to fromPointAndLine: build the parallel line. |
PERPENDICULAR: LineProperty | Constant to give to fromPointAndLine: build the perpendicular line. |
fromCoefficient(a: InputValue<Fraction>, b: InputValue<Fraction>, c: InputValue<Fraction>): Line | Build the line ax + by + c = 0. Fractional coefficients are multiplied to become integers. |
fromEquation(value: InputAlgebra<Equation>): Line | Build 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): Line | The line through point parallel to parallel. |
fromPerpendicular(perpendicular: Line, point: Point): Line | The line through point perpendicular to perpendicular. |
fromPointAndDirection(P: Point | Vector, d: Vector): Line | The line through a point with a direction vector. Throws: {ParseError} if the vector is zero. |
fromPointAndLine(P: Point | Vector, L: Line, orientation?: LineProperty): Line | The line through a point, parallel (default) or perpendicular to a line. |
fromPointAndNormal(P: Point | Vector, n: Vector): Line | The line through a point with a normal vector. Throws: {ParseError} if the normal vector is zero. |
fromPoints(A: Point, B: Point): Line | The line through two points. Throws: {ParseError} if the points are the same. |
Properties and getters
| Member | Description |
|---|---|
tex: string | LaTeX rendering of the current state (terminal output, not chainable). |
display: string | ASCIIMath rendering of the current state (terminal output, not chainable). |
OA: Vector | A point of the line, as a vector. Setting it moves the line through that point and keeps its direction. |
a: Fraction | Coefficient of x in ax + by + c = 0. Setting it does not update the reference point OA. |
asCanonical: Line | Output option for the next tex or display: ax+by+c=0 (default). Chainable. |
asCartesian: Line | Output option for the next tex or display: ax+by=-c. Chainable. |
asMxh: Line | Output option for the next tex or display: y=mx+h, or x=k for a vertical line. Chainable. |
asParametric: Line | Output option for the next tex or display: a point and a direction vector. Chainable. |
asSystem: Line | Output option for the next tex or display: the parametric system of x and y. Chainable. |
b: Fraction | Coefficient of y in ax + by + c = 0. Setting it does not update the reference point OA. |
c: Fraction | Constant term in ax + by + c = 0. Setting it does not update the reference point OA. |
d: Vector | Direction 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: Vector | Same as d. |
height: Fraction | Intercept h of y = mx + h: -c/b. Infinite for a vertical line. |
n: Vector | Normal vector computed from the direction (the direction turned by 90 degrees). It can be the opposite of normal. |
normal: Vector | Normal vector (a, b). |
slope: Fraction | Slope m of y = mx + h: -a/b. Infinite for a vertical line. |
Methods
| Member | Description |
|---|---|
parse(...values: unknown[]): Line | Replace 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): Line | Copy 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(): Line | Full duplicate of this instance, including display state (selected form and options set via as*** / with***). Distinct from copy. |
withDigits(digits: number | null): Line | Show 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): Root | Distance from a point to the line, as an exact reduced Root. |
getEquation(): Equation | The equation ax + by + c = 0 with integer coefficients, as an Equation. |
getValueAtX(value: Fraction | number): Fraction | Returns an invalid (NaN) Fraction if the line is vertical (no y term). |
getValueAtY(value: Fraction | number): Fraction | Returns an invalid (NaN) Fraction if the line is horizontal (no x term). |
hitSegment(A: Point, B: Point): boolean | True when the line crosses the segment [AB], ends included. |
intersection(line: Line): LineIntersection | Intersection with another line, as {point, hasIntersection, isParallel, isSame}. The point is null when the lines are parallel or the same. |
isHorizontal(): boolean | True when the slope is zero. |
isPointOnLine(pt: Point): boolean | True when the point satisfies the equation of the line. |
isParallelTo(line: Line): boolean | True when the lines have the same direction but are not the same line. |
isPerpendicularTo(line: Line): boolean | True when the directions are perpendicular. |
isEqual(line: Line): boolean | True when both lines are the same line, whatever their coefficients. |
isVertical(): boolean | True when the slope is infinite. |
randomNearPoint(k?: number): Point | A random point close to the line but not on it. |
randomPoint(k?: number): Point | A random point of the line: the point OA moved along the direction vector by a non-zero integer between -k and k. |
simplify(): Line | Give the equation the smallest integer coefficients with no common divisor. |
project(pt: Point): Point | Orthogonal projection of pt onto this line. |
reflect(pt: Point): Point | Reflection 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
| Member | Description |
|---|---|
fromCenterPoint(center: Point, pointThrough: Point): Circle | The circle with the given center, through a point. |
fromCenterRadius(center: Point, radius: Fraction | number, square?: boolean): Circle | The circle with the given center and radius. |
fromEquation(value: InputAlgebra<Equation>): Circle | Does not mutate the input. Throws: {MathError} if the input is not a valid circle equation |
fromPoints(A: Point, B: Point, C: Point): Circle | The circle through three points. Throws: {MathError} if the points are collinear or two of them are the same. |
fromString(str: string): Circle | The circle of an equation written in a string. Throws: {MathError} if the equation is not the one of a circle. |
RELATIVE_POSITION: typeof CircleRelativePosition | The values returned by relativePosition for two circles. |
Properties and getters
| Member | Description |
|---|---|
tex: string | LaTeX rendering of the current state (terminal output, not chainable). |
display: string | ASCIIMath rendering of the current state (terminal output, not chainable). |
asDeveloped: Circle | Output option: the developed equation x^2+y^2-2x+4y-4=0. Chainable, persistent. |
asCenterRadius: Circle | Output option: the form (x-a)^2+(y-b)^2=r^2 (default). Chainable, persistent. |
center: Point | The center, as a point. |
equation: Equation | The equation (x-a)^2+(y-b)^2-r^2=0, as an Equation (a copy). |
radius: Root | The radius, as an exact reduced Root (3, 2sqrt(2)). |
squareRadius: Fraction | The square of the radius, as an exact fraction. It is -1 for a circle that has not been defined. |
Methods
| Member | Description |
|---|---|
parse(...values: unknown[]): Circle | Replace 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(): Circle | Full duplicate of this instance, including display state (selected form and options set via as*** / with***). Distinct from copy. |
withDigits(digits: number | null): Circle | Show 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): Circle | Copy 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): boolean | True when the point satisfies the equation of the circle. |
isEqual(circ: Circle): boolean | True 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 | 2relativePosition(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): Circle | Change 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
| Member | Description |
|---|---|
fromCoordinates(x1: InputValue<Fraction>, y1: InputValue<Fraction>, x2: InputValue<Fraction>, y2: InputValue<Fraction>, x3: InputValue<Fraction>, y3: InputValue<Fraction>): Triangle | Build 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): Triangle | Build 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): Triangle | Build a triangle from its three vertices. Throws: {MathError} if the points are collinear or two of them are the same. |
Properties and getters
| Member | Description |
|---|---|
tex: string | Not implemented on purpose: a triangle has no single equation to display. Throws: {NotImplementedError} always. Describe it through its lines or its vertices. |
display: string | Not implemented on purpose: see tex. Throws: {NotImplementedError} always. |
A: Point | Vertex A. Setting a vertex refreshes the validity and the remarkable lines. |
AB: Vector | The vector from A to B. |
AC: Vector | The vector from A to C. |
B: Point | Vertex B. Setting a vertex refreshes the validity and the remarkable lines. |
BA: Vector | The vector from B to A. |
BC: Vector | The vector from B to C. |
C: Point | Vertex C. Setting a vertex refreshes the validity and the remarkable lines. |
CA: Vector | The vector from C to A. |
CB: Vector | The vector from C to B. |
asDegree: Triangle | Output option: getAngle gives degrees. Chainable, persistent. |
asRadians: Triangle | Output option: getAngle gives radians (default). Chainable, persistent. |
isValid: boolean | False when the three vertices are collinear. |
lines: Record<TriangleSide, Line> | The lines of the sides, as {AB, BC, AC}. |
remarquables: RemarquableLines | The remarkable lines already computed. An entry is null until the matching get*** method is called. |
Methods
| Member | Description |
|---|---|
parse(...values: unknown[]): Triangle | Replace 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(): Triangle | Full duplicate of this instance, including display state (selected form and options set via as*** / with***). Distinct from copy. |
copy(value: Triangle): Triangle | Copies 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"): number | Angle 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): boolean | True when both triangles have the same vertices, whatever their order. |
isEquilateral(): boolean | True when the three sides have the same length. |
isIsocele(): boolean | True when two sides have the same length. |
isRectangle(): boolean | True when two sides are perpendicular. |
reset(): Triangle | Recompute 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. |