Skip to content
Geometry

geometry-ai999x

Plane and solid geometry, coordinate geometry, conic sections, polygons and polyhedra, computational geometry (convex hulls, Voronoi, triangulation) and curves and surfaces.

76capabilities
13topics
76formulas typeset
8worked examples below
1.0.0version
About this model

What Geometry does

Geometry (geometry-ai999x) is an offline Python package for geometry. It covers plane and solid geometry, coordinate geometry, conic sections, polygons and polyhedra, computational geometry (convex hulls, Voronoi, triangulation) and curves and surfaces.

It has 76 capabilities — 76 computational procedures — in 13 topics, the largest being Computational geometry, Coordinate geometry, Plane figures, Solids, Solid coordinate geometry and Polygons. Ask a question in words with ask(), or call a capability by name with typed inputs with solve(). Every answer carries its value and unit, the steps that produced it and the formula in LaTeX.

When a question is not determined — a value is missing, an input is out of range, or the request is outside the package — it says so and names what it needs, instead of guessing. It runs on an ordinary CPU without a network connection (Python >=3.10), and the same question always gets the same answer.

Install

pip install geometry-ai999x
hf download AI999X/geometry-ai999x --local-dir geometry-ai999x

What it covers

Computational geometry12Area of the intersection of two convex polygons · Closest pair of points · Convex hull of points in the plane …Conic sections2Classify a conic section from its general equation · Perimeter of an ellipse (exact, by the complete elliptic integral)Coordinate geometry11Angle between two lines · Barycentric coordinates of a point in a triangle · Circumcircle: the circle through three points …Curves4Arc length of a parabola · Curvature of a polynomial graph at a point · Curvature of an ellipse at a point …Plane figures10Area of a triangle from base and height · Area of an annulus (ring) · Circle: area, circumference and diameter …Polygons7Centroid of a polygon · Interior angles of a polygon from its vertices · Is a polygon convex? …Polyhedra1Platonic solids: counts, Euler characteristic, volume, surface, radiiSolid coordinate geometry8Angle between two planes · Distance between two lines in space (skew or parallel) · Distance from a point to a plane …Solid geometry2Solid angle of a cone · Solid angle subtended by a triangleSolids10Cone: volume, slant height and surface area · Cuboid (rectangular box): volume, surface area, space diagonal · Cylinder: volume and surface area …Spherical geometry3Area and spherical excess of a spherical triangle · Great-circle distance between two points on a sphere · Initial bearing (forward azimuth) along a great circleSurfaces2Curvature of a torus at a point · Gaussian and mean curvature of a quadratic surface z = f(x, y)Transformations4Dilation (enlargement) of a point · Reflection of a point in a line · Rotation of a point …
Try it

Worked examples

Each question below was put to geometry-ai999x and the answer shown is the one it returned, with the steps it took.

Coordinate geometrym.ask(…)

Find the circumcenter and circumradius of the triangle with vertices (0, 0), (4, 0) and (0, 3).

cx = 2
cy = 1.5
radius = 2.5
Show the steps
  1. Circumcircle: the circle through three points
    |O - A| = |O - B| = |O - C| = R
    with points = [0, 0, 4, 0, 0, 3]
    → cx = 2, cy = 1.5, radius = 2.5
Computational geometrym.ask(…)

Find the convex hull of the points (0, 0), (2, 1), (4, 0), (3, 3), (1, 2), (2, 4).

hull = [[0, 0], [4, 0], [3, 3], [2, 4]]
n_vertices = 4
area = 9
perimeter = 13.04862718
Show the steps
  1. Convex hull of points in the plane
    \operatorname{conv}(S) = \{\textstyle\sum \lambda_i p_i : \lambda_i \ge 0, \sum\lambda_i = 1\}
    with points = [0, 0, 2, 1, 4, 0, 3, 3, 1, 2, 2, 4]
    → hull = [[0, 0], [4, 0], [3, 3], [2, 4]], n_vertices = 4, area = 9, perimeter = 13.04862718
Coordinate geometrym.ask(…)

Where does the line y = x + 1 intersect the circle x^2 + y^2 = 25?

count = 2
x1 = -4
y1 = -3
x2 = 3
y2 = 4
Show the steps
  1. Intersection of a circle and a line
    d = \frac{|a c_x + b c_y + c|}{\sqrt{a^2+b^2}},\quad P = F \pm \sqrt{r^2-d^2}\,\frac{(-b, a)}{\sqrt{a^2+b^2}}
    with cx = 0, cy = 0, r = 5, a = -1, b = 1, c = -1
    → count = 2, x1 = -4, y1 = -3, x2 = 3, y2 = 4
Polyhedram.ask(…)

Find the volume and surface area of a regular icosahedron with edge 2.

vertices = 12
edges = 30
faces = 20
euler_characteristic = 2
volume = 17.45355993
surface_area = 34.64101615
Show the steps
  1. Platonic solids: counts, Euler characteristic, volume, surface, radii
    V - E + F = 2,\quad V_{\text{ico}} = \tfrac{5}{12}(3+\sqrt5)\,a^3
    with solid = icosahedron, edge = 2
    → vertices = 12, edges = 30, faces = 20, euler_characteristic = 2, volume = 17.45355993, surface_area = 34.64101615, circumradius = 1.902113033, inradius = 1.511522628
Spherical geometrym.solve(…)
m.solve("great_circle_distance", lat1=51.5074, lon1=-0.1278, lat2=40.7128, lon2=-74.006)
central_angle = 50.09421156
distance = 5570.22218
Show the steps
  1. Great-circle distance between two points on a sphere
    h = \sin^2\tfrac{\Delta\varphi}{2} + \cos\varphi_1\cos\varphi_2\sin^2\tfrac{\Delta\lambda}{2},\quad d = 2R\,\operatorname{atan2}(\sqrt h, \sqrt{1-h})
    with lat1 = 51.5074, lon1 = -0.1278, lat2 = 40.7128, lon2 = -74.006
    → central_angle = 50.09421156, distance = 5570.22218
Conic sectionsm.ask(…)

Classify the conic x^2 + 4y^2 - 4 = 0.

type = ellipse
Show the steps
  1. Classify a conic section from its general equation
    \Delta = \det\begin{pmatrix}A & B/2 & D/2\\ B/2 & C & E/2\\ D/2 & E/2 & F\end{pmatrix},\quad B^2 - 4AC \lessgtr 0
    with A = 1, B = 0, C = 4, D = 0, E = 0, F = -4
    → type = ellipse
Curvesm.ask(…)

Find the curvature of y = x^2 at x = 0.

curvature = 2
radius_of_curvature = 0.5
slope = 0
Show the steps
  1. Curvature of a polynomial graph at a point
    \kappa = \frac{|y''|}{(1+y'^2)^{3/2}},\quad R = \frac1\kappa
    with coefficients = [1, 0, 0], x0 = 0
    → curvature = 2, radius_of_curvature = 0.5, slope = 0
Plane figuresm.ask(…)

Find the area of an annulus with outer radius 5 and inner radius 3.

area = 50.26548246
Show the steps
  1. Area of an annulus (ring)
    A = \pi (R^2 - r^2)
    with outer = 5, inner = 3
    → area = 50.26548246
Use it

From Python or the command line

Every snippet was run as shown; the output under it is what it printed.

import geometry_ai999x as m

a = m.ask("Find the circumcenter and circumradius of the triangle with vertices (0, 0), (4, 0) and (0, 3).")
print(a.outcome)
print(a.values)
for step in a.steps:
    print(step["name"])
Output
SOLVED
{'cx': 2.0, 'cy': 1.5, 'radius': 2.5}
Circumcircle: the circle through three points
Figures

Computed, not drawn by hand

Every value in these figures was computed by the package, each point a run of solve(); in a notebook, plot() and plot_relation() draw a capability's curves the same way.

Convex hull and smallest enclosing circle of ten points

\operatorname{conv}(S) = \{\textstyle\sum \lambda_i p_i : \lambda_i \ge 0, \sum\lambda_i = 1\}
Convex hull and smallest enclosing circle of ten pointsTen points (0 0, 5 5, 1 1, 9 2, 6 6.5, 3 7, 7 3, 2 4, 8 6, 4 1.5), their convex hull as returned by the package — 5 vertices, area 38.25, perimeter 26.0614 — and the smallest circle enclosing them; marked: its centre x = 4.07895, y = 2.89474, radius 5.00173.0510-2.502.557.5(4.07895, 2.89474)smallest enclosing circleconvex hullpointsxy
Ten points (0 0, 5 5, 1 1, 9 2, 6 6.5, 3 7, 7 3, 2 4, 8 6, 4 1.5), their convex hull as returned by the package — 5 vertices, area 38.25, perimeter 26.0614 — and the smallest circle enclosing them; marked: its centre x = 4.07895, y = 2.89474, radius 5.00173.

A triangle's circles and centres

|O - A| = |O - B| = |O - C| = R
A triangle's circles and centresThe triangle with vertices 0 0, 4 0, 1 3: circumcircle (centre O = (2, 1), radius 2.23607), incircle (centre I = (1.45982, 1.05218), radius 1.05218), orthocentre H = (1, 1) and centroid G = (1.66667, 1), each computed by the package; O, G and H lie on the Euler line.02402OIHGcircumcircleincircletriangleEuler linexy
The triangle with vertices 0 0, 4 0, 1 3: circumcircle (centre O = (2, 1), radius 2.23607), incircle (centre I = (1.45982, 1.05218), radius 1.05218), orthocentre H = (1, 1) and centroid G = (1.66667, 1), each computed by the package; O, G and H lie on the Euler line.

A polygon's angles, area and centroid

C_x = \frac{1}{6A}\sum_i (x_i + x_{i+1})(x_i y_{i+1} - x_{i+1} y_i)
A polygon's angles, area and centroidThe L-shaped polygon 0 0, 6 0, 6 2, 2 2, 2 5, 0 5, with the interior angle at each vertex (sum 720°, 1 reflex), area 18 and perimeter 22; marked: the centroid x = 2.33333, y = 1.83333 — all computed by the package. The centroid of a non-convex shape need not be its middle.024602490°90°90°270°90°90°centroid (2.33333, 1.83333)polygonxy
The L-shaped polygon 0 0, 6 0, 6 2, 2 2, 2 5, 0 5, with the interior angle at each vertex (sum 720°, 1 reflex), area 18 and perimeter 22; marked: the centroid x = 2.33333, y = 1.83333 — all computed by the package. The centroid of a non-convex shape need not be its middle.

Tangent lines from an outside point to a circle

L = \sqrt{|P-C|^2 - r^2},\quad T = C + \frac{r^2}{d^2}(P-C) \pm \frac{rL}{d^2}(P-C)^{\perp}
Tangent lines from an outside point to a circleTangents from P = (5, 0) to the circle of centre C = (0, 0) and radius 3: the package gives the touching points (1.8, -2.4) and (1.8, 2.4) and the tangent length 4. The circle on the diameter CP meets the circle at the same two points (its intersection, also computed by the package: (1.8, -2.4) and (1.8, 2.4)).-2.502.55-202CPcirclecircle on the diameter CPtangentradiusxy
Tangents from P = (5, 0) to the circle of centre C = (0, 0) and radius 3: the package gives the touching points (1.8, -2.4) and (1.8, 2.4) and the tangent length 4. The circle on the diameter CP meets the circle at the same two points (its intersection, also computed by the package: (1.8, -2.4) and (1.8, 2.4)).

Rotation, reflection and dilation of a triangle

\begin{pmatrix}x'\\y'\end{pmatrix} = \begin{pmatrix}\cos\theta & -\sin\theta\\ \sin\theta & \cos\theta\end{pmatrix}\begin{pmatrix}x-c_x\\y-c_y\end{pmatrix} + \begin{pmatrix}c_x\\c_y\end{pmatrix}
Rotation, reflection and dilation of a triangleThe triangle (1, 1), (4, 1), (2, 3) and three images, each vertex mapped by the package: rotated 90° about the origin ((-1, 1), (-1, 4), (-3, 2)), reflected in the line x + y = 0 ((-1, -1), (-1, -4), (-3, -2)) and dilated about the origin by −0.5 ((-0.5, -0.5), (-2, -0.5), (-1, -1.5)).-505-5-2.502.55mirror x + y = 0originalrotated 90° about Oreflecteddilated by −0.5xy
The triangle (1, 1), (4, 1), (2, 3) and three images, each vertex mapped by the package: rotated 90° about the origin ((-1, 1), (-1, 4), (-3, 2)), reflected in the line x + y = 0 ((-1, -1), (-1, -4), (-3, -2)) and dilated about the origin by −0.5 ((-0.5, -0.5), (-2, -0.5), (-1, -1.5)).

Angles of regular polygons, 3 to 20 sides

\theta_{int} = \frac{(n-2)\,180^\circ}{n},\quad \theta_{ext} = \frac{360^\circ}{n},\quad D = \frac{n(n-3)}{2}
Angles of regular polygons, 3 to 20 sidesInterior and exterior angles of the regular polygons with 3 to 20 sides, each computed by the package: the interior angle climbs towards 180° (triangle 60°, 20-gon 162°) while the exterior angle 360°/n falls; marked: n = 6, interior angle = 120°.5101520050100150180°hexagon 120°interior angleexterior anglen — number of sidesangle [°]
Interior and exterior angles of the regular polygons with 3 to 20 sides, each computed by the package: the interior angle climbs towards 180° (triangle 60°, 20-gon 162°) while the exterior angle 360°/n falls; marked: n = 6, interior angle = 120°.
Formulas

The mathematics inside

12 of its 76 formulas; every one is in the capability browser below.

Circumcircle: the circle through three points
|O - A| = |O - B| = |O - C| = R
Convex hull of points in the plane
\operatorname{conv}(S) = \{\textstyle\sum \lambda_i p_i : \lambda_i \ge 0, \sum\lambda_i = 1\}
Intersection of a circle and a line
d = \frac{|a c_x + b c_y + c|}{\sqrt{a^2+b^2}},\quad P = F \pm \sqrt{r^2-d^2}\,\frac{(-b, a)}{\sqrt{a^2+b^2}}
Platonic solids: counts, Euler characteristic, volume, surface, radii
V - E + F = 2,\quad V_{\text{ico}} = \tfrac{5}{12}(3+\sqrt5)\,a^3
Great-circle distance between two points on a sphere
h = \sin^2\tfrac{\Delta\varphi}{2} + \cos\varphi_1\cos\varphi_2\sin^2\tfrac{\Delta\lambda}{2},\quad d = 2R\,\operatorname{atan2}(\sqrt h, \sqrt{1-h})
Classify a conic section from its general equation
\Delta = \det\begin{pmatrix}A & B/2 & D/2\\ B/2 & C & E/2\\ D/2 & E/2 & F\end{pmatrix},\quad B^2 - 4AC \lessgtr 0
Curvature of a polynomial graph at a point
\kappa = \frac{|y''|}{(1+y'^2)^{3/2}},\quad R = \frac1\kappa
Area of an annulus (ring)
A = \pi (R^2 - r^2)
Perimeter of an ellipse (exact, by the complete elliptic integral)
P = 4a\,E(e),\quad E(m) = \frac{\pi}{2\,\mathrm{AGM}(1,\sqrt{1-m})}\Big(1 - \sum_{n\ge0} 2^{n-1} c_n^2\Big)
Angle between two lines
\tan\theta = \left|\frac{a_1b_2 - a_2b_1}{a_1a_2 + b_1b_2}\right|
Arc length of a parabola
L = \frac{1}{2a}\Big[\tfrac12\big(u\sqrt{1+u^2} + \operatorname{arsinh} u\big)\Big]_{u_0}^{u_1},\quad u = 2ax + b
Capabilities

Every capability, with an example

Search by name, formula, input or topic. Each capability opens to show what it takes, what it returns, when it applies, and a question it answered.

76 capabilities

Computational geometry 12

Area of the intersection of two convex polygonsconvex_polygon_intersection

The area common to two convex polygons given by their vertices.

A(P \cap Q)

Inputs

  • p first convex polygon's vertices in order vector
  • q second convex polygon's vertices in order vector

Returns

  • area area of the intersection (0 if they do not overlap)

Applies when

  • both polygons simple and convex

Example

m.ask("Find the area of intersection of the polygon with vertices (0, 0), (2, 0), (2, 2), (0, 2) and the polygon with vertices (1, 1), (3, 1), (3, 3), (1, 3).")
→ area = 1
Closest pair of pointsclosest_pair

The smallest distance between any two of a set of points in the plane.

\delta = \min_{i<j} \|p_i - p_j\|

Inputs

  • points the points: x1 y1, x2 y2, ... vector

Returns

  • distance smallest pairwise distance

Applies when

  • at least 2 points, at most 2000
  • a repeated point gives distance 0

Example

m.ask("Find the closest pair distance among the points (0, 0), (5, 5), (1, 1), (9, 2), (6, 6.5).")
→ distance = 1.41421
Convex hull of points in the planeconvex_hull

The convex hull of a set of points: its vertices (counterclockwise), their number, its area and perimeter.

\operatorname{conv}(S) = \{\textstyle\sum \lambda_i p_i : \lambda_i \ge 0, \sum\lambda_i = 1\}

Inputs

  • points the points: x1 y1, x2 y2, ... vector

Returns

  • hull hull vertices [x, y], counterclockwise from the smallest x (then smallest y)
  • n_vertices number of hull vertices
  • area area of the hull
  • perimeter perimeter of the hull

Applies when

  • at least 3 points, not all collinear, at most 5000
  • points on a hull edge between two vertices are not vertices
  • repeated points count once

Example

m.ask("Find the convex hull of the points (0, 0), (2, 1), (4, 0), (3, 3), (1, 2), (2, 4).")
→ hull = [[0.0, 0.0], [4.0, 0.0], [3.0, 3.0], [2.0, 4.0]], n_vertices = 4, area = 9, perimeter = 13.0486
Delaunay triangulation and Voronoi diagram: countsdelaunay_voronoi_counts

Numbers of Delaunay triangles and edges, hull vertices, Voronoi vertices and unbounded Voronoi cells of points in general position.

T = 2n - 2 - h,\quad E = 3n - 3 - h

Inputs

  • points the points: x1 y1, x2 y2, ... (3 to 25) vector

Returns

  • triangles Delaunay triangles 2n - 2 - h
  • edges Delaunay edges 3n - 3 - h
  • hull_vertices h, vertices of the convex hull
  • voronoi_vertices Voronoi vertices (one per triangle)
  • unbounded_cells unbounded Voronoi cells (one per hull vertex)

Applies when

  • 3 to 25 distinct points
  • general position: no three collinear, no four concyclic (checked exactly)

Example

m.ask("How many triangles are in the Delaunay triangulation of the points (0, 0), (4, 0), (0, 3), (5, 4), (2, 1)?")
→ triangles = 4, edges = 8, hull_vertices = 4, voronoi_vertices = 4, unbounded_cells = 4
Distance from a point to a segmentpoint_segment_distance

The shortest distance from a point to the segment AB and the closest point of the segment.

t^* = \operatorname{clamp}\!\left(\frac{(P-A)\cdot(B-A)}{\|B-A\|^2}, 0, 1\right),\quad d = \|P - (A + t^*(B-A))\|

Inputs

  • px x of the point
  • py y of the point
  • x1 x of A
  • y1 y of A
  • x2 x of B
  • y2 y of B

Returns

  • distance shortest distance
  • qx x of the closest point
  • qy y of the closest point

Applies when

  • A != B

Example

m.ask("Find the distance from the point (3, 4) to the segment from (0, 0) to (6, 0).")
→ distance = 4, qx = 3, qy = 0
Farthest pair of points (diameter of a point set)farthest_pair

The largest distance between any two of a set of points in the plane.

D = \max_{i<j} \|p_i - p_j\|

Inputs

  • points the points: x1 y1, x2 y2, ... vector

Returns

  • distance largest pairwise distance

Applies when

  • at least 2 points, at most 5000

Example

m.ask("Find the farthest pair distance among the points (0, 0), (3, 4), (1, 1), (2, 2).")
→ distance = 5
Hausdorff distance between two point setshausdorff_distance

The Hausdorff distance between two finite point sets and both directed distances.

d_H(A,B) = \max\{\sup_{a}\inf_{b}\|a-b\|,\ \sup_{b}\inf_{a}\|a-b\|\}

Inputs

  • a first set: x1 y1, x2 y2, ... vector
  • b second set vector

Returns

  • distance max of the two directed distances
  • from_a max over A of the distance to the nearest point of B
  • from_b max over B of the distance to the nearest point of A

Applies when

  • 1 to 1000 points per set

Example

m.ask("Find the Hausdorff distance between the set (0, 0), (1, 0) and the set (0, 0), (3, 4).")
→ distance = 4.47214, from_a = 1, from_b = 4.47214
Intersection of two line segmentssegment_intersection

Whether segments AB and CD meet, and where: at one point, along an overlap, or not at all.

A + t(B-A) = C + u(D-C),\quad 0 \le t, u \le 1

Inputs

  • points the endpoints A, B, C, D: xA yA, xB yB, xC yC, xD yD vector

Returns

  • status point / overlap / none
  • x x of the common point (point only)
  • y y of the common point (point only)

Applies when

  • each segment has distinct endpoints
  • decided exactly on the written coordinates (touching counts as meeting)

Example

m.ask("Do the segments from (0, 0) to (4, 4) and from (0, 4) to (4, 0) intersect?")
→ status = point, x = 2, y = 2
Minimum-area enclosing rectanglemin_area_rectangle

The area (and sides) of the smallest-area rectangle, in any orientation, enclosing the points.

A^* = \min_{e \in \text{hull edges}} w_e\, h_e

Inputs

  • points the points: x1 y1, x2 y2, ... vector

Returns

  • area minimum area
  • width shorter side of that rectangle
  • length longer side

Applies when

  • at least 3 points, not all collinear
  • when two orientations tie in area, the sides of the first found are reported

Example

m.ask("Find the minimum area bounding rectangle of the points (0, 0), (2, 2), (4, 0), (2, -2).")
→ area = 8, width = 2.82843, length = 2.82843
Nearest neighbour of a query pointnearest_neighbor

Which of a list of points is nearest to a query point, and how far it is.

k^* = \arg\min_k \|p_k - q\|

Inputs

  • px x of the query point
  • py y of the query point
  • points the candidate points: x1 y1, x2 y2, ... vector

Returns

  • index position of the nearest point in the list (1 = first)
  • distance its distance
  • nx its x
  • ny its y

Applies when

  • ties go to the earliest point in the list

Example

m.ask("Which of the points (0, 0), (5, 5), (2, 3) is nearest to the point (3, 3)?")
→ index = 3, distance = 1, nx = 2, ny = 3
Point in polygon testpoint_in_polygon

Whether a point lies inside, outside or on the boundary of a simple polygon.

\text{inside} \iff \#\{\text{edges crossed by the ray } y = p_y, x > p_x\} \text{ is odd}

Inputs

  • px x of the point
  • py y of the point
  • points polygon vertices in order: x1 y1, x2 y2, ... vector

Returns

  • location inside / outside / boundary

Applies when

  • simple polygon with at least 3 vertices
  • decided exactly on the written coordinates

Example

m.ask("Is the point (2, 3) inside the polygon with vertices (0, 0), (5, 0), (5, 5), (0, 5)?")
→ location = inside
Smallest enclosing circle of pointsmin_enclosing_circle

Centre and radius of the smallest circle that contains every given point.

\min_{c, r} r \;\text{ s.t. } \|p_i - c\| \le r\ \forall i

Inputs

  • points the points: x1 y1, x2 y2, ... vector

Returns

  • cx x of the centre
  • cy y of the centre
  • radius radius

Applies when

  • 1 to 2000 points
  • the smallest enclosing circle is unique

Example

m.ask("Find the smallest enclosing circle of the points (0, 0), (4, 0), (2, 1).")
→ cx = 2, cy = 0, radius = 2

Conic sections 2

Classify a conic section from its general equationconic_classify

Whether A x^2 + B xy + C y^2 + D x + E y + F = 0 is a circle, ellipse, parabola, hyperbola, a degenerate conic or has no real points.

\Delta = \det\begin{pmatrix}A & B/2 & D/2\\ B/2 & C & E/2\\ D/2 & E/2 & F\end{pmatrix},\quad B^2 - 4AC \lessgtr 0

Inputs

  • A coefficient of x^2
  • B coefficient of xy
  • C coefficient of y^2
  • D coefficient of x
  • E coefficient of y
  • F constant term

Returns

  • type circle / ellipse / parabola / hyperbola / degenerate / empty

Applies when

  • A, B, C not all 0
  • exact on the written coefficients
  • 'degenerate' = a point, a pair of lines or a degenerate equation (zero 3x3 determinant); 'empty' = an ellipse with no real points

Example

m.ask("Classify the conic x^2 + 4y^2 - 4 = 0.")
→ type = ellipse
Perimeter of an ellipse (exact, by the complete elliptic integral)ellipse_perimeter

The exact perimeter (circumference) and area of an ellipse with semi-axes a and b.

P = 4a\,E(e),\quad E(m) = \frac{\pi}{2\,\mathrm{AGM}(1,\sqrt{1-m})}\Big(1 - \sum_{n\ge0} 2^{n-1} c_n^2\Big)

Inputs

  • a one semi-axis
  • b the other semi-axis

Returns

  • perimeter 4 a E(e^2), a the larger semi-axis
  • area pi a b

Applies when

  • a, b > 0
  • axis ratio at least 0.001

Example

m.ask("Find the perimeter of an ellipse with semi-major axis 5 and semi-minor axis 3.")
→ perimeter = 25.527, area = 47.1239

Coordinate geometry 11

Angle between two linesangle_between_lines

The acute (or right) angle between two lines given by equations.

\tan\theta = \left|\frac{a_1b_2 - a_2b_1}{a_1a_2 + b_1b_2}\right|

Inputs

  • a1 coefficient of x in line 1 (a1 x + b1 y + c1 = 0)
  • b1 coefficient of y in line 1
  • c1 constant of line 1
  • a2 coefficient of x in line 2 (a2 x + b2 y + c2 = 0)
  • b2 coefficient of y in line 2
  • c2 constant of line 2

Returns

  • angle angle between the lines, degrees, 0 to 90

Applies when

  • each line has a or b nonzero
  • the acute angle is reported (parallel lines: 0)

Example

m.ask("Find the angle between the lines y = x + 1 and y = -x + 3.")
→ angle = 90
Barycentric coordinates of a point in a trianglebarycentric_coordinates

The barycentric coordinates (l1, l2, l3) of a point with respect to triangle ABC: P = l1 A + l2 B + l3 C, l1 + l2 + l3 = 1.

\lambda_1 = \frac{[PBC]}{[ABC]},\ \lambda_2 = \frac{[APC]}{[ABC]},\ \lambda_3 = \frac{[ABP]}{[ABC]}

Inputs

  • px x of the point
  • py y of the point
  • points the triangle's vertices A, B, C vector

Returns

  • l1 weight of A
  • l2 weight of B
  • l3 weight of C

Applies when

  • A, B, C not collinear
  • all weights positive exactly when P is inside

Example

m.ask("Find the barycentric coordinates of the point (1, 1) in the triangle with vertices (0, 0), (4, 0), (0, 4).")
→ l1 = 0.5, l2 = 0.25, l3 = 0.25
Circumcircle: the circle through three pointstriangle_circumcircle

Circumcentre and circumradius of a triangle given by its vertices (the circle through three points).

|O - A| = |O - B| = |O - C| = R

Inputs

  • points the three points: x1 y1, x2 y2, x3 y3 vector

Returns

  • cx x of the circumcentre
  • cy y of the circumcentre
  • radius circumradius

Applies when

  • exactly 3 points
  • not collinear

Example

m.ask("Find the circumcenter and circumradius of the triangle with vertices (0, 0), (4, 0) and (0, 3).")
→ cx = 2, cy = 1.5, radius = 2.5
Incircle of a triangle: incentre and inradiustriangle_incircle

Incentre and inradius of the triangle with the given vertices.

I = \frac{aA + bB + cC}{a+b+c},\quad r = \frac{2K}{a+b+c}

Inputs

  • points the vertices: xA yA, xB yB, xC yC vector

Returns

  • ix x of the incentre
  • iy y of the incentre
  • radius inradius

Applies when

  • exactly 3 points
  • not collinear

Example

m.ask("Find the incenter and inradius of the triangle with vertices (0, 0), (4, 0) and (0, 3).")
→ ix = 1, iy = 1, radius = 1
Intersection of a circle and a linecircle_line_intersection

The points where the line a x + b y + c = 0 meets the circle with centre (cx, cy) and radius r (0, 1 or 2 points).

d = \frac{|a c_x + b c_y + c|}{\sqrt{a^2+b^2}},\quad P = F \pm \sqrt{r^2-d^2}\,\frac{(-b, a)}{\sqrt{a^2+b^2}}

Inputs

  • cx x of the centre
  • cy y of the centre
  • r radius
  • a coefficient of x of the line
  • b coefficient of y of the line
  • c constant of the line

Returns

  • count number of intersection points (0, 1 or 2)
  • x1 x of the first point (ordered by x, then y)
  • y1 y of the first point
  • x2 x of the second point
  • y2 y of the second point

Applies when

  • r > 0
  • a and b not both 0
  • tangency is decided exactly on the written values
  • points ordered by x, then y; absent points are empty

Example

m.ask("Where does the line y = x + 1 intersect the circle x^2 + y^2 = 25?")
→ count = 2, x1 = -4, y1 = -3, x2 = 3, y2 = 4
Intersection of two circlescircle_circle_intersection

The points where two circles meet (0, 1 or 2 points).

a = \frac{d^2 + r_1^2 - r_2^2}{2d},\quad h = \sqrt{r_1^2 - a^2}

Inputs

  • x1 x of the first centre
  • y1 y of the first centre
  • r1 first radius
  • x2 x of the second centre
  • y2 y of the second centre
  • r2 second radius

Returns

  • count number of intersection points (0, 1 or 2)
  • x1 x of the first point (ordered by x, then y)
  • y1 y of the first point
  • x2 x of the second point
  • y2 y of the second point

Applies when

  • r1, r2 > 0
  • the circles are not identical
  • tangency decided exactly on the written values
  • points ordered by x, then y

Example

m.ask("Find the intersection points of the circle with center (0, 0) and radius 5 and the circle with center (6, 0) and radius 5.")
→ count = 2, x1 = 3, y1 = -4, x2 = 3, y2 = 4
Intersection point of two linesline_intersection

The point where two lines a1 x + b1 y + c1 = 0 and a2 x + b2 y + c2 = 0 meet.

x = \frac{b_1c_2 - b_2c_1}{a_1b_2 - a_2b_1},\quad y = \frac{c_1a_2 - c_2a_1}{a_1b_2 - a_2b_1}

Inputs

  • a1 coefficient of x in line 1 (a1 x + b1 y + c1 = 0)
  • b1 coefficient of y in line 1
  • c1 constant of line 1
  • a2 coefficient of x in line 2 (a2 x + b2 y + c2 = 0)
  • b2 coefficient of y in line 2
  • c2 constant of line 2

Returns

  • x x of the intersection
  • y y of the intersection

Applies when

  • each line has a or b nonzero
  • the lines are not parallel (exact test on the written coefficients)

Example

m.ask("Find the intersection of the lines 2x + y = 5 and x - y = 1.")
→ x = 2, y = 1
Length of a polyline (path through points)polyline_length

The total length of the open path that visits the points in the order given.

L = \sum_{i=1}^{n-1} \|p_{i+1} - p_i\|

Inputs

  • points the points in order: x1 y1, x2 y2, ... vector

Returns

  • length sum of the segment lengths
  • segments number of segments

Applies when

  • at least 2 points
  • the path is open (not closed back to the start)

Example

m.ask("Find the length of the path through (0, 0), (3, 4) and (3, 10).")
→ length = 11, segments = 2
Orthocentre of a triangletriangle_orthocenter

The orthocentre (common point of the three altitudes) of the triangle with the given vertices.

(H-A)\cdot(C-B) = 0,\quad (H-B)\cdot(C-A) = 0

Inputs

  • points the vertices: xA yA, xB yB, xC yC vector

Returns

  • hx x of the orthocentre
  • hy y of the orthocentre

Applies when

  • exactly 3 points
  • not collinear

Example

m.ask("Find the orthocenter of the triangle with vertices (0, 0), (4, 0) and (1, 3).")
→ hx = 1, hy = 1
Tangents from a point to a circletangent_from_point

The tangent length from an external point to a circle and the two points of tangency.

L = \sqrt{|P-C|^2 - r^2},\quad T = C + \frac{r^2}{d^2}(P-C) \pm \frac{rL}{d^2}(P-C)^{\perp}

Inputs

  • cx x of the centre
  • cy y of the centre
  • r radius
  • px x of the external point
  • py y of the external point

Returns

  • length tangent length sqrt(d^2 - r^2)
  • x1 x of the first tangency point (ordered by x, then y)
  • y1 y of the first tangency point
  • x2 x of the second tangency point
  • y2 y of the second tangency point

Applies when

  • r > 0
  • the point is not inside the circle (on the circle: length 0, both points at the point)

Example

m.ask("Find the length of the tangent from the point (5, 0) to the circle with center (0, 0) and radius 3.")
→ length = 4, x1 = 1.8, y1 = -2.4, x2 = 1.8, y2 = 2.4
Triangle from vertex coordinates: area, perimeter, centroid, anglestriangle_coordinates

Area, perimeter, centroid and the angles at A, B, C of the triangle with vertices A, B, C.

K = \tfrac12 |(x_B-x_A)(y_C-y_A) - (x_C-x_A)(y_B-y_A)|,\quad G = \tfrac13(A+B+C)

Inputs

  • points the vertices A, B, C: xA yA, xB yB, xC yC vector

Returns

  • area area (shoelace)
  • perimeter perimeter
  • gx x of the centroid
  • gy y of the centroid
  • angle_A angle at A, degrees
  • angle_B angle at B, degrees
  • angle_C angle at C, degrees

Applies when

  • exactly 3 vertices
  • not collinear

Example

m.ask("Find the area of the triangle with vertices (0, 0), (4, 0) and (0, 3).")
→ area = 6, perimeter = 12, gx = 1.33333, gy = 1, angle_A = 90, angle_B = 36.8699, angle_C = 53.1301

Curves 4

Arc length of a parabolaparabola_arc_length

The length of the curve y = a x^2 + b x + c between x = x0 and x = x1.

L = \frac{1}{2a}\Big[\tfrac12\big(u\sqrt{1+u^2} + \operatorname{arsinh} u\big)\Big]_{u_0}^{u_1},\quad u = 2ax + b

Inputs

  • a coefficient of x^2
  • b coefficient of x
  • x0 start x
  • x1 end x
  • c constant (does not affect the length) optional

Returns

  • length arc length

Applies when

  • x0 != x1 (either order)

Example

m.ask("Find the arc length of y = x^2 from x = 0 to x = 1.")
→ length = 1.47894
Curvature of a polynomial graph at a pointcurvature_of_graph

The curvature and radius of curvature of y = p(x) at x = x0 for a polynomial p.

\kappa = \frac{|y''|}{(1+y'^2)^{3/2}},\quad R = \frac1\kappa

Inputs

  • coefficients coefficients from the highest power down: a_n, ..., a_1, a_0 vector
  • x0 the x-coordinate of the point

Returns

  • curvature |y''| / (1 + y'^2)^(3/2)
  • radius_of_curvature 1 / curvature (none where the curvature is 0)
  • slope y'(x0)

Applies when

  • polynomial of degree at most 10

Example

m.ask("Find the curvature of y = x^2 at x = 0.")
→ curvature = 2, radius_of_curvature = 0.5, slope = 0
Curvature of an ellipse at a pointellipse_curvature

The curvature and radius of curvature of the ellipse (a cos t, b sin t) at parameter t (eccentric anomaly).

\kappa(t) = \frac{ab}{(a^2\sin^2 t + b^2\cos^2 t)^{3/2}}

Inputs

  • a semi-axis along x
  • b semi-axis along y
  • t parameter t (eccentric anomaly), degrees

Returns

  • curvature ab / (a^2 sin^2 t + b^2 cos^2 t)^(3/2)
  • radius_of_curvature 1 / curvature
  • x x of the point
  • y y of the point

Applies when

  • a, b > 0
  • the point is (a cos t, b sin t); 'end of the major/minor axis' means t = 0 / 90 degrees

Example

m.ask("Find the curvature of the ellipse with semi-major axis 5 and semi-minor axis 3 at the end of the major axis.")
→ curvature = 0.555556, radius_of_curvature = 1.8, x = 5, y = 0
Helix: curvature, torsion and length per turnhelix_measures

Curvature, torsion and arc length per turn of the circular helix of radius r and pitch p (rise per turn).

\kappa = \frac{r}{r^2+c^2},\quad \tau = \frac{c}{r^2+c^2},\quad c = \frac{p}{2\pi}

Inputs

  • radius radius r of the helix
  • pitch pitch p: rise per full turn (negative: left-handed)

Returns

  • curvature r / (r^2 + c^2), c = p / (2 pi)
  • torsion c / (r^2 + c^2)
  • length_per_turn sqrt((2 pi r)^2 + p^2)

Applies when

  • radius > 0
  • parametrised (r cos t, r sin t, c t)

Example

m.ask("Find the curvature and torsion of a helix with radius 1 and pitch 6.283185307179586.")
→ curvature = 0.5, torsion = 0.5, length_per_turn = 8.88577

Plane figures 10

Area of a triangle from base and heighttriangle_area_base_height

The area of a triangle from a base and the height (altitude) to that base.

A = \tfrac{1}{2} b h

Inputs

  • base length of the base
  • height height perpendicular to the base

Returns

  • area area b*h/2

Applies when

  • base > 0
  • height > 0

Example

m.ask("Find the area of a triangle with base 10 and height 6.")
→ area = 30
Area of an annulus (ring)annulus_area

The area between two concentric circles.

A = \pi (R^2 - r^2)

Inputs

  • outer outer radius
  • inner inner radius

Returns

  • area pi (R^2 - r^2)

Applies when

  • 0 < inner < outer

Example

m.ask("Find the area of an annulus with outer radius 5 and inner radius 3.")
→ area = 50.2655
Circle: area, circumference and diametercircle_measures

Area, circumference and diameter of a circle from its radius (or diameter).

A = \pi r^2,\quad C = 2\pi r

Inputs

  • radius radius of the circle

Returns

  • area area pi r^2
  • circumference circumference 2 pi r
  • diameter diameter 2r

Applies when

  • radius > 0

Example

m.ask("Find the area of a circle with radius 3.")
→ area = 28.2743, circumference = 18.8496, diameter = 6
Circular sector: arc length, area and chordsector_measures

Arc length, sector area and chord of a circular sector from the radius and central angle.

s = r\theta,\quad A = \tfrac{1}{2} r^2\theta,\quad c = 2r\sin\tfrac{\theta}{2}

Inputs

  • radius radius
  • angle central angle in degrees

Returns

  • arc_length r theta (theta in radians)
  • sector_area r^2 theta / 2
  • chord 2 r sin(theta/2)

Applies when

  • radius > 0
  • 0 < angle <= 360 degrees

Example

m.ask("Find the arc length and area of a sector with radius 6 and central angle 60 degrees.")
→ arc_length = 6.28319, sector_area = 18.8496, chord = 6
Circular segment: area, chord, height, arccircular_segment

Area, chord, height (sagitta) and arc length of the circular segment cut off by a chord with a given central angle.

A = \tfrac12 r^2(\theta - \sin\theta),\quad c = 2r\sin\tfrac{\theta}{2},\quad h = r\left(1-\cos\tfrac{\theta}{2}\right)

Inputs

  • radius radius
  • angle central angle in degrees

Returns

  • area r^2 (theta - sin theta)/2
  • chord 2 r sin(theta/2)
  • height r (1 - cos(theta/2))
  • arc_length r theta

Applies when

  • radius > 0
  • 0 < angle < 360 degrees

Example

m.ask("Find the area of the circular segment with radius 10 and central angle 60 degrees.")
→ area = 9.05861, chord = 10, height = 1.33975, arc_length = 10.472
Classify a triangle by its sides and anglestriangle_classify

Whether a triangle with sides a, b, c is equilateral, isosceles or scalene, and acute, right or obtuse.

x^2 + y^2 \gtreqless z^2 \;\Leftrightarrow\; \text{acute / right / obtuse}

Inputs

  • a side a
  • b side b
  • c side c

Returns

  • by_sides equilateral / isosceles / scalene
  • by_angles acute / right / obtuse

Applies when

  • a, b, c > 0
  • triangle inequality
  • the sides are compared exactly as written

Example

m.ask("Classify the triangle with sides 3, 4 and 5.")
→ by_sides = scalene, by_angles = right
Medians, altitudes and angle bisectors of a triangletriangle_cevians

The lengths of the three medians, three altitudes and three internal angle bisectors of a triangle from its sides.

m_a = \tfrac12\sqrt{2b^2+2c^2-a^2},\quad h_a = \frac{2K}{a},\quad t_a = \frac{\sqrt{bc\,[(b+c)^2-a^2]}}{b+c}

Inputs

  • a side a (opposite A)
  • b side b (opposite B)
  • c side c (opposite C)

Returns

  • median_a median from vertex A (to side a)
  • median_b median from vertex B (to side b)
  • median_c median from vertex C (to side c)
  • altitude_a altitude from vertex A (to side a)
  • altitude_b altitude from vertex B (to side b)
  • altitude_c altitude from vertex C (to side c)
  • bisector_a bisector from vertex A (to side a)
  • bisector_b bisector from vertex B (to side b)
  • bisector_c bisector from vertex C (to side c)

Applies when

  • a, b, c > 0
  • triangle inequality

Example

m.ask("Find the medians of a triangle with sides 3, 4 and 5.")
→ median_a = 4.272, median_b = 3.60555, median_c = 2.5, altitude_a = 4, altitude_b = 3, altitude_c = 2.4, bisector_a = 4.21637, bisector_b = 3.3541, bisector_c = 2.42437
Rectangle: area, perimeter and diagonalrectangle_measures

Area, perimeter and diagonal of a rectangle (a square when length = width).

A = lw,\quad P = 2(l+w),\quad d = \sqrt{l^2+w^2}

Inputs

  • length length of the rectangle
  • width width of the rectangle

Returns

  • area area l*w
  • perimeter perimeter 2(l + w)
  • diagonal diagonal sqrt(l^2 + w^2)

Applies when

  • length > 0
  • width > 0

Example

m.ask("Find the area and perimeter of a rectangle with length 8 and width 5.")
→ area = 40, perimeter = 26, diagonal = 9.43398
Rhombus from its diagonals: area, side, perimeterrhombus_measures

Area, side and perimeter of a rhombus from its two diagonals.

A = \tfrac{1}{2} d_1 d_2,\quad s = \tfrac{1}{2}\sqrt{d_1^2+d_2^2}

Inputs

  • d1 first diagonal
  • d2 second diagonal

Returns

  • area d1 d2 / 2
  • side sqrt(d1^2 + d2^2)/2
  • perimeter 4 * side

Applies when

  • d1, d2 > 0 (the diagonals of a rhombus bisect each other at right angles)

Example

m.ask("Find the area of a rhombus with diagonals 6 and 8.")
→ area = 24, side = 5, perimeter = 20
Trapezoid: area and midsegmenttrapezoid_measures

Area and midsegment (median) of a trapezoid from its parallel sides and height.

A = \frac{(a+b)\,h}{2}

Inputs

  • a first parallel side
  • b second parallel side
  • height distance between the parallel sides

Returns

  • area (a + b) h / 2
  • midsegment (a + b) / 2

Applies when

  • a, b, height > 0

Example

m.ask("Find the area of a trapezoid with parallel sides 6 and 10 and height 4.")
→ area = 32, midsegment = 8

Polygons 7

Centroid of a polygonpolygon_centroid

The centroid (centre of mass of the uniform region) of a simple polygon given its vertices in order.

C_x = \frac{1}{6A}\sum_i (x_i + x_{i+1})(x_i y_{i+1} - x_{i+1} y_i)

Inputs

  • points vertices in order: x1 y1, x2 y2, ... vector

Returns

  • cx x of the centroid
  • cy y of the centroid

Applies when

  • at least 3 vertices, in order
  • simple polygon

Example

m.ask("Find the centroid of the polygon with vertices (0, 0), (4, 0), (4, 2), (0, 2).")
→ cx = 2, cy = 1
Interior angles of a polygon from its verticespolygon_interior_angles

The interior angle at every vertex of a simple polygon (reflex angles included), their sum and the number of reflex vertices.

\theta_i = 180^\circ - \operatorname{atan2}(\mathbf u\times\mathbf v, \mathbf u\cdot\mathbf v),\quad \sum\theta_i = (n-2)180^\circ

Inputs

  • points vertices in order: x1 y1, x2 y2, ... vector

Returns

  • angles interior angle at each vertex, degrees, in the order given
  • angle_sum (n - 2) 180
  • reflex_vertices number of angles above 180 degrees

Applies when

  • simple polygon
  • either orientation

Example

m.ask("Find the interior angles of the polygon with vertices (0, 0), (2, 0), (2, 2), (1, 1), (0, 2).")
→ angles = [90.0, 90.0, 45.0, 270.0, 45.0], angle_sum = 540, reflex_vertices = 1
Is a polygon convex?polygon_is_convex

Whether a simple polygon given by its vertices is convex.

\operatorname{sign}\big((p_{i+1}-p_i)\times(p_{i+2}-p_{i+1})\big) \text{ constant}

Inputs

  • points vertices in order: x1 y1, x2 y2, ... vector

Returns

  • convex yes / no

Applies when

  • simple polygon
  • a vertex on a straight edge (180 degrees) does not make it non-convex
  • exact on the written coordinates

Example

m.ask("Is the polygon with vertices (0, 0), (4, 0), (4, 4), (2, 1), (0, 4) convex?")
→ convex = no
Pick's theorem: lattice points of a polygonpick_lattice_points

Area, boundary lattice points and interior lattice points of a simple polygon with integer vertices.

A = I + \frac{B}{2} - 1

Inputs

  • points integer vertices in order: x1 y1, x2 y2, ... vector

Returns

  • area area
  • boundary_points lattice points on the boundary
  • interior_points lattice points strictly inside

Applies when

  • integer coordinates
  • simple polygon

Example

m.ask("How many lattice points are inside the polygon with vertices (0, 0), (4, 0), (4, 3), (0, 3)?")
→ area = 12, boundary_points = 14, interior_points = 6
Polygon angles and diagonalsregular_polygon_angles

Each interior and exterior angle of a regular n-gon, the interior angle sum of any n-gon and its number of diagonals.

\theta_{int} = \frac{(n-2)\,180^\circ}{n},\quad \theta_{ext} = \frac{360^\circ}{n},\quad D = \frac{n(n-3)}{2}

Inputs

  • n number of sides integer

Returns

  • interior_angle each interior angle of the regular polygon, degrees
  • exterior_angle each exterior angle, degrees
  • interior_sum sum of the interior angles, degrees
  • diagonals number of diagonals n(n-3)/2

Applies when

  • 3 <= n <= 1000 (whole number)
  • each single angle assumes a regular polygon

Example

m.ask("What is each interior angle of a regular hexagon?")
→ interior_angle = 120, exterior_angle = 60, interior_sum = 720, diagonals = 9
Polygon from vertices: area, perimeter, orientationpolygon_area

Area (shoelace formula), perimeter and orientation of a simple polygon given its vertices in order.

A = \tfrac12\left|\sum_{i} (x_i y_{i+1} - x_{i+1} y_i)\right|

Inputs

  • points vertices in order: x1 y1, x2 y2, ... vector

Returns

  • area enclosed area
  • perimeter sum of the edge lengths
  • orientation counterclockwise or clockwise

Applies when

  • at least 3 vertices, in order
  • the polygon is simple (its edges do not cross)

Example

m.ask("Find the area of the polygon with vertices (0, 0), (4, 0), (4, 3), (0, 3).")
→ area = 12, perimeter = 14, orientation = counterclockwise
Regular polygon: area, perimeter, apothem, circumradiusregular_polygon_measures

Area, perimeter, apothem (inradius) and circumradius of a regular n-gon from its side length.

a = \frac{s}{2\tan(\pi/n)},\quad R = \frac{s}{2\sin(\pi/n)},\quad A = \tfrac12 n s a

Inputs

  • n number of sides integer
  • side side length

Returns

  • area n s a / 2
  • perimeter n s
  • apothem s / (2 tan(pi/n))
  • circumradius s / (2 sin(pi/n))

Applies when

  • 3 <= n <= 200
  • side > 0

Example

m.ask("Find the area of a regular hexagon with side 4.")
→ area = 41.5692, perimeter = 24, apothem = 3.4641, circumradius = 4

Polyhedra 1

Platonic solids: counts, Euler characteristic, volume, surface, radiiplatonic_solid

Vertices, edges, faces, Euler characteristic, volume, surface area, circumradius and inradius of a regular polyhedron of edge a.

V - E + F = 2,\quad V_{\text{ico}} = \tfrac{5}{12}(3+\sqrt5)\,a^3

Inputs

  • solid which Platonic solid choice
  • edge edge length a

Returns

  • vertices V
  • edges E
  • faces F
  • euler_characteristic V - E + F
  • volume volume
  • surface_area surface area
  • circumradius radius of the circumscribed sphere
  • inradius radius of the inscribed sphere

Applies when

  • edge > 0

Example

m.ask("Find the volume and surface area of a regular icosahedron with edge 2.")
→ vertices = 12, edges = 30, faces = 20, euler_characteristic = 2, volume = 17.4536, surface_area = 34.641, circumradius = 1.90211, inradius = 1.51152

Solid coordinate geometry 8

Angle between two planesangle_between_planes

The acute (dihedral) angle between two planes given by their equations (only the normals matter).

\cos\theta = \frac{|\mathbf n_1\cdot\mathbf n_2|}{\|\mathbf n_1\|\|\mathbf n_2\|}

Inputs

  • a1 x-coefficient of plane 1
  • b1 y-coefficient of plane 1
  • c1 z-coefficient of plane 1
  • a2 x-coefficient of plane 2
  • b2 y-coefficient of plane 2
  • c2 z-coefficient of plane 2

Returns

  • angle angle between the planes, degrees, 0 to 90

Applies when

  • nonzero normals
  • the constants do not affect the angle

Example

m.ask("Find the angle between the planes z = 0 and x + z = 2.")
→ angle = 45
Distance between two lines in space (skew or parallel)skew_lines_distance

The shortest distance between the lines P1 + s d1 and P2 + t d2 in three dimensions.

d = \frac{|(P_2-P_1)\cdot(\mathbf d_1\times\mathbf d_2)|}{\|\mathbf d_1\times\mathbf d_2\|}

Inputs

  • p1 a point on line 1 vector
  • d1 direction of line 1 vector
  • p2 a point on line 2 vector
  • d2 direction of line 2 vector

Returns

  • distance shortest distance
  • parallel yes / no (exact test)

Applies when

  • nonzero directions

Example

m.ask("Find the distance between the lines through (0, 0, 0) with direction (1, 0, 0) and through (0, 1, 1) with direction (0, 1, 0).")
→ distance = 1, parallel = no
Distance from a point to a planepoint_plane_distance

The distance from a point to the plane a x + b y + c z + d = 0 and the foot of the perpendicular.

d = \frac{|a p_x + b p_y + c p_z + d|}{\sqrt{a^2+b^2+c^2}}

Inputs

  • px x of the point
  • py y of the point
  • pz z of the point
  • a coefficient of x
  • b coefficient of y
  • c coefficient of z
  • d constant term

Returns

  • distance |a px + b py + c pz + d| / sqrt(a^2 + b^2 + c^2)
  • fx x of the foot
  • fy y of the foot
  • fz z of the foot

Applies when

  • a, b, c not all 0

Example

m.ask("Find the distance from the point (1, 2, 3) to the plane 2x - y + 2z = 3.")
→ distance = 1, fx = 0.333333, fy = 2.33333, fz = 2.33333
Intersection of a line and a planeline_plane_intersection

The point where the line P0 + t v meets the plane a x + b y + c z + d = 0.

t = -\frac{\mathbf n\cdot P_0 + d}{\mathbf n\cdot\mathbf v},\quad X = P_0 + t\,\mathbf v

Inputs

  • x0 x of a point on the line
  • y0 y of the point
  • z0 z of the point
  • dx x of the direction
  • dy y of the direction
  • dz z of the direction
  • a coefficient of x
  • b coefficient of y
  • c coefficient of z
  • d constant term

Returns

  • x x of the intersection
  • y y
  • z z
  • t line parameter at the intersection

Applies when

  • direction not zero
  • a, b, c not all 0
  • line not parallel to the plane (exact test)

Example

m.ask("Where does the line through (1, 0, 0) with direction (1, 2, 3) meet the plane x + y + z = 7?")
→ x = 2, y = 2, z = 3, t = 1
Plane through three pointsplane_through_points

The equation a x + b y + c z + d = 0 of the plane through three points, with (a, b, c) a unit normal.

\mathbf n = (B-A)\times(C-A),\quad \mathbf n\cdot\mathbf x - \mathbf n\cdot A = 0

Inputs

  • points the three points: x y z for each vector

Returns

  • a x-component of the unit normal
  • b y-component
  • c z-component
  • d constant term

Applies when

  • exactly 3 points, not collinear
  • convention: (a, b, c) has length 1 and its first nonzero component is positive

Example

m.ask("Find the equation of the plane through (1, 0, 0), (0, 1, 0) and (0, 0, 1).")
→ a = 0.57735, b = 0.57735, c = 0.57735, d = -0.57735
Sphere through four points (circumsphere of a tetrahedron)sphere_four_points

Centre and radius of the sphere through four non-coplanar points.

|X - P_i|^2 = R^2 \;(i = 1..4) \Rightarrow 2(P_i - P_1)\cdot X = |P_i|^2 - |P_1|^2

Inputs

  • points the four points: x y z for each vector

Returns

  • cx x of the centre
  • cy y of the centre
  • cz z of the centre
  • radius radius

Applies when

  • exactly 4 points, not coplanar

Example

m.ask("Find the sphere through (1, 0, 0), (0, 1, 0), (0, 0, 1) and (0, 0, 0).")
→ cx = 0.5, cy = 0.5, cz = 0.5, radius = 0.866025
Tetrahedron from four vertices: volume and surface areatetrahedron_measures

Volume and total surface area of the tetrahedron with four given vertices.

V = \tfrac16\left|(B-A)\cdot\big((C-A)\times(D-A)\big)\right|

Inputs

  • points the four vertices: x y z for each vector

Returns

  • volume |det(B - A, C - A, D - A)| / 6
  • surface_area sum of the four face areas

Applies when

  • exactly 4 points
  • not coplanar

Example

m.ask("Find the volume of the tetrahedron with vertices (0, 0, 0), (1, 0, 0), (0, 1, 0) and (0, 0, 1).")
→ volume = 0.166667, surface_area = 2.36603
Triangle in space: area and perimeter from verticestriangle_area_3d

Area and perimeter of the triangle with vertices A, B, C in three-dimensional space.

K = \tfrac14\sqrt{(a+b+c)(-a+b+c)(a-b+c)(a+b-c)}

Inputs

  • points the vertices: xA yA zA, xB yB zB, xC yC zC vector

Returns

  • area area
  • perimeter perimeter

Applies when

  • exactly 3 points, not collinear

Example

m.ask("Find the area of the triangle with vertices (1, 0, 0), (0, 2, 0) and (0, 0, 3).")
→ area = 3.5, perimeter = 9.0039

Solid geometry 2

Solid angle of a conesolid_angle_cone

The solid angle (steradians) subtended at the apex by a right circular cone of given half-angle.

\Omega = 2\pi(1-\cos\alpha) = 4\pi\sin^2\tfrac{\alpha}{2}

Inputs

  • half_angle half-angle of the cone (axis to side), degrees

Returns

  • solid_angle 2 pi (1 - cos a) steradians
  • fraction_of_sphere solid angle / (4 pi)

Applies when

  • 0 < half-angle <= 180 degrees
  • an apex (full opening) angle in the question is halved

Example

m.ask("What is the solid angle of a cone with half-angle 60 degrees?")
→ solid_angle = 3.14159, fraction_of_sphere = 0.25
Solid angle subtended by a trianglesolid_angle_triangle

The solid angle (steradians) that the triangle with vertices A, B, C subtends at the origin.

\tan\frac{\Omega}{2} = \frac{|\mathbf a\cdot(\mathbf b\times\mathbf c)|}{abc + (\mathbf a\cdot\mathbf b)c + (\mathbf a\cdot\mathbf c)b + (\mathbf b\cdot\mathbf c)a}

Inputs

  • points the vertices as seen from the origin: x y z for each vector

Returns

  • solid_angle solid angle, steradians

Applies when

  • no vertex at the origin
  • the triangle's plane does not pass through the origin
  • observer at the origin

Example

m.ask("What solid angle does the triangle with vertices (1, 0, 0), (0, 1, 0), (0, 0, 1) subtend at the origin?")
→ solid_angle = 1.5708

Solids 10

Cone: volume, slant height and surface areacone_measures

Volume, slant height, lateral area and total surface area of a right circular cone.

V = \tfrac13 \pi r^2 h,\quad l = \sqrt{r^2+h^2},\quad A_L = \pi r l

Inputs

  • radius radius of the base
  • height perpendicular height

Returns

  • volume pi r^2 h / 3
  • slant_height sqrt(r^2 + h^2)
  • lateral_area pi r l
  • total_area pi r (r + l)

Applies when

  • radius, height > 0

Example

m.ask("Find the volume of a cone with radius 3 and height 4.")
→ volume = 37.6991, slant_height = 5, lateral_area = 47.1239, total_area = 75.3982
Cuboid (rectangular box): volume, surface area, space diagonalcuboid_measures

Volume, total surface area and space diagonal of a rectangular box (a cube when all edges are equal).

V = lwh,\quad S = 2(lw+lh+wh),\quad d = \sqrt{l^2+w^2+h^2}

Inputs

  • length length
  • width width
  • height height

Returns

  • volume l w h
  • surface_area 2(lw + lh + wh)
  • space_diagonal sqrt(l^2 + w^2 + h^2)

Applies when

  • length, width, height > 0

Example

m.ask("Find the volume and surface area of a box 3 by 4 by 12.")
→ volume = 144, surface_area = 192, space_diagonal = 13
Cylinder: volume and surface areacylinder_measures

Volume, lateral (curved) area and total surface area of a right circular cylinder.

V = \pi r^2 h,\quad A = 2\pi r h + 2\pi r^2

Inputs

  • radius radius of the base
  • height height

Returns

  • volume pi r^2 h
  • lateral_area 2 pi r h
  • total_area 2 pi r (r + h)

Applies when

  • radius, height > 0

Example

m.ask("Find the volume of a cylinder with radius 3 and height 5.")
→ volume = 141.372, lateral_area = 94.2478, total_area = 150.796
Frustum of a cone: volume and surface areafrustum_measures

Volume, slant height, lateral and total surface area of a frustum of a right circular cone.

V = \tfrac13\pi h (R^2 + Rr + r^2),\quad A_L = \pi (R+r)\sqrt{h^2+(R-r)^2}

Inputs

  • r1 radius of one base
  • r2 radius of the other base
  • height perpendicular height

Returns

  • volume pi h (R^2 + R r + r^2)/3
  • slant_height sqrt(h^2 + (R - r)^2)
  • lateral_area pi (R + r) s
  • total_area lateral + pi (R^2 + r^2)

Applies when

  • r1, r2, height > 0

Example

m.ask("Find the volume of a frustum with radii 3 and 6 and height 4.")
→ volume = 263.894, slant_height = 5, lateral_area = 141.372, total_area = 282.743
Right prism on a regular polygon base: volume and surface arearegular_prism

Volume, base area, lateral and total surface area of a right prism whose base is a regular n-gon.

B = \frac{n s^2}{4\tan(\pi/n)},\quad V = Bh,\quad A = nsh + 2B

Inputs

  • n number of sides of the base integer
  • side side length of the base
  • height height (length) of the prism

Returns

  • volume base area * height
  • lateral_area n s h
  • total_area lateral + 2 * base
  • base_area n s^2 / (4 tan(pi/n))

Applies when

  • 3 <= n <= 200
  • side, height > 0
  • a triangular prism is read only when 'regular' or 'equilateral' is said

Example

m.ask("Find the volume of a regular hexagonal prism with side 2 and height 10.")
→ volume = 103.923, lateral_area = 120, total_area = 140.785, base_area = 10.3923
Right rectangular (or square) pyramid: volume and surface areapyramid_measures

Volume, lateral area and total surface area of a right pyramid on a rectangular base (apex above the base centre).

V = \tfrac13 lwh,\quad A_L = l\sqrt{h^2+(w/2)^2} + w\sqrt{h^2+(l/2)^2}

Inputs

  • length base length
  • width base width
  • height perpendicular height

Returns

  • volume l w h / 3
  • lateral_area area of the four triangular faces
  • total_area lateral + base

Applies when

  • length, width, height > 0
  • the apex is directly above the centre of the base

Example

m.ask("Find the volume of a square pyramid with base side 6 and height 4.")
→ volume = 48, lateral_area = 60, total_area = 96
Sphere: volume and surface areasphere_measures

Volume and surface area of a sphere from its radius (or diameter).

V = \tfrac43\pi r^3,\quad S = 4\pi r^2

Inputs

  • radius radius

Returns

  • volume 4/3 pi r^3
  • surface_area 4 pi r^2

Applies when

  • radius > 0

Example

m.ask("Find the volume of a sphere with radius 3.")
→ volume = 113.097, surface_area = 113.097
Spherical cap: volume, curved area, base radiusspherical_cap

Volume, curved surface area and base radius of a cap of height h cut from a sphere of radius R.

V = \tfrac13 \pi h^2(3R - h),\quad A = 2\pi R h,\quad a = \sqrt{h(2R-h)}

Inputs

  • radius radius R of the sphere
  • height height h of the cap

Returns

  • volume pi h^2 (3R - h)/3
  • cap_area 2 pi R h
  • base_radius sqrt(h (2R - h))

Applies when

  • R > 0
  • 0 < h <= 2R

Example

m.ask("Find the volume of a spherical cap of height 2 cut from a sphere of radius 5.")
→ volume = 54.4543, cap_area = 62.8319, base_radius = 4
Spheroid (ellipsoid of revolution): surface area and volumespheroid_measures

Surface area and volume of an oblate or prolate spheroid with equatorial radius a and polar radius c.

S_{\text{obl}} = 2\pi a^2\left(1 + \frac{1-e^2}{e}\operatorname{artanh} e\right),\quad S_{\text{pro}} = 2\pi a^2\left(1 + \frac{c}{ae}\arcsin e\right)

Inputs

  • a equatorial radius (semi-axis in the equator)
  • c polar radius (semi-axis along the axis)

Returns

  • surface_area surface area
  • volume 4/3 pi a^2 c
  • shape oblate / prolate / sphere

Applies when

  • a, c > 0

Example

m.ask("Find the surface area of a prolate spheroid with a = 1 and c = 2.")
→ surface_area = 21.4784, volume = 8.37758, shape = prolate
Torus: volume and surface areatorus_measures

Volume and surface area of a ring torus with major radius R (centre to tube centre) and tube radius r.

V = 2\pi^2 R r^2,\quad A = 4\pi^2 R r

Inputs

  • major major radius R
  • minor tube (minor) radius r

Returns

  • volume 2 pi^2 R r^2
  • surface_area 4 pi^2 R r

Applies when

  • 0 < r < R

Example

m.ask("Find the volume of a torus with major radius 5 and minor radius 2.")
→ volume = 394.784, surface_area = 394.784

Spherical geometry 3

Area and spherical excess of a spherical trianglespherical_triangle_area

The spherical excess and area of the triangle with three vertices given by latitude and longitude on a sphere of radius R.

\tan\frac E4 = \sqrt{\tan\frac s2\tan\frac{s-a}2\tan\frac{s-b}2\tan\frac{s-c}2},\quad A = E R^2

Inputs

  • points the vertices (lat lon): lat1 lon1, lat2 lon2, lat3 lon3, degrees vector
  • radius sphere radius (default 1; 'Earth' means 6371 km) optional

Returns

  • excess spherical excess A + B + C - 180, degrees
  • area area E R^2 (E in radians)

Applies when

  • the smaller triangle (each side less than 180 degrees)
  • vertices not on one great circle
  • radius defaults to 1

Example

m.ask("Find the area of the spherical triangle with vertices (0, 0), (0, 90) and (90, 0) on a sphere of radius 1.")
→ excess = 90, area = 1.5708
Great-circle distance between two points on a spheregreat_circle_distance

The central angle and great-circle distance between two points given by latitude and longitude (on the Earth unless a radius is given).

h = \sin^2\tfrac{\Delta\varphi}{2} + \cos\varphi_1\cos\varphi_2\sin^2\tfrac{\Delta\lambda}{2},\quad d = 2R\,\operatorname{atan2}(\sqrt h, \sqrt{1-h})

Inputs

  • lat1 latitude of point 1, degrees
  • lon1 longitude of point 1, degrees
  • lat2 latitude of point 2
  • lon2 longitude of point 2
  • radius sphere radius (default 6371, the mean Earth radius in km) optional

Returns

  • central_angle central angle, degrees
  • distance great-circle distance (radius units)

Applies when

  • points written (latitude, longitude) in signed decimal degrees
  • radius defaults to 6371 km (mean Earth radius; the Earth is treated as a sphere)

Example

m.ask("What is the central angle between (0, 0) and (0, 90) on a sphere of radius 1?")
→ central_angle = 90, distance = 1.5708
Initial bearing (forward azimuth) along a great circleinitial_bearing

The initial compass bearing from point 1 to point 2 along the great circle, degrees clockwise from north.

\theta = \operatorname{atan2}\big(\sin\Delta\lambda\cos\varphi_2,\ \cos\varphi_1\sin\varphi_2 - \sin\varphi_1\cos\varphi_2\cos\Delta\lambda\big)

Inputs

  • lat1 latitude of the start, degrees
  • lon1 longitude of the start
  • lat2 latitude of the destination
  • lon2 longitude of the destination

Returns

  • bearing initial bearing, degrees in [0, 360), clockwise from north

Applies when

  • (latitude, longitude) in signed decimal degrees
  • the start is not a pole; the points are neither equal nor antipodal

Example

m.ask("Find the initial bearing from (0, 0) to (0, 90).")
→ bearing = 90

Surfaces 2

Curvature of a torus at a pointtorus_curvature

Gaussian, mean and principal curvatures of a ring torus at tube angle v (v = 0 on the outer equator, 180 on the inner).

K = \frac{\cos v}{r(R + r\cos v)},\quad H = \frac{R + 2r\cos v}{2r(R + r\cos v)}

Inputs

  • major major radius R
  • minor tube radius r
  • v tube angle v, degrees (0 = outer equator)

Returns

  • gaussian K = cos v / (r (R + r cos v))
  • mean H = (R + 2 r cos v) / (2 r (R + r cos v))
  • k1 principal curvature around the tube, 1/r
  • k2 principal curvature along the ring, cos v / (R + r cos v)

Applies when

  • 0 < r < R
  • signs: curvatures positive where the surface bends away from the outward normal (a sphere is positive)

Example

m.ask("Find the Gaussian curvature of a torus with major radius 3 and minor radius 1 at tube angle 0 degrees.")
→ gaussian = 0.25, mean = 0.625, k1 = 1, k2 = 0.25
Gaussian and mean curvature of a quadratic surface z = f(x, y)surface_curvature

Gaussian curvature K and mean curvature H of z = A x^2 + B xy + C y^2 + D x + E y + F at the point above (x0, y0).

K = \frac{f_{xx}f_{yy}-f_{xy}^2}{(1+f_x^2+f_y^2)^2},\quad H = \frac{(1+f_y^2)f_{xx} - 2f_xf_yf_{xy} + (1+f_x^2)f_{yy}}{2(1+f_x^2+f_y^2)^{3/2}}

Inputs

  • A coefficient of x^2
  • B coefficient of xy
  • C coefficient of y^2
  • D coefficient of x
  • E coefficient of y
  • x0 x of the point
  • y0 y of the point
  • F constant term (does not affect curvature) optional

Returns

  • gaussian Gaussian curvature K
  • mean mean curvature H (upward normal: positive where the surface opens upward)

Applies when

  • the unit normal points upward, (-f_x, -f_y, 1)/|...|

Example

m.ask("Find the Gaussian and mean curvature of z = x^2 + y^2 at (0, 0).")
→ gaussian = 4, mean = 2

Transformations 4

Dilation (enlargement) of a pointdilate_point

The image of a point under a dilation with scale factor k about a centre (the origin unless given).

P' = C + k\,(P - C)

Inputs

  • px x of the point
  • py y of the point
  • k scale factor (negative: through the centre)
  • cx x of the centre (default 0) optional
  • cy y of the centre (default 0) optional

Returns

  • x x of the image
  • y y of the image

Applies when

  • k != 0
  • centre defaults to the origin

Example

m.ask("Dilate the point (2, 3) by a scale factor of 3 about the origin.")
→ x = 6, y = 9
Reflection of a point in a linereflect_point_line

The mirror image of a point in the line a x + b y + c = 0 (including the axes and y = x).

P' = P - 2\,\frac{a p_x + b p_y + c}{a^2+b^2}\,(a, b)

Inputs

  • px x of the point
  • py y of the point
  • a coefficient of x of the line
  • b coefficient of y of the line
  • c constant of the line

Returns

  • x x of the image
  • y y of the image

Applies when

  • a and b not both 0

Example

m.ask("Reflect the point (3, 4) in the line y = x.")
→ x = 4, y = 3
Rotation of a pointrotate_point

The image of a point rotated by an angle about a centre (the origin unless given); counterclockwise is positive.

\begin{pmatrix}x'\\y'\end{pmatrix} = \begin{pmatrix}\cos\theta & -\sin\theta\\ \sin\theta & \cos\theta\end{pmatrix}\begin{pmatrix}x-c_x\\y-c_y\end{pmatrix} + \begin{pmatrix}c_x\\c_y\end{pmatrix}

Inputs

  • px x of the point
  • py y of the point
  • angle rotation angle in degrees, counterclockwise positive
  • cx x of the centre (default 0) optional
  • cy y of the centre (default 0) optional

Returns

  • x x of the image
  • y y of the image

Applies when

  • angle in degrees, counterclockwise positive ('clockwise' in a question makes it negative)
  • centre defaults to the origin

Example

m.ask("Rotate the point (3, 4) by 90 degrees about the origin.")
→ x = -4, y = 3
Rotation of a point in space about an axisrotate_point_3d

The image of a point rotated by an angle about an axis through the origin (right-hand rule).

\mathbf v' = \mathbf v\cos\theta + (\mathbf k\times\mathbf v)\sin\theta + \mathbf k(\mathbf k\cdot\mathbf v)(1-\cos\theta)

Inputs

  • point the point x y z vector
  • axis axis direction (through the origin) vector
  • angle angle in degrees (right-hand rule)

Returns

  • x x of the image
  • y y of the image
  • z z of the image

Applies when

  • axis not zero; it passes through the origin
  • positive angle: counterclockwise looking from the axis tip toward the origin

Example

m.ask("Rotate the point (1, 0, 0) by 90 degrees about the z-axis.")
→ x = 0, y = 1, z = 0
Questions

Frequently asked

What does geometry-ai999x do?

Geometry answers questions in geometry: plane and solid geometry, coordinate geometry, conic sections, polygons and polyhedra, computational geometry (convex hulls, Voronoi, triangulation) and curves and surfaces. Each answer gives the value with its unit, the steps and the formula in LaTeX.

How do I install geometry-ai999x?

With pip: pip install geometry-ai999x. The same files are on Hugging Face (hf download AI999X/geometry-ai999x --local-dir geometry-ai999x) and GitHub.

Does it run offline?

Yes. It is a Python package that runs on an ordinary CPU without a network connection (Python >=3.10); no GPU and no API key are needed.

How many capabilities does geometry-ai999x have?

76 capabilities in 13 topics, including Computational geometry, Coordinate geometry, Plane figures, Solids, Solid coordinate geometry.

Which field and tasks does it cover?

Field: Mathematics & Statistics. Tasks: Question Answering, Token Classification, Text Classification, Sentence Similarity, Feature Extraction.

What does an answer look like?

Asked "Find the circumcenter and circumradius of the triangle with vertices (0, 0), (4, 0) and (0, 3).", it answers: cx = 2, cy = 1.5, radius = 2.5.

What happens when a question cannot be answered?

It says so and names what is missing or out of range, instead of guessing a number.

More from AI999X

Explore every model.