RiptideRiptide
Download Riptide SDKInstall Riptorch
Menu
Raya docs · Geometry, physics and speed

Conics and quadrics

Conics and quadrics exactly over the rationals: cone sections, Dandelin spheres, foci and directrices.

import 'package:riptide_conics/riptide_conics.ray';
19 classes157 functions and methods141 of 263 documented104 runnable examples

Overview

Conics and quadrics two ways, exact over \mathbb{Q} (pure Raya).

  • cone_slice.ray: the double cone x^{2} + y^{2} = \mu^{2}z^{2} cut by the plane tilted by a Cayley half-tangent \tau at distance d from the vertex. The kind (circle, ellipse, parabola, hyperbola; point, line, two lines) from two spreads, s_{\beta} = c^{2} against s_{\alpha} = \frac{\mu^{2}}{1 + \mu^{2}}, and from the section's matrix (\det = -\mu^{2}d^{2}); e^{2} = s^{2}(1 + \mu^{2}); every rational generator g(t) = (\mu(1 - t^{2}), 2\mu t, 1 + t^{2}) gives a rational point of the section.
  • dandelin.ray: Dandelin's spheres on Pythagorean cones (1 + \mu^{2} a square): centres, foci, touch circles, focal distances d = |P_{z} - h| \cdot \kappa, d_{1} \pm d_{2} = L, the triple quad formula, focus–directrix ratio e^{2}.
  • quadrics.ray: the six quadric surfaces, rational points by projection from a point, exact rulings, plane sections.
  • polarity.ray: Apollonius' polar (M \cdot p), the quadrangle construction, harmonic conjugates, tangent points (rational only when a discriminant is a square), polar planes of quadrics and the contact circle.
  • mirror.ray: the parabolic mirror's reflection r = d - \frac{2(d \cdot n)}{n \cdot n} n through the focus.
  • classic.ray: the classic side (angles, sin, cos, cosh, sinh, square roots in doubles); the only file with them.

Sources: Apollonius, Conics; G. P. Dandelin (1822); N J Wildberger's lectures (Differential Geometry 9 and 5; WildTrig "Conics via projective geometry"; Universal Hyperbolic Geometry 1, 2, 13).

Also exported here

Functions and constants

Functions

coshfunction
double cosh(double x)

Cosh and sinh from exp.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  print('cosh(0) = ${cosh(0)}');
  print('cosh(1) = ${cosh(1).toStringAsFixed(12)}');
  final x = 0.7;
  print('cosh² − sinh² at 0.7 = ${(cosh(x) * cosh(x) - sinh(x) * sinh(x)).toStringAsFixed(12)}');
        {'label': 'cosh', 'points': [for (var i = 0; i <= 80; i++) [-2 + i / 20, cosh(-2 + i / 20)]]},
        {'label': 'sinh', 'points': [for (var i = 0; i <= 80; i++) [-2 + i / 20, sinh(-2 + i / 20)]]},
      ]})}');
}
Output
cosh(0) = 1.0
cosh(1) = 1.543080634815
cosh² − sinh² at 0.7 = 1.000000000000
sinhfunction
double sinh(double x)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  print('sinh(0) = ${sinh(0)}');
  print('sinh(1) = ${sinh(1).toStringAsFixed(12)}');
  print('odd: sinh(−2) = ${sinh(-2).toStringAsFixed(9)}, −sinh(2) = ${(-sinh(2)).toStringAsFixed(9)}');
        {'label': 'branch', 'points': [for (var i = 0; i <= 60; i++) [cosh(-1.5 + i / 20), sinh(-1.5 + i / 20)]]},
      ]})}');
}
Output
sinh(0) = 0.0
sinh(1) = 1.175201193644
odd: sinh(−2) = -3.626860408, −sinh(2) = -3.626860408
distancefunction
double distance((double, double, double) a, (double, double, double) b)

The Euclidean distance \sqrt{\Delta x^{2} + \Delta y^{2} + \Delta z^{2}}.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  print('distance((0,0,0), (1,2,2)) = ${distance((0, 0, 0), (1, 2, 2))}');
  final a = (1.0, -1.0, 0.5), b = (4.0, 3.0, 0.5);
  print('distance(a, b) = ${distance(a, b)}');
  // The exact side keeps the quadrance instead: 25 = 5².
  print('quadrance of the same points = ${quadrance(QV3(q(1), q(-1), q(1, 2)), QV3(q(4), q(3), q(1, 2)))}');
        'points': [[a.$1, a.$2, 'a'], [b.$1, b.$2, 'b']], 'segments': [[a.$1, a.$2, b.$1, b.$2]]})}');
}
Output
distance((0,0,0), (1,2,2)) = 3.0
distance(a, b) = 5.0
quadrance of the same points = 25
(double, double, double) classicQuadricPoint(QuadricKind kind, double a, double b, double c, double theta, double phi)

A quadric's classic parametrisation by angles (\theta round the axis, \varphi along it): (a \cos \varphi \cos \theta, b \cos \varphi \sin \theta, c \sin \varphi) for the ellipsoid, cosh and sinh for the hyperboloids, polar coordinates for the paraboloids and the cone.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';
import 'raya:math' as math;

void main() {
  final p = classicQuadricPoint(QuadricKind.ellipsoid, 3, 2, 1, 0, math.pi / 2);
  print('ellipsoid (3, 2, 1) at φ = π/2: (${p.$1.toStringAsFixed(3)}, ${p.$2.toStringAsFixed(3)}, ${p.$3})');
  // Meridians (θ = 0) of three surfaces, drawn in the x–z plane.
  List<List<double>> meridian(QuadricKind k, double from, double to) => [
        for (var i = 0; i <= 60; i++)
          (() { final (x, _, z) = classicQuadricPoint(k, 2, 2, 1, 0, from + (to - from) * i / 60); return [x, z]; })(),
      ];
        {'label': 'ellipsoid', 'points': meridian(QuadricKind.ellipsoid, -math.pi / 2, math.pi / 2)},
        {'label': 'hyperboloid', 'points': meridian(QuadricKind.hyperboloidOne, -1.4, 1.4)},
        {'label': 'paraboloid', 'points': meridian(QuadricKind.ellipticParaboloid, 0, 1.6)},
      ]})}');
}
Output
ellipsoid (3, 2, 1) at φ = π/2: (0.000, 0.000, 1.0)
((double, double, double), (double, double, double)) classicRuling(double a, double b, double c, double phi, int family)

The classic ruling of the hyperboloid of one sheet through the waist point at angle \varphi: (a \cos \varphi, b \sin \varphi, 0)

  • \lambda(-a \sin \varphi, b \cos \varphi, \pm c).
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';
import 'raya:math' as math;

void main() {
  final (p, d) = classicRuling(1, 1, 1, 0, 1);
  print('waist point at φ = 0: $p, direction: (${d.$1}, ${d.$2}, ${d.$3})');
  // Every point of the ruling stays on x² + y² − z² = 1 (residual zero up to rounding).
  var worst = 0.0;
  for (var l = -3.0; l <= 3.0; l += 0.5) {
    final r = hyperboloidResidual(1, 1, 1, (p.$1 + l * d.$1, p.$2 + l * d.$2, p.$3 + l * d.$3));
    worst = math.max(worst, r.abs());
  }
  print('largest residual along the line: below 1e-12: ${worst < 1e-12}');
  // Seen from above, the rulings are tangent lines of the waist circle.
  final segs = <List<double>>[];
  for (var k = 0; k < 16; k++) {
    final (q0, u) = classicRuling(1, 1, 1, 2 * math.pi * k / 16, 1);
    segs.add([q0.$1 - 1.5 * u.$1, q0.$2 - 1.5 * u.$2, q0.$1 + 1.5 * u.$1, q0.$2 + 1.5 * u.$2]);
  }
}
Output
waist point at φ = 0: (1.0, 0.0, 0.0), direction: (-0.0, 1.0, 1.0)
largest residual along the line: below 1e-12: true
double hyperboloidResidual(double a, double b, double c, (double, double, double) p)

The value of \frac{x^{2}}{a^{2}} + \frac{y^{2}}{b^{2}} - \frac{z^{2}}{c^{2}} - 1 in doubles (the one-sheet hyperboloid's residual).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  print('on the waist (2, 0, 0): ${hyperboloidResidual(2, 1, 1, (2, 0, 0))}');
  print('at the centre: ${hyperboloidResidual(2, 1, 1, (0, 0, 0))}');
  print('outside (4, 0, 1): ${hyperboloidResidual(2, 1, 1, (4, 0, 1))}');
        {'label': 'r(x, 0, 0)', 'points': [for (var i = 0; i <= 40; i++) [i / 10, hyperboloidResidual(2, 1, 1, (i / 10, 0, 0))]]},
      ]})}');
}
Output
on the waist (2, 0, 0): 0.0
at the centre: -1.0
outside (4, 0, 1): 2.0
double classicMirrorMiss(double f, double x)

The classic mirror: the tangent's angle \theta = \operatorname{atan}(\frac{x}{2f}), the reflected ray (-\sin 2\theta, \cos 2\theta) in the plane through the axis. Returns how far the reflected line misses the focus (a cross product; zero up to rounding).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  // How far the reflected ray misses the focus of y = x²/(4f), computed with angles.
  var worst = 0.0;
  for (var x = -3.0; x <= 3.0; x += 0.25) {
    final m = classicMirrorMiss(1, x);
    if (m > worst) worst = m;
  }
  print('f = 1, x in [−3, 3]: worst miss below 1e-12: ${worst < 1e-12}');
  print('exact side for comparison: ParabolicMirror(1).throughFocus = ${ParabolicMirror(q(1)).throughFocus(ParabolicMirror(q(1)).hit(q(3), q(0)))}');
}
Output
f = 1, x in [−3, 3]: worst miss below 1e-12: true
exact side for comparison: ParabolicMirror(1).throughFocus = true
List<(double, double)> classicTangentPoints(List<double> coeffs, (double, double) pole)

The classic tangent points from a pole to the conic A x^{2} + B xy + C y^{2} + D x + E y + F = 0: the polar's meets with the conic by the quadratic formula (a square root). Empty inside.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  // x² + y² − 1 = 0 and the pole (2, 0).
  final pts = classicTangentPoints([1, 0, 1, 0, 0, -1], (2, 0));
  for (final (x, y) in pts) {
    print('touches at (${x.toStringAsFixed(4)}, ${y.toStringAsFixed(4)})');
  }
  print('from inside (0.5, 0): ${classicTangentPoints([1, 0, 1, 0, 0, -1], (0.5, 0))}');
        'points': [[2, 0, 'pole'], for (final (x, y) in pts) [x, y]],
        'segments': [for (final (x, y) in pts) [2, 0, x, y]]})}');
}
Output
touches at (0.5000, 0.8660)
touches at (0.5000, -0.8660)
from inside (0.5, 0): []
archimedesfunction
Rational archimedes(Rational a, Rational b, Rational c)

Archimedes' function A(a, b, c) = (a + b + c)^{2} - 2(a^{2} + b^{2} + c^{2}): zero exactly when \sqrt{a} \pm \sqrt{b} \pm \sqrt{c} = 0 for some choice of signs (Wildberger's triple quad formula; Heron's formula is its -16 \times \mathrm{area}^{2} form).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  // Zero exactly when √a ± √b ± √c = 0: here 1 + 2 = 3.
  print('A(1, 4, 9) = ${exact(archimedes(q(1), q(4), q(9)))}');
  print('A(1, 1, 1) = ${exact(archimedes(q(1), q(1), q(1)))}');
  // A right triangle with sides 3, 4, 5: quadrances 9, 16, 25. −A/16 is the squared area: 36.
  final a = archimedes(q(9), q(16), q(25));
  print('A(9, 16, 25) = ${exact(a)}, area² = ${exact(a / q(16))}');
}
Output
A(1, 4, 9) = 0
A(1, 1, 1) = 3
A(9, 16, 25) = 576, area² = 36
qfunction
Rational q(int n, [int d = 1])

The rational \frac{n}{d}.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  print('q(3, 4) = ${q(3, 4)}');
  print('q(6, 8) reduces: ${q(6, 8)}');
  print('q(5) = ${q(5)}');
  print('q(1, 3) + q(1, 6) = ${q(1, 3) + q(1, 6)}');
}
Output
q(3, 4) = 3/4
q(6, 8) reduces: 3/4
q(5) = 5
q(1, 3) + q(1, 6) = 1/2
exactfunction
String exact(Rational r)

"−51/4" with a true minus sign.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  print('toString: ${q(-51, 4)}');
  print('exact:    ${exact(q(-51, 4))}');
  print('exact(1/3 − 1/2) = ${exact(q(1, 3) - q(1, 2))}');
}
Output
toString: -51/4
exact:    −51/4
exact(1/3 − 1/2) = −1/6
bitsOffunction
int bitsOf(Rational r)

The cost of exactness: the bits of numerator and denominator together.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  print('bitsOf(3/4) = ${bitsOf(q(3, 4))}');
  // Repeated squaring doubles the bits each time.
  var r = q(2, 3);
  final rows = <List<num>>[];
  for (var k = 0; k < 6; k++) {
    print('(2/3)^(2^$k): ${bitsOf(r)} bits');
    rows.add([k, bitsOf(r)]);
    r = r * r;
  }
}
Output
bitsOf(3/4) = 5
(2/3)^(2^0): 4 bits
(2/3)^(2^1): 7 bits
(2/3)^(2^2): 12 bits
(2/3)^(2^3): 22 bits
(2/3)^(2^4): 43 bits
(2/3)^(2^5): 84 bits
shortExactfunction
String shortExact(Rational r, {int most = 18})

A fraction for a label: the fraction itself when short, else its value and its size in bits.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  print(shortExact(q(3, 4)));
  var r = q(2, 3);
  for (var k = 0; k < 4; k++) {
    r = r * r + q(1, 7);
  }
  print(shortExact(r));
  print(shortExact(r, most: 400).length > 18);
}
Output
3/4
≈ 0.28785570 (95-bit fraction)
true
integerRootfunction
BigInt integerRoot(BigInt n)

The integer square root of n \ge 0 by Newton's method on integers (floor of the root).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  print('⌊√99⌋ = ${integerRoot(BigInt.from(99))}');
  print('⌊√100⌋ = ${integerRoot(BigInt.from(100))}');
  final big = BigInt.from(10).pow(40) + BigInt.one;
  print('⌊√(10^40 + 1)⌋ = ${integerRoot(big)}');
        {'label': 'floor root', 'points': [for (var n = 0; n <= 60; n++) [n, integerRoot(BigInt.from(n)).toInt()]]},
      ]})}');
}
Output
⌊√99⌋ = 9
⌊√100⌋ = 10
⌊√(10^40 + 1)⌋ = 100000000000000000000
rationalRootfunction
Rational? rationalRoot(Rational r)

The rational square root of r when r is the square of a rational, else null. Integer arithmetic only: a square in Q is a square numerator over a square denominator in lowest terms.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  print('√(9/16) = ${rationalRoot(q(9, 16))}');
  print('√(169/25) = ${rationalRoot(q(169, 25))}');
  print('√2 = ${rationalRoot(q(2))}');
  print('√(−4) = ${rationalRoot(q(-4))}');
}
Output
√(9/16) = 3/4
√(169/25) = 13/5
√2 = null
√(−4) = null
quadrancefunction
Rational quadrance(QV3 a, QV3 b)

The quadrance between two points.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final a = QV3.ints(1, 2, 3), b = QV3.ints(4, 6, 3);
  print('Q(a, b) = ${quadrance(a, b)}');
  final c = QV3(q(1, 2), q(0), q(1, 3));
  print('Q(a, c) = ${exact(quadrance(a, c))}');
}
Output
Q(a, b) = 25
Q(a, c) = 409/36
dpfunction
(double, double) dp(QP2 p)

Points of the plane as doubles (drawing).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final p = (q(1, 2), q(-3, 4));
  final (x, y) = dp(p);
  print('exact (${exact(p.$1)}, ${exact(p.$2)}) -> doubles ($x, $y)');
  print('${dp((q(1, 3), q(2, 3)))}');
}
Output
exact (1/2, −3/4) -> doubles (0.5, -0.75)
(0.3333333333333333, 0.6666666666666666)
linearfunction
String linear(List<(Rational, String)> terms)

"−10/9 x − 1/2 y − 1": a linear form with its signs written once and zero terms left out.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  print(linear([(q(-10, 9), 'x'), (q(-1, 2), 'y'), (q(-1), '')]));
  print(linear([(q(1), 'x'), (q(0), 'y'), (q(3, 2), '')]));
  print(linear([(q(0), 'x'), (q(0), '')]));
}
Output
−10/9 x − 1/2 y − 1
x + 3/2
0
cayleyfunction
(Rational, Rational) cayley(Rational t)

A turn by a Cayley half-tangent t: \cos = \frac{1 - t^{2}}{1 + t^{2}}, \sin = \frac{2t}{1 + t^{2}}, both rational (no angle).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final pts = <List<Object>>[];
  for (final t in [q(0), q(1, 3), q(1, 2), q(1), q(2), q(-1, 2)]) {
    final (c, s) = cayley(t);
    print('t = ${exact(t).padRight(4)} (c, s) = (${exact(c)}, ${exact(s)})  c² + s² = ${c * c + s * s}');
    pts.add([c.toDouble(), s.toDouble(), exact(t)]);
  }
}
Output
t = 0    (c, s) = (1, 0)  c² + s² = 1
t = 1/3  (c, s) = (4/5, 3/5)  c² + s² = 1
t = 1/2  (c, s) = (3/5, 4/5)  c² + s² = 1
t = 1    (c, s) = (0, 1)  c² + s² = 1
t = 2    (c, s) = (−3/5, 4/5)  c² + s² = 1
t = −1/2 (c, s) = (3/5, −4/5)  c² + s² = 1
crossRatiofunction
Rational crossRatio(Rational a, Rational c, Rational b, Rational d)

The cross ratio (a, c; b, d) = ((b - a)(d - c)) / ((d - a)(b - c)) of four points on a line, given by their coordinates along it. It is -1 exactly when a and c are harmonic conjugates with respect to b and d (AB/AD = −CB/CD, UHG 2 @20:09).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  // Points on a line by coordinate: a = 0, c = 3/2, b = 1, d = 3.
  print('(0, 3/2; 1, 3) = ${exact(crossRatio(q(0), q(3, 2), q(1), q(3)))}');
  print('(0, 2; 1, 3) = ${exact(crossRatio(q(0), q(2), q(1), q(3)))}');
        'points': [[0, 0, 'a'], [1, 0, 'b'], [1.5, 0, 'c'], [3, 0, 'd']]})}');
}
Output
(0, 3/2; 1, 3) = −1
(0, 2; 1, 3) = −1/3
Rational harmonicConjugate(Rational a, Rational b, Rational d)

The harmonic conjugate of a with respect to b and d: the c with (a, c; b, d) = -1.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final c = harmonicConjugate(q(0), q(1), q(3));
  print('conjugate of 0 w.r.t. 1 and 3: ${exact(c)}');
  print('check: cross ratio = ${exact(crossRatio(q(0), c, q(1), q(3)))}');
  print('midpoint case: conjugate of 2 w.r.t. 1 and 3 = ${exact(harmonicConjugate(q(4), q(1), q(3)))}');
}
Output
conjugate of 0 w.r.t. 1 and 3: 3/2
check: cross ratio = −1
midpoint case: conjugate of 2 w.r.t. 1 and 3 = 5/2
Rational lineParameter(QV3 base, QV3 u, QV3 x)

A coordinate along the line through base in direction u (the first coordinate the line moves in).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final base = QV3.ints(1, 1, 1), u = QV3.ints(2, 4, 6);
  final x = base + u.scale(q(3, 4));
  print('x = $x');
  print('parameter of x: ${exact(lineParameter(base, u, x))}');
  print('direction with u.x = 0: ${exact(lineParameter(QV3.zero, QV3.ints(0, 5, 0), QV3.ints(0, -2, 0)))}');
}
Output
x = (5/2, 4, 11/2)
parameter of x: 3/4
direction with u.x = 0: −2/5
({Rational quarterDiscriminant, List<QP2> rational}) tangentPoints(ConicForm conic, QP2 pole)

The points where the tangents from pole touch conic: the polar's meets with the conic. They need the root of the quarter discriminant B(p, u)^{2} - Q(u) \cdot f(p) along the polar; rational exactly when it is a square. Returns the quarter discriminant (negative: the pole is inside, no real tangents) and the points when rational.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final circle = ConicForm.coefficients(q(1), q(0), q(1), q(0), q(0), q(-1));
  final pole = (q(5, 3), q(0));
  final r = tangentPoints(circle, pole);
  print('quarter discriminant: ${exact(r.quarterDiscriminant)}');
  for (final p in r.rational) {
    print('touches at (${exact(p.$1)}, ${exact(p.$2)}), on the circle: ${circle.contains(p)}');
  }
  print('from (2, 0) the points are not rational: ${tangentPoints(circle, (q(2), q(0))).rational.isEmpty}');
        'points': [[5 / 3, 0, 'pole'], for (final p in r.rational) [p.$1.toDouble(), p.$2.toDouble(), '(${exact(p.$1)}, ${exact(p.$2)})']],
        'segments': [for (final p in r.rational) [5 / 3, 0, p.$1.toDouble(), p.$2.toDouble()]]})}');
}
Output
quarter discriminant: 16/9
touches at (3/5, 4/5), on the circle: true
touches at (3/5, −4/5), on the circle: true
from (2, 0) the points are not rational: true

Typedefs

QP2typedef
typedef QP2 = (Rational, Rational)

A point of the plane with rational coordinates.

QLine3typedef
typedef QLine3 = ({QV3 point, QV3 direction})

A straight line p + \lambda u on a surface.

Classes

enum ClassicKind

The classic kind of a section, read off e = \cos \beta / \cos \alpha in doubles: e < 1 ellipse, e = 1 parabola, e > 1 hyperbola (and \beta = 90^{\circ} a circle). Equality of two doubles decides the parabola, so a plane exactly parallel to a generator can come out an ellipse or a hyperbola by one rounding.

Values

circlevalue
circle
ellipsevalue
ellipse
parabola
hyperbola
pointvalue
point
linevalue
line
linePair
final class ClassicSlice

The cone of half-angle alpha cut by a plane at angle beta to the axis, offset from the vertex (radians).

Constructors

ClassicSliceconstructor
ClassicSlice(this.alpha, this.beta, this.offset)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';
import 'raya:math' as math;

void main() {
  // A cone of half-angle 30° cut by planes at 20°, 30° and 60° to the axis.
  for (final deg in [20.0, 30.0, 60.0]) {
    final s = ClassicSlice(math.pi / 6, deg * math.pi / 180, 1);
    print('β = ${deg.toStringAsFixed(0)}°: e = ${s.eccentricity.toStringAsFixed(4)} → ${s.kind.name}');
  }
  final e = ClassicSlice(math.pi / 6, math.pi / 3, 1);
  final (a, b) = e.semiAxes;
  print('the ellipse: semi-axes ${a.toStringAsFixed(4)}, ${b.toStringAsFixed(4)}');
        {'label': 'ellipse', 'points': [for (final (u, v) in e.points(80).first) [u, v]]},
      ]})}');
}
Output
β = 20°: e = 1.0851 → hyperbola
β = 30°: e = 1.0000 → parabola
β = 60°: e = 0.5774 → ellipse
the ellipse: semi-axes 0.7071, 0.8660
factory ClassicSlice.fromSlopes(double mu, double tau, double offset)

From the lab's rational inputs: \tan \alpha = \mu and the tilt's Cayley half-tangent \tau (\theta = 2 \operatorname{atan} \tau).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';
import 'raya:math' as math;

void main() {
  // The same cones and planes as the exact ConeSlice: tan α = 3/4, tilt half-tangent τ.
  for (final (t, tq) in [(0.25, q(1, 4)), (0.75, q(3, 4))]) {
    final classic = ClassicSlice.fromSlopes(0.75, t, 1);
    final exactSlice = ConeSlice(q(3, 4), tq, q(1));
    print('τ = $t: classic ${classic.kind.name} (e = ${classic.eccentricity.toStringAsFixed(6)}), '
        'exact ${exactSlice.kind.name} (e² = ${exact(exactSlice.eccentricitySquared)})');
  }
  // τ = 1/2 is the parabola exactly; in doubles e comes out near 1 and the kind depends on rounding.
  print('τ = 0.5: e − 1 = ${(ClassicSlice.fromSlopes(0.75, 0.5, 1).eccentricity - 1).abs() < 1e-12}');
}
Output
τ = 0.25: classic ellipse (e = 0.588235), exact ellipse (e² = 100/289)
τ = 0.75: classic hyperbola (e = 1.200000), exact hyperbola (e² = 36/25)
τ = 0.5: e − 1 = true

Properties

alphafield
final double alpha
betafield
final double beta
offsetfield
final double offset
cfield
late final double c
sfield
late final double s
mfield
late final double m
bigCfield
late final double bigC
bigEfield
late final double bigE
bigFfield
late final double bigF
double get eccentricity

e = \cos \beta / \cos \alpha.

double get alphaDegrees
double get betaDegrees
kindgetter
ClassicKind get kind
v0getter
double get v0

The centre's v and the right side R of u^{2} + C(v - v_{0})^{2} = R.

rgetter
double get r
semiAxesgetter
(double, double) get semiAxes

Semi-axes (along u and along v) of an ellipse: \sqrt{R} and \sqrt{\frac{R}{C}}.

spheresgetter
List<({double z, double radius, double touch, (double, double, double) focus})> get spheres

The Dandelin spheres the classic way: centres z = offset/(\cos \theta \pm \sin \alpha) (one sphere for a parabola), radii

z\sin \alpha, touch heights z \cos^{2}\alpha; the focal distances are lengths, square roots of sums of squares.

Methods

residualmethod
double residual(double u, double v)

u^{2} + C v^{2} + E v + F in doubles at a point of the plane (zero on the section, up to rounding).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';
import 'raya:math' as math;

void main() {
  final s = ClassicSlice.fromSlopes(0.75, 0.25, 1);
  var worst = 0.0;
  for (final (u, v) in s.points(64).first) {
    worst = math.max(worst, s.residual(u, v).abs());
  }
  print('${s.kind.name}: largest residual on 64 sampled points below 1e-12: ${worst < 1e-12}');
  print('residual at the centre (0, v₀): ${s.residual(0, s.v0).toStringAsFixed(6)}  (= −R)');
        {'label': 'r(0, v)', 'points': [for (var i = 0; i <= 60; i++) [-1 + i / 15, s.residual(0, -1 + i / 15)]]},
      ]})}');
}
Output
ellipse: largest residual on 64 sampled points below 1e-12: true
residual at the centre (0, v₀): -0.860119  (= −R)
pointsmethod
List<List<(double, double)>> points(int n, {double reach = 2.2})

Points of the section in plane coordinates (u, v), from an angle: (a \cos \varphi, v_{0} + b \sin \varphi) for an ellipse, cosh and sinh for a hyperbola (both branches), and v = -\frac{u^{2} + F}{E} for a parabola. n points a branch.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';
import 'raya:math' as math;

void main() {
  final series = <Map<String, Object>>[];
  for (final (name, tau) in [('ellipse', 0.25), ('hyperbola', 0.75)]) {
    final s = ClassicSlice.fromSlopes(0.75, tau, 1);
    final branches = s.points(60, reach: 1.6);
    print('$name: ${branches.length} branch(es), ${branches.first.length} points each');
    for (final (k, b) in branches.indexed) {
      series.add({'label': '$name ${k + 1}', 'points': [for (final (u, v) in b) [u, v]]});
    }
  }
}
Output
ellipse: 1 branch(es), 61 points each
hyperbola: 2 branch(es), 60 points each
enum SliceKind

What the plane cuts from the cone.

Values

circlevalue
circle
ellipsevalue
ellipse
parabola
hyperbola
pointvalue
point

Degenerate (the plane through the vertex): the vertex alone, one generator (the plane touches the cone), or two generators.

linevalue
line
linePair

Properties

bool get degenerate
final class ConeSlice

The right double cone x^{2} + y^{2} = \mu^{2} z^{2} (generators of slope \mu against the axis: \tan \alpha = \mu) cut by the plane at distance offset from the vertex, its normal tilted from the axis by the Cayley half-tangent tau (c = \frac{1 - \tau^{2}}{1 + \tau^{2}}, s = \frac{2\tau}{1 + \tau^{2}}; the plane -s y + c z = offset).

Everything is decided over Q without an angle: the spread between a generator and the axis, s_{\alpha} = \frac{\mu^{2}}{1 + \mu^{2}}, against the spread between the plane and the axis, s_{\beta} = c^{2}. The plane is steeper than the generators (s_{\beta} < s_{\alpha}) for a hyperbola, parallel to one (s_{\beta} = s_{\alpha}) for a parabola, shallower (s_{\beta} > s_{\alpha}) for an ellipse; through the vertex (offset 0) it is a point, a line or a pair. The classic eccentricity e = \cos \beta / \cos \alpha is a root, but its square e^{2} = \frac{1 - s_{\beta}}{1 - s_{\alpha}} = s^{2}(1 + \mu^{2}) is rational.

Constructors

ConeSliceconstructor
ConeSlice(this.mu, this.tau, this.offset)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final mu = q(3, 4);
  for (final tau in [q(0), q(1, 4), q(1, 2), q(3, 4)]) {
    final s = ConeSlice(mu, tau, q(1));
    print('τ = ${exact(tau).padRight(3)} plane spread ${exact(s.spreadPlane).padRight(9)} e² = ${exact(s.eccentricitySquared).padRight(7)} ${s.kind.name}');
  }
  final ellipse = ConeSlice(mu, q(1, 4), q(1));
  print('ellipse: ${ellipse.conic}');
  final pts = [for (final (t, _) in ellipse.rationalPoints(maxDen: 3, range: 3)) ellipse.planePointAt(t)!];
        'points': [for (final p in pts) [p.$1.toDouble(), p.$2.toDouble()]]})}');
}
Output
τ = 0   plane spread 1         e² = 0       circle
τ = 1/4 plane spread 225/289   e² = 100/289 ellipse
τ = 1/2 plane spread 9/25      e² = 1       parabola
τ = 3/4 plane spread 49/625    e² = 36/25   hyperbola
ellipse: 1x² + 0xy + 189/289y² + 0x + −375/289y + −1001/4624 = 0

Properties

mufield
final Rational mu

The generators' slope against the axis (\tan \alpha).

taufield
final Rational tau

The tilt's Cayley half-tangent and the plane's distance from the vertex.

offsetfield
final Rational offset

The tilt's Cayley half-tangent and the plane's distance from the vertex.

cfield
late final Rational c

Cos and sin of the plane's tilt, rational.

sfield
late final Rational s

Cos and sin of the plane's tilt, rational.

framefield
late final PlaneFrame frame
conefield
late final QuadricForm cone
conicfield
late final ConicForm conic

The section in the plane's own (isometric) coordinates u, v.

Rational get spreadGenerator

The spread between a generator and the axis: s_{\alpha} = \frac{\mu^{2}}{1 + \mu^{2}} (classically \sin^{2}\alpha).

Rational get spreadPlane

The spread between the plane and the axis: s_{\beta} = c^{2} (classically \sin^{2}\beta).

Rational get eccentricitySquared

e^{2} = \frac{1 - s_{\beta}}{1 - s_{\alpha}} = s^{2}(1 + \mu^{2}).

kindgetter
SliceKind get kind

The kind, from the spreads (and the offset).

SliceKind get kindFromMatrix

The kind read from the section's matrix instead (det and the 2 \times 2 minor): it agrees with kind always (tested).

normalgetter
QV3 get normal

The plane's unit normal (0, -s, c).

QV3 get generatorAtInfinity
({Rational quarterDiscriminant, List<Rational?> rational}) get asymptoticParameters

The Cayley parameters of the generators parallel to the plane: c t² − 2μs t + c = 0. Their discriminant over 4 is \mu^{2}s^{2} - c^{2}: none for an ellipse, one (doubled) for a parabola, two for a hyperbola, rational exactly when it is a square. A vertical plane (c = 0) has t = 0 and t = \infty.

Methods

generatormethod
QV3 generator(Rational t)

The generator of the Cayley parameter t: (\mu(1 - t^{2}), 2\mu t, 1 + t^{2}); every rational t gives a rational line of the cone through the vertex, and every rational line of the cone but one (t = \infty: (-\mu, 0, 1)) arises so.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final s = ConeSlice(q(3, 4), q(1, 4), q(1));
  for (final t in [q(0), q(1, 2), q(1), q(-2)]) {
    final g = s.generator(t);
    // On the cone: x² + y² = μ² z², exactly.
    final onCone = g.x * g.x + g.y * g.y == s.mu * s.mu * g.z * g.z;
    print('t = ${exact(t).padRight(3)} g = $g  on the cone: $onCone');
  }
        'segments': [for (var k = -6; k <= 6; k++) (() { final g = s.generator(q(k, 2)); return [0, 0, g.x.toDouble() / g.z.toDouble(), g.y.toDouble() / g.z.toDouble()]; })()],
        'circles': [[0, 0, 0.75]]})}');
}
Output
t = 0   g = (3/4, 0, 1)  on the cone: true
t = 1/2 g = (9/16, 3/4, 5/4)  on the cone: true
t = 1   g = (0, 3/2, 2)  on the cone: true
t = −2  g = (−9/4, −3, 5)  on the cone: true
meetmethod
QV3? meet(QV3 g)

Where the generator g meets the plane: offset · g / (n \cdot g), rational. Null when the generator is parallel to the plane (it meets it at infinity: an asymptotic direction of the hyperbola, the axis direction of the parabola). With the plane through the vertex every generator meets it at the vertex.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final ellipse = ConeSlice(q(3, 4), q(1, 4), q(1));
  final g = ellipse.generator(q(1, 2));
  final p = ellipse.meet(g)!;
  print('generator $g meets the plane at $p');
  print('on the plane: ${ellipse.frame.plane.contains(p)}');
  // A parabola's plane is parallel to one generator: that one meets it at infinity.
  final parabola = ConeSlice(q(3, 4), q(1, 2), q(1));
  final t = parabola.asymptoticParameters.rational.first!;
  print('parabola: generator t = ${exact(t)} meets the plane: ${parabola.meet(parabola.generator(t))}');
}
Output
generator (9/16, 3/4, 5/4) meets the plane at (3/4, 1, 5/3)
on the plane: true
parabola: generator t = 1 meets the plane: null
pointAtmethod
QV3? pointAt(Rational? t)

The section's point on generator t (t null: t = \infty). Wildberger's projective view: the conic is where the cone's lines through the eye cross the viewing plane.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final s = ConeSlice(q(3, 4), q(1, 4), q(1));
  for (final t in [q(0), q(1), null]) {
    final p = s.pointAt(t)!;
    print('t = ${t == null ? '∞' : exact(t)}: $p  on cone ${s.cone.contains(p)}, on plane ${s.frame.plane.contains(p)}');
  }
}
Output
t = 0: (17/20, 0, 17/15)  on cone true, on plane true
t = 1: (0, 17/12, 17/9)  on cone true, on plane true
t = ∞: (−17/20, 0, 17/15)  on cone true, on plane true
QP2? planePointAt(Rational? t)

The same point in the plane's coordinates.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';
import 'raya:math' as math;

void main() {
  final s = ConeSlice(q(3, 4), q(1, 4), q(1));
  final (u, v) = s.planePointAt(q(1, 3))!;
  print('t = 1/3 → (${exact(u)}, ${exact(v)}), conic value ${s.conic.value((u, v))}');
  final pts = [for (final (t, _) in s.rationalPoints(maxDen: 6, range: 4)) s.planePointAt(t)!];
  // Order the points round the centre to draw the curve.
  final cv = pts.map((p) => p.$2.toDouble()).reduce(math.max) / 2 + pts.map((p) => p.$2.toDouble()).reduce(math.min) / 2;
  pts.sort((a, b) => math.atan2(a.$2.toDouble() - cv, a.$1.toDouble()).compareTo(math.atan2(b.$2.toDouble() - cv, b.$1.toDouble())));
  print('${pts.length} rational points');
        'polygons': [[for (final p in pts) [p.$1.toDouble(), p.$2.toDouble()]]],
        'points': [[u.toDouble(), v.toDouble(), 't = 1/3']]})}');
}
Output
t = 1/3 → (17/19, 295/228), conic value 0
98 rational points
List<(Rational?, QV3)> rationalPoints({int maxDen = 4, int range = 3})

Rational points of the section: t = \frac{p}{den} for |\frac{p}{den}| ≤ range, every den up to maxDen, and t = \infty.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final s = ConeSlice(q(3, 4), q(3, 4), q(1)); // a hyperbola
  final pts = s.rationalPoints(maxDen: 2, range: 2);
  print('${pts.length} rational points, the first three:');
  for (final (t, p) in pts.take(3)) {
    print('  t = ${t == null ? '∞' : exact(t)}: $p');
  }
  final many = [for (final (t, _) in s.rationalPoints(maxDen: 8, range: 3)) s.planePointAt(t)!];
        'points': [for (final p in many) if (p.$1.toDouble().abs() < 6 && p.$2.toDouble().abs() < 6) [p.$1.toDouble(), p.$2.toDouble()]]})}');
}
Output
10 rational points, the first three:
  t = −2: (−225/428, −75/107, 125/107)
  t = −1: (0, −3/4, 1)
  t = 0: (75/28, 0, 25/7)
List<QP2> chordPoints({int maxDen = 3, int range = 3})

Diophantus' chord method in the plane: from the section's point on generator 0, lines of slope k meet the section again in rational points (k = \frac{p}{den} as above).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final s = ConeSlice(q(3, 4), q(1, 4), q(1));
  final base = s.planePointAt(q(0))!;
  final pts = s.chordPoints(maxDen: 3, range: 3);
  print('from (${exact(base.$1)}, ${exact(base.$2)}): ${pts.length} new rational points');
  print('all on the conic: ${pts.every(s.conic.contains)}');
  final b = [base.$1.toDouble(), base.$2.toDouble()];
        'segments': [for (final p in pts) [b[0], b[1], p.$1.toDouble(), p.$2.toDouble()]],
        'points': [[b[0], b[1], 'base'], for (final p in pts) [p.$1.toDouble(), p.$2.toDouble()]]})}');
}
Output
from (17/20, 8/15): 25 new rational points
all on the conic: true
final class DandelinSphere

One sphere inscribed in the cone and touching the plane.

Constructors

DandelinSphereconstructor
DandelinSphere({required this.centre, required this.radius, required this.focus, required this.touchHeight})
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  // Usually made by DandelinSpheres.of; here one sphere by hand: centre (0, 0, 2), radius 6/5 on the cone μ = 3/4.
  final sp = DandelinSphere(centre: QV3.ints(0, 0, 2), radius: q(6, 5), focus: QV3.ints(0, 0, 1), touchHeight: q(32, 25));
  print('centre ${sp.centre}, radius ${exact(sp.radius)}, touch height ${exact(sp.touchHeight)}');
  // The touch height is z cos²α = z/(1 + μ²).
  print('z/(1 + μ²) = ${exact(q(2) / (q(1) + q(9, 16)))}');
        'segments': [[0, 0, 3, 4], [0, 0, -3, 4]], 'circles': [[0, 2, 1.2]]})}');
}
Output
centre (0, 0, 2), radius 6/5, touch height 32/25
z/(1 + μ²) = 32/25

Properties

centrefield
final QV3 centre

On the axis: (0, 0, z).

radiusfield
final Rational radius
z\sin \alpha (rational on a Pythagorean cone).
focusfield
final QV3 focus

Where it touches the plane: a focus of the section.

final Rational touchHeight

The height of the circle where it touches the cone: z \cos^{2}\alpha = \frac{z}{1 + \mu^{2}}.

final class DandelinSpheres

The Dandelin spheres of a ConeSlice on a Pythagorean cone: one whose 1 + \mu^{2} is a square \kappa^{2} (\mu = \frac{3}{4}: \kappa = \frac{5}{4}, \sin \alpha = \frac{3}{5}, \cos \alpha = \frac{4}{5}). Then the spheres' centres z = offset/(c \pm \sin \alpha), their radii, the foci and every focal distance of a rational point are rational, and Dandelin's theorem is a set of exact identities:

  • The tangent lengths from P are equal: Q(P, F) = Q(P, T), T where P's generator touches the sphere;
  • The focal distances are d = |P_{z} - h| \cdot \kappa (h: the touch circle's height), so d_{1} + d_{2} (ellipse) or |d_{1} - d_{2}| (hyperbola) is the constant L = |h_{1} - h_{2}| \cdot \kappa;
  • Root-free for any cone: the three quadrances Q_{1}, Q_{2} and L^{2} satisfy Archimedes' (Heron's) triple quad formula (Q_{1} + Q_{2} + L^{2})^{2} = 2(Q_{1}^{2} + Q_{2}^{2} + L^{4}), which says \sqrt{Q_{1}} \pm \sqrt{Q_{2}} \pm L = 0 for some signs;
  • Focus and directrix: \frac{Q(P, F)}{Q}(P, directrix) = e^{2} = s^{2}(1 + \mu^{2}).

On any other cone the centres need \sqrt{1 + \mu^{2}}: DandelinSpheres.of returns null and the lab says so.

Static

ofstaticmethod
static DandelinSpheres? of(ConeSlice slice)

The spheres of slice, or null when the cone isn't Pythagorean or the plane passes through the vertex.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final s = ConeSlice(q(3, 4), q(1, 4), q(1));
  final d = DandelinSpheres.of(s)!;
  print('κ = ${exact(d.kappa)}, sin α = ${exact(d.sinAlpha)}, cos α = ${exact(d.cosAlpha)}');
  for (final sp in d.spheres) {
    print('sphere at ${sp.centre}, radius ${exact(sp.radius)}, focus ${sp.focus}');
  }
  print('focal constant d₁ + d₂ = ${exact(d.focalConstant!)}');
  print('μ = 1 (not Pythagorean): ${DandelinSpheres.of(ConeSlice(q(1), q(1, 4), q(1)))}');
  // Side view in the (y, z) plane: the cone's two generators, the plane and the spheres.
  final segs = [[-3.0, -4.0, 3.0, 4.0], [3.0, -4.0, -3.0, 4.0]];
  final c = s.c.toDouble(), sn = s.s.toDouble();
  segs.add([-3, (1 + sn * -3) / c, 3, (1 + sn * 3) / c]);
        'circles': [for (final sp in d.spheres) [0, sp.centre.z.toDouble(), sp.radius.toDouble()]],
        'points': [for (final sp in d.spheres) [sp.focus.y.toDouble(), sp.focus.z.toDouble(), 'F']]})}');
}
Output
κ = 5/4, sin α = 3/5, cos α = 4/5
sphere at (0, 0, 85/126), radius 17/42, focus (0, −4/21, 65/63)
sphere at (0, 0, 85/24), radius 17/8, focus (0, 1, 5/3)
focal constant d₁ + d₂ = 289/126
μ = 1 (not Pythagorean): null

Properties

slicefield
final ConeSlice slice
kappafield
final Rational kappa

\sqrt{1 + \mu^{2}} = \frac{1}{\cos \alpha}, rational.

spheresfield
final List<DandelinSphere> spheres

Two spheres (ellipse, hyperbola; one for a parabola, the other is at infinity). For a circle the two foci meet at the centre.

sinAlphagetter
Rational get sinAlpha
cosAlphagetter
Rational get cosAlpha
Rational? get focalConstant

The distance along a generator between the two touch circles: d_{1} + d_{2} (ellipse) or |d_{1} - d_{2}| (hyperbola).

Methods

Rational focalDistance(QV3 p, int i)

The distance from the section's point p to focus i, exact: |P_{z} - h_{i}| \cdot \kappa.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final s = ConeSlice(q(3, 4), q(1, 4), q(1));
  final d = DandelinSpheres.of(s)!;
  for (final (t, p) in s.rationalPoints(maxDen: 1, range: 1)) {
    final d1 = d.focalDistance(p, 0), d2 = d.focalDistance(p, 1);
    print('t = ${t == null ? '∞' : exact(t)}: d₁ = ${exact(d1)}, d₂ = ${exact(d2)}, sum ${exact(d1 + d2)}');
  }
}
Output
t = −1: d₁ = 17/36, d₂ = 51/28, sum 289/126
t = 0: d₁ = 221/252, d₂ = 17/12, sum 289/126
t = 1: d₁ = 51/28, d₂ = 17/36, sum 289/126
t = ∞: d₁ = 221/252, d₂ = 17/12, sum 289/126
QV3 touchPoint(QV3 p, int i)

Where p's generator (the line from the vertex through p) touches sphere i.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final s = ConeSlice(q(3, 4), q(1, 4), q(1));
  final d = DandelinSpheres.of(s)!;
  final p = s.pointAt(q(1, 2))!;
  for (var i = 0; i < 2; i++) {
    final tp = d.touchPoint(p, i);
    // Two tangents from P to the same sphere: Q(P, F) = Q(P, T), exactly.
    print('sphere $i: T = $tp, Q(P,F) = ${exact(quadrance(p, d.spheres[i].focus))}, Q(P,T) = ${exact(quadrance(p, tp))}');
  }
}
Output
sphere 0: T = (34/175, 136/525, 136/315), Q(P,F) = 151321/63504, Q(P,T) = 151321/63504
sphere 1: T = (51/50, 34/25, 34/15), Q(P,F) = 9/16, Q(P,T) = 9/16
Rational? directrixV(int i)

The directrix of sphere i in the plane's coordinates: the line v = (h - c·offset)/s (null for a circle, s = 0).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final s = ConeSlice(q(3, 4), q(1, 4), q(1));
  final d = DandelinSpheres.of(s)!;
  print('directrices: v = ${exact(d.directrixV(0)!)} and v = ${exact(d.directrixV(1)!)}');
  print('a circle has none: ${DandelinSpheres.of(ConeSlice(q(3, 4), q(0), q(1)))!.directrixV(0)}');
  final pts = [for (final (t, _) in s.rationalPoints(maxDen: 4, range: 4)) s.planePointAt(t)!];
  final v0 = d.directrixV(0)!.toDouble(), v1 = d.directrixV(1)!.toDouble();
        'points': [for (final p in pts) [p.$1.toDouble(), p.$2.toDouble()]],
        'segments': [[-2, v0, 2, v0], [-2, v1, 2, v1]]})}');
}
Output
directrices: v = −2413/2520 and v = 353/120
a circle has none: null
Rational? focusDirectrixRatio(QV3 p, int i)

Q(P, F_{i}) / Q(P, directrix_i): equals e^{2} at every point of the section.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final s = ConeSlice(q(3, 4), q(1, 4), q(1));
  final d = DandelinSpheres.of(s)!;
  print('e² = ${exact(s.eccentricitySquared)}');
  for (final (t, p) in s.rationalPoints(maxDen: 2, range: 1).take(5)) {
    print('t = ${t == null ? '∞' : exact(t)}: Q(P,F)/Q(P,directrix) = ${exact(d.focusDirectrixRatio(p, 0)!)}');
  }
}
Output
e² = 100/289
t = −1: Q(P,F)/Q(P,directrix) = 100/289
t = 0: Q(P,F)/Q(P,directrix) = 100/289
t = 1: Q(P,F)/Q(P,directrix) = 100/289
t = −1/2: Q(P,F)/Q(P,directrix) = 100/289
t = 1/2: Q(P,F)/Q(P,directrix) = 100/289
class

QV3

final class QV3

A point or vector of three-dimensional space with rational coordinates.

Constructors

QV3constructor
QV3(this.x, this.y, this.z)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final v = QV3(q(1, 2), q(-3), q(2, 3));
  print('v = $v');
  print('quadrance ${exact(v.quadrance)}, as doubles ${v.d}');
  print('homogeneous ${v.homogeneous}');
}
Output
v = (1/2, −3, 2/3)
quadrance 349/36, as doubles (0.5, -3.0, 0.6666666666666666)
homogeneous [1/2, -3, 2/3, 1]
QV3.intsfactory
factory QV3.ints(int x, int y, int z)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final v = QV3.ints(3, 4, 12);
  print('v = $v, Q = ${v.quadrance}');
  print('equal to QV3(q(3), q(4), q(12)): ${v == QV3(q(3), q(4), q(12))}');
}
Output
v = (3, 4, 12), Q = 169
equal to QV3(q(3), q(4), q(12)): true

Static

zerostaticfield
static final QV3 zero

Properties

xfield
final Rational x
yfield
final Rational y
zfield
final Rational z
quadrancegetter
Rational get quadrance

The quadrance (squared length): Wildberger's replacement for distance.

isZerogetter
bool get isZero
dgetter
(double, double, double) get d

As doubles, for drawing (the boundary).

List<Rational> get homogeneous

The homogeneous point [x, y, z, 1].

directiongetter
List<Rational> get direction

The homogeneous direction [x, y, z, 0] (a point at infinity).

hashCodegetter
int get hashCode

Methods

scalemethod
QV3 scale(Rational k)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final v = QV3.ints(2, -4, 6);
  print('v·(1/2) = ${v.scale(q(1, 2))}');
  print('v·(−3/4) = ${v.scale(q(-3, 4))}');
  print('Q scales by k²: ${v.scale(q(1, 2)).quadrance == v.quadrance * q(1, 4)}');
}
Output
v·(1/2) = (1, −2, 3)
v·(−3/4) = (−3/2, 3, −9/2)
Q scales by k²: true
dotmethod
Rational dot(QV3 o)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final a = QV3.ints(1, 2, 2), b = QV3(q(2), q(-1), q(1, 2));
  print('a·b = ${exact(a.dot(b))}');
  print('perpendicular: (1, 1, 0)·(1, −1, 5) = ${QV3.ints(1, 1, 0).dot(QV3.ints(1, -1, 5))}');
  // The spread between a and b: 1 − (a·b)²/(Q(a)Q(b)), exact.
  print('spread = ${exact(q(1) - a.dot(b) * a.dot(b) / (a.quadrance * b.quadrance))}');
}
Output
a·b = 1
perpendicular: (1, 1, 0)·(1, −1, 5) = 0
spread = 185/189
crossmethod
QV3 cross(QV3 o)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final a = QV3.ints(1, 0, 0), b = QV3.ints(0, 1, 0);
  print('x × y = ${a.cross(b)}');
  final u = QV3(q(1, 2), q(2), q(-1)), w = QV3.ints(3, 0, 1);
  final n = u.cross(w);
  print('u × w = $n, perpendicular to both: ${n.dot(u).isZero && n.dot(w).isZero}');
        'segments': [[0, 0, 0.5, 2], [0, 0, 3, 0]], 'points': [[0.5, 2, 'u'], [3, 0, 'w']]})}');
}
Output
x × y = (0, 0, 1)
u × w = (2, −7/2, −6), perpendicular to both: true
toStringmethod
String toString()
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  print(QV3(q(-1, 2), q(3), q(0)));
  print('${QV3.ints(1, 2, 3)}');
}
Output
(−1/2, 3, 0)
(1, 2, 3)

Operators

operator +operator
QV3 operator +(QV3 o)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final a = QV3.ints(1, 2, 0), b = QV3(q(2), q(1, 2), q(1));
  print('a + b = ${a + b}');
        'segments': [[0, 0, 1, 2], [1, 2, 3, 2.5], [0, 0, 3, 2.5]], 'points': [[1, 2, 'a'], [3, 2.5, 'a + b']]})}');
}
Output
a + b = (3, 5/2, 1)
operator -operator
QV3 operator -(QV3 o)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final a = QV3.ints(4, 6, 3), b = QV3.ints(1, 2, 3);
  print('a − b = ${a - b}');
  print('quadrance(a, b) = Q(a − b) = ${(a - b).quadrance}');
}
Output
a − b = (3, 4, 0)
quadrance(a, b) = Q(a − b) = 25
operator -operator
QV3 operator -()
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final v = QV3(q(1, 2), q(-2), q(3));
  print('−v = ${-v}');
  print('v + (−v) is zero: ${(v + -v).isZero}');
}
Output
−v = (−1/2, 2, −3)
v + (−v) is zero: true
operator ==operator
bool operator ==(Object other)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  print(QV3(q(2, 4), q(1), q(0)) == QV3(q(1, 2), q(1), q(0)));
  print(QV3.ints(1, 2, 3) == QV3.ints(1, 2, 4));
  print('usable in sets: ${{QV3.ints(1, 1, 1), QV3(q(2, 2), q(1), q(1))}.length}');
}
Output
true
false
usable in sets: 1
class

QLine

final class QLine

The line a x + b y + c = 0 (homogeneous coordinates [a: b: c]).

Constructors

QLineconstructor
QLine(this.a, this.b, this.c)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

List<double> segOf(QLine l, double lo, double hi) {
  final a = l.a.toDouble(), b = l.b.toDouble(), c = l.c.toDouble();
  if (b.abs() > 1e-12) return [lo, -(a * lo + c) / b, hi, -(a * hi + c) / b];
  return [-c / a, lo, -c / a, hi];
}

void main() {
  final l = QLine(q(1), q(2), q(-4)); // x + 2y − 4 = 0
  print('line: $l');
  print('(2, 1) on it: ${l.contains((q(2), q(1)))}');
}
Output
line: x + 2 y − 4 = 0
(2, 1) on it: true
QLine.joinfactory
factory QLine.join(QP2 p, QP2 r)

The line through two distinct points (the cross product of [x: y: 1]).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

List<double> segOf(QLine l, double lo, double hi) {
  final a = l.a.toDouble(), b = l.b.toDouble(), c = l.c.toDouble();
  if (b.abs() > 1e-12) return [lo, -(a * lo + c) / b, hi, -(a * hi + c) / b];
  return [-c / a, lo, -c / a, hi];
}

void main() {
  final p = (q(1), q(1)), r = (q(4), q(3));
  final l = QLine.join(p, r);
  print('join of (1, 1) and (4, 3): $l');
  print('contains both: ${l.contains(p) && l.contains(r)}');
}
Output
join of (1, 1) and (4, 3): −2 x + 3 y − 1 = 0
contains both: true

Properties

afield
final Rational a
bfield
final Rational b
cfield
final Rational c

Methods

atmethod
Rational at(QP2 p)

A x + b y + c at p: zero exactly when p lies on the line.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final l = QLine(q(3), q(-4), q(0)); // 3x − 4y = 0
  for (final p in [(q(4), q(3)), (q(0), q(1)), (q(1, 3), q(1, 4))]) {
    print('at (${exact(p.$1)}, ${exact(p.$2)}) = ${exact(l.at(p))}');
  }
}
Output
at (4, 3) = 0
at (0, 1) = −4
at (1/3, 1/4) = 0
containsmethod
bool contains(QP2 p)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final l = QLine.join((q(0), q(0)), (q(1, 3), q(1, 7)));
  print('line $l');
  print('(1/3, 1/7): ${l.contains((q(1, 3), q(1, 7)))}');
  print('(7, 3): ${l.contains((q(7), q(3)))}');
  print('(3, 7): ${l.contains((q(3), q(7)))}');
}
Output
line −1/7 x + 1/3 y = 0
(1/3, 1/7): true
(7, 3): true
(3, 7): false
meetmethod
QP2? meet(QLine o)

The meet of two lines, or null when they are parallel (they meet at infinity).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

List<double> segOf(QLine l, double lo, double hi) {
  final a = l.a.toDouble(), b = l.b.toDouble(), c = l.c.toDouble();
  if (b.abs() > 1e-12) return [lo, -(a * lo + c) / b, hi, -(a * hi + c) / b];
  return [-c / a, lo, -c / a, hi];
}

void main() {
  final l = QLine(q(1), q(-1), q(0)), m = QLine(q(1), q(2), q(-3));
  final p = l.meet(m)!;
  print('meet: (${exact(p.$1)}, ${exact(p.$2)})');
  print('parallel lines: ${l.meet(QLine(q(2), q(-2), q(5)))}');
        'segments': [segOf(l, -1, 3), segOf(m, -1, 3)], 'points': [[p.$1.toDouble(), p.$2.toDouble(), 'meet']]})}');
}
Output
meet: (1, 1)
parallel lines: null
toStringmethod
String toString()
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  print(QLine(q(-10, 9), q(-1, 2), q(-1)));
  print(QLine(q(1), q(0), q(3, 2)));
}
Output
−10/9 x − 1/2 y − 1 = 0
x + 3/2 = 0
class

SymForm

final class SymForm

A symmetric n \times n matrix over Q: the quadratic form x^{T} M x on homogeneous coordinates.

Constructors

SymFormconstructor
SymForm(List<List<Rational>> rows)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final m = SymForm([
    [q(1), q(1, 2), q(0)],
    [q(1, 2), q(2), q(-1)],
    [q(0), q(-1), q(3)],
  ]);
  print('size ${m.size}, det ${exact(m.determinant)}, rank ${m.rank}');
  try {
    SymForm([[q(1), q(2)], [q(3), q(1)]]);
  } on ArgumentError catch (e) {
    print('rejected: ${e.message}');
  }
}
Output
size 3, det 17/4, rank 3
rejected: not symmetric at (1, 0)

Properties

mfield
final List<List<Rational>> m
sizegetter
int get size
Rational get determinant

The determinant (cofactor expansion; sizes up to 4).

rankgetter
int get rank

The rank (Gaussian elimination over Q).

hashCodegetter
int get hashCode

Methods

applymethod
List<Rational> apply(List<Rational> a)

M a.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final m = SymForm([
    [q(2), q(1)],
    [q(1), q(3)],
  ]);
  final y = m.apply([q(1), q(-1, 2)]);
  print('M (1, −1/2) = (${y.map(exact).join(', ')})');
}
Output
M (1, −1/2) = (3/2, −1/2)
bilinearmethod
Rational bilinear(List<Rational> a, List<Rational> b)

a^{T} M b (the polar, or bilinear, form).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final m = SymForm([
    [q(1), q(0), q(0)],
    [q(0), q(1), q(0)],
    [q(0), q(0), q(-1)],
  ]);
  final a = [q(3), q(4), q(5)], b = [q(1), q(1, 2), q(1)];
  print('aᵀ M b = ${exact(m.bilinear(a, b))}');
  print('symmetric: ${m.bilinear(a, b) == m.bilinear(b, a)}');
}
Output
aᵀ M b = 0
symmetric: true
formmethod
Rational form(List<Rational> a)

a^{T} M a.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  // The cone x² + y² − z² as a 3 × 3 form: (3, 4, 5) lies on it.
  final m = SymForm([
    [q(1), q(0), q(0)],
    [q(0), q(1), q(0)],
    [q(0), q(0), q(-1)],
  ]);
  print('Q(3, 4, 5) = ${m.form([q(3), q(4), q(5)])}');
  print('Q(1, 1, 1) = ${m.form([q(1), q(1), q(1)])}');
}
Output
Q(3, 4, 5) = 0
Q(1, 1, 1) = 1

Operators

operator ==operator
bool operator ==(Object other)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final a = SymForm([[q(1), q(1, 2)], [q(1, 2), q(1)]]);
  final b = SymForm([[q(2, 2), q(2, 4)], [q(2, 4), q(3, 3)]]);
  print('a == b: ${a == b}');
  print('a == 2a: ${a == SymForm([[q(2), q(1)], [q(1), q(2)]])}');
}
Output
a == b: true
a == 2a: false
enum ConicKind

What a plane conic is, decided exactly from its matrix.

Values

circlevalue
circle
ellipsevalue
ellipse
parabola
hyperbola
emptyvalue
empty

x^{2} + y^{2} = -1: no real points.

pointvalue
point

Degenerate: a single real point (two conjugate lines).

linePair

Degenerate: two lines crossing.

parallelLines

Degenerate: two parallel lines.

doubleLine

Degenerate: one line counted twice.

Properties

bool get degenerate
final class ConicForm

The plane conic A x^{2} + B xy + C y^{2} + D x + E y + F = 0 as the symmetric matrix of [x, y, 1].

Constructors

ConicFormconstructor
ConicForm(this.form)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

// Points of a conic through the chord method from a rational point p, ordered by slope.
List<List<double>> trace(ConicForm c, QP2 p) => [
      for (var k = -60; k <= 60; k++)
        if (c.throughPoint(p, q(k, 8)) case final x?) [x.$1.toDouble(), x.$2.toDouble()],
    ];

void main() {
  // x²/4 + y² − 1 = 0 as its symmetric matrix.
  final c = ConicForm(SymForm([
    [q(1, 4), q(0), q(0)],
    [q(0), q(1), q(0)],
    [q(0), q(0), q(-1)],
  ]));
  print('$c');
  print('kind ${c.kind.name}, det ${exact(c.determinant)}, discriminant ${exact(c.discriminant)}');
}
Output
1/4x² + 0xy + 1y² + 0x + 0y + −1 = 0
kind ellipse, det −1/4, discriminant −1
factory ConicForm.coefficients(Rational a, Rational b, Rational c, Rational d, Rational e, Rational f)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

// Points of a conic through the chord method from a rational point p, ordered by slope.
List<List<double>> trace(ConicForm c, QP2 p) => [
      for (var k = -60; k <= 60; k++)
        if (c.throughPoint(p, q(k, 8)) case final x?) [x.$1.toDouble(), x.$2.toDouble()],
    ];

void main() {
  final kinds = {
    'x² + y² − 1': ConicForm.coefficients(q(1), q(0), q(1), q(0), q(0), q(-1)),
    'x² − y − 1': ConicForm.coefficients(q(1), q(0), q(0), q(0), q(-1), q(-1)),
    'xy − 1': ConicForm.coefficients(q(0), q(1), q(0), q(0), q(0), q(-1)),
    'x² − y²': ConicForm.coefficients(q(1), q(0), q(-1), q(0), q(0), q(0)),
  };
  kinds.forEach((name, c) => print('${name.padRight(12)} → ${c.kind.name}'));
  final par = kinds['x² − y − 1']!;
        {'label': 'chord points', 'style': 'points', 'points': trace(par, (q(1), q(0)))..removeWhere((p) => p[0].abs() > 3)},
      ]})}');
}
Output
x² + y² − 1  → circle
x² − y − 1   → parabola
xy − 1       → hyperbola
x² − y²      → linePair

Properties

formfield
final SymForm form
agetter
Rational get a
bgetter
Rational get b
cgetter
Rational get c
dgetter
Rational get d
egetter
Rational get e
fgetter
Rational get f
Rational get determinant

\det M (zero: degenerate).

minorgetter
Rational get minor

AC - \frac{B^{2}}{4}: positive for ellipses, zero for parabolas, negative for hyperbolas (-\tfrac{1}{4} of the discriminant B² − 4AC).

Rational get discriminant

B² − 4AC.

kindgetter
ConicKind get kind

The kind, exactly: the sign of the 2 \times 2 minor, whether \det M vanishes, and for real ellipses the sign of A \cdot \det.

Methods

valuemethod
Rational value(QP2 p)

The value at p: zero exactly on the conic.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final c = ConicForm.coefficients(q(1), q(0), q(1), q(0), q(0), q(-25));
  for (final p in [(q(3), q(4)), (q(0), q(0)), (q(6), q(0))]) {
    print('value at (${exact(p.$1)}, ${exact(p.$2)}) = ${exact(c.value(p))}');
  }
        {'label': 'f(x, 0)', 'points': [for (var i = -7; i <= 7; i++) [i, c.value((q(i), q(0))).toDouble()]]},
      ]})}');
}
Output
value at (3, 4) = 0
value at (0, 0) = −25
value at (6, 0) = 11
containsmethod
bool contains(QP2 p)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final c = ConicForm.coefficients(q(1), q(0), q(1), q(0), q(0), q(-1));
  final pts = [(q(3, 5), q(4, 5)), (q(5, 13), q(-12, 13)), (q(1, 2), q(1, 2))];
  for (final p in pts) {
    print('(${exact(p.$1)}, ${exact(p.$2)}) on the unit circle: ${c.contains(p)}');
  }
        'points': [for (final p in pts) [p.$1.toDouble(), p.$2.toDouble(), c.contains(p) ? 'on' : 'off']]})}');
}
Output
(3/5, 4/5) on the unit circle: true
(5/13, −12/13) on the unit circle: true
(1/2, 1/2) on the unit circle: false
polarmethod
QLine polar(QP2 p)

The polar of p (Apollonius; the tangent when p is on the conic): the line M [p, 1].

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

List<double> segOf(QLine l, double lo, double hi) {
  final a = l.a.toDouble(), b = l.b.toDouble(), c = l.c.toDouble();
  if (b.abs() > 1e-12) return [lo, -(a * lo + c) / b, hi, -(a * hi + c) / b];
  return [-c / a, lo, -c / a, hi];
}

void main() {
  final c = ConicForm.coefficients(q(1), q(0), q(1), q(0), q(0), q(-1));
  final pole = (q(2), q(1));
  final l = c.polar(pole);
  print('polar of (2, 1): $l');
  print('tangent at (3/5, 4/5): ${c.polar((q(3, 5), q(4, 5)))}');
        'segments': [segOf(l, -1.5, 1.5)], 'points': [[2, 1, 'pole']]})}');
}
Output
polar of (2, 1): 2 x + y − 1 = 0
tangent at (3/5, 4/5): 3/5 x + 4/5 y − 1 = 0
QLine polarOfDirection(QP2 u)

The polar of the point at infinity in direction u (a diameter).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

List<double> segOf(QLine l, double lo, double hi) {
  final a = l.a.toDouble(), b = l.b.toDouble(), c = l.c.toDouble();
  if (b.abs() > 1e-12) return [lo, -(a * lo + c) / b, hi, -(a * hi + c) / b];
  return [-c / a, lo, -c / a, hi];
}

void main() {
  // The diameter of x²/4 + y² = 1 conjugate to the direction (1, 1).
  final c = ConicForm.coefficients(q(1, 4), q(0), q(1), q(0), q(0), q(-1));
  final d = c.polarOfDirection((q(1), q(1)));
  print('conjugate diameter of (1, 1): $d');
  print('passes through the centre: ${d.contains((q(0), q(0)))}');
        'polygons': [[for (var k = 0; k < 48; k++) [2 * (1 - (k / 12 - 2) * (k / 12 - 2)) / (1 + (k / 12 - 2) * (k / 12 - 2)), 2 * (k / 12 - 2) / (1 + (k / 12 - 2) * (k / 12 - 2))]]],
        'segments': [[-1, -1, 1, 1], segOf(d, -2, 2)]})}');
}
Output
conjugate diameter of (1, 1): 1/4 x + y = 0
passes through the centre: true
QP2? secondMeet(QP2 p, QP2 u)

The second meet of the line through p (on the conic) in direction u, or null for a tangent or asymptotic direction. With x = p + \lambda u: f(x) = f(p) + 2\lambda B(p, u) + \lambda^{2} Q(u), and f(p) = 0, so \lambda = -\frac{2B(p, u)}{Q(u)}: no root.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final c = ConicForm.coefficients(q(1), q(0), q(1), q(0), q(0), q(-1));
  final p = (q(-1), q(0));
  final x = c.secondMeet(p, (q(2), q(1)))!;
  print('from (−1, 0) in direction (2, 1): (${exact(x.$1)}, ${exact(x.$2)})');
  print('tangent direction (0, 1): ${c.secondMeet(p, (q(0), q(1)))}');
        'segments': [[-1, 0, x.$1.toDouble(), x.$2.toDouble()]], 'points': [[-1, 0, 'p'], [x.$1.toDouble(), x.$2.toDouble(), 'second meet']]})}');
}
Output
from (−1, 0) in direction (2, 1): (3/5, 4/5)
tangent direction (0, 1): (-1, 0)
QP2? throughPoint(QP2 p, Rational? t)

Diophantus' chord method: from one rational point p, the line of slope t meets the conic again in a rational point (slope null: the vertical line).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  // Diophantus: lines of rational slope through (−1, 0) give every rational point of x² + y² = 1.
  final c = ConicForm.coefficients(q(1), q(0), q(1), q(0), q(0), q(-1));
  final pts = <List<Object>>[];
  for (final t in [q(1, 2), q(1, 3), q(2, 3), q(-1, 4), q(3)]) {
    final x = c.throughPoint((q(-1), q(0)), t)!;
    print('slope ${exact(t).padRight(4)} → (${exact(x.$1)}, ${exact(x.$2)})');
    pts.add([x.$1.toDouble(), x.$2.toDouble(), exact(t)]);
  }
        'segments': [for (final p in pts) [-1, 0, p[0], p[1]]]})}');
}
Output
slope 1/2  → (3/5, 4/5)
slope 1/3  → (4/5, 3/5)
slope 2/3  → (5/13, 12/13)
slope −1/4 → (15/17, −8/17)
slope 3    → (−4/5, 3/5)
isPoleOfmethod
bool isPoleOf(QP2 r, QLine line)

Is the point r the pole of line: does M r equal the line up to a scalar?

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final c = ConicForm.coefficients(q(1), q(0), q(1), q(0), q(0), q(-1));
  final l = QLine(q(4), q(2), q(-2)); // a multiple of 2x + y − 1
  print('(2, 1) is the pole of $l: ${c.isPoleOf((q(2), q(1)), l)}');
  print('(1, 1) is its pole: ${c.isPoleOf((q(1), q(1)), l)}');
}
Output
(2, 1) is the pole of 4 x + 2 y − 2 = 0: true
(1, 1) is its pole: false
toStringmethod
String toString()
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final c = ConicForm.coefficients(q(1, 4), q(0), q(1), q(-1), q(1, 2), q(-1));
  print(c);
  print(ConeSlice(q(3, 4), q(1, 2), q(1)).conic);
}
Output
1/4x² + 0xy + 1y² + −1x + 1/2y + −1 = 0
1x² + 0xy + 0y² + 0x + −3/2y + 7/16 = 0
class

QPlane

final class QPlane

The plane n \cdot X + k = 0 in space.

Constructors

QPlaneconstructor
QPlane(this.n, this.k)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final p = QPlane(QV3.ints(1, 1, 1), q(-3)); // x + y + z = 3
  print('(1, 1, 1) on it: ${p.contains(QV3.ints(1, 1, 1))}');
  print('(0, 0, 0) gives ${p.at(QV3.zero)}');
}
Output
(1, 1, 1) on it: true
(0, 0, 0) gives -3

Properties

nfield
final QV3 n
kfield
final Rational k

Methods

atmethod
Rational at(QV3 x)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final p = QPlane(QV3.ints(0, 0, 2), q(-2)); // 2z − 2 = 0
  for (final x in [QV3.ints(5, 5, 1), QV3(q(0), q(0), q(3, 2)), QV3.zero]) {
    print('at $x = ${exact(p.at(x))}');
  }
        {'label': 'at(0, 0, z)', 'points': [for (var i = -4; i <= 8; i++) [i / 4, p.at(QV3(q(0), q(0), q(i, 4))).toDouble()]]},
      ]})}');
}
Output
at (5, 5, 1) = 0
at (0, 0, 3/2) = 1
at (0, 0, 0) = −2
containsmethod
bool contains(QV3 x)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final f = PlaneFrame.tilted(q(1, 3), q(2));
  final plane = f.plane;
  print('frame point (1/2, 7) on the tilted plane: ${plane.contains(f.point(q(1, 2), q(7)))}');
  print('origin on it: ${plane.contains(QV3.zero)}');
}
Output
frame point (1/2, 7) on the tilted plane: true
origin on it: false
Rational? meetParameter(QV3 p, QV3 u)

Where the line p + \lambda u meets the plane (\lambda), or null when the line is parallel to it.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final p = QPlane(QV3.ints(0, 0, 1), q(-4)); // z = 4
  final from = QV3.ints(1, 1, 0), dir = QV3.ints(1, 2, 3);
  print('λ = ${exact(p.meetParameter(from, dir)!)}');
  print('parallel line: ${p.meetParameter(from, QV3.ints(1, 0, 0))}');
}
Output
λ = 4/3
parallel line: null
meetmethod
QV3? meet(QV3 p, QV3 u)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final p = QPlane(QV3.ints(0, 0, 1), q(-4));
  final x = p.meet(QV3.ints(1, 1, 0), QV3.ints(1, 2, 3))!;
  print('meet = $x, on the plane: ${p.contains(x)}');
        'segments': [[-1, 4, 4, 4], [1, 0, x.x.toDouble(), x.z.toDouble()]], 'points': [[1, 0, 'p'], [x.x.toDouble(), x.z.toDouble(), 'meet']]})}');
}
Output
meet = (7/3, 11/3, 4), on the plane: true
final class PlaneFrame

A plane in space with a frame: X = origin + u e_{1} + v e2.

PlaneFrame.tilted builds an orthonormal frame with rational vectors: the horizontal plane at height offset is tilted about the x-axis by the Cayley half-tangent tau, then turned about the z-axis by psi. Unit normals with rational coordinates are exactly what Cayley's parametrisation gives, so plane coordinates (u, v) measure true quadrances: Q = \Delta u^{2} + \Delta v^{2}.

Constructors

PlaneFrameconstructor
PlaneFrame(this.origin, this.e1, this.e2, {this.orthonormal = false})
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final f = PlaneFrame(QV3.ints(0, 0, 1), QV3.ints(1, 0, 0), QV3.ints(0, 1, 0), orthonormal: true);
  print('normal ${f.normal}, plane contains (5, −2, 1): ${f.plane.contains(QV3.ints(5, -2, 1))}');
  final p = f.point(q(3), q(-1, 2));
  print('point(3, −1/2) = $p, coordinates back: ${f.coordinates(p)}');
}
Output
normal (0, 0, 1), plane contains (5, −2, 1): true
point(3, −1/2) = (3, −1/2, 1), coordinates back: (3, -1/2)
factory PlaneFrame.tilted(Rational tau, Rational offset, {Rational? psi})
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final f = PlaneFrame.tilted(q(1, 2), q(1));
  print('origin ${f.origin}, e1 ${f.e1}, e2 ${f.e2}');
  print('unit and perpendicular: Q(e2) = ${f.e2.quadrance}, e1·e2 = ${f.e1.dot(f.e2)}, Q(n) = ${f.normal.quadrance}');
  final g = PlaneFrame.tilted(q(1, 2), q(1), psi: q(1, 3));
  print('turned by ψ = 1/3: e1 = ${g.e1}');
        'segments': [[f.origin.y.toDouble() - 2 * f.e2.y.toDouble(), f.origin.z.toDouble() - 2 * f.e2.z.toDouble(), f.origin.y.toDouble() + 2 * f.e2.y.toDouble(), f.origin.z.toDouble() + 2 * f.e2.z.toDouble()], [0, 0, f.origin.y.toDouble(), f.origin.z.toDouble()]],
        'points': [[0, 0, 'vertex'], [f.origin.y.toDouble(), f.origin.z.toDouble(), 'O']]})}');
}
Output
origin (0, −4/5, 3/5), e1 (1, 0, 0), e2 (0, 3/5, 4/5)
unit and perpendicular: Q(e2) = 1, e1·e2 = 0, Q(n) = 1
turned by ψ = 1/3: e1 = (4/5, 3/5, 0)

Properties

originfield
final QV3 origin
e1field
final QV3 e1
e2field
final QV3 e2
final bool orthonormal

E1, e2 and their normal are unit and perpendicular: plane coordinates are isometric.

normalgetter
QV3 get normal

The normal e_{1} \times e_{2} (a unit vector when orthonormal).

planegetter
QPlane get plane

Methods

pointmethod
QV3 point(Rational u, Rational v)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final f = PlaneFrame.tilted(q(1, 3), q(2));
  final a = f.point(q(0), q(0)), b = f.point(q(3), q(4));
  print('a = $a\nb = $b');
  // Isometric: the quadrance in space equals Δu² + Δv² = 25.
  print('Q(a, b) = ${quadrance(a, b)}');
}
Output
a = (0, −6/5, 8/5)
b = (3, 2, 4)
Q(a, b) = 25
QP2 coordinates(QV3 x)

The plane coordinates of a point of the plane (orthonormal frames).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final s = ConeSlice(q(3, 4), q(1, 4), q(1));
  final p = s.pointAt(q(1, 2))!;
  final (u, v) = s.frame.coordinates(p);
  print('space point $p → plane (${exact(u)}, ${exact(v)})');
  print('round trip: ${s.frame.point(u, v) == p}');
}
Output
space point (3/4, 1, 5/3) → plane (3/4, 5/3)
round trip: true
final class QuadricForm

A quadric surface as the symmetric 4 \times 4 matrix of [x, y, z, 1].

Constructors

QuadricFormconstructor
QuadricForm(this.form)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  // The unit sphere as a 4 × 4 form.
  final rows = [
    [q(1), q(0), q(0), q(0)],
    [q(0), q(1), q(0), q(0)],
    [q(0), q(0), q(1), q(0)],
    [q(0), q(0), q(0), q(-1)],
  ];
  final s = QuadricForm(SymForm(rows));
  print('(2/3, 2/3, 1/3) on the sphere: ${s.contains(QV3(q(2, 3), q(2, 3), q(1, 3)))}');
}
Output
(2/3, 2/3, 1/3) on the sphere: true
factory QuadricForm.diagonal(Rational a, Rational b, Rational c, Rational d)

The diagonal quadric a x^{2} + b y^{2} + c z^{2} + d = 0.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final e = QuadricForm.diagonal(q(1, 4), q(1, 9), q(1), q(-1)); // x²/4 + y²/9 + z² = 1
  print('(2, 0, 0): ${e.contains(QV3.ints(2, 0, 0))}, (0, 3, 0): ${e.contains(QV3.ints(0, 3, 0))}');
  print('value at the centre: ${e.value(QV3.zero)}');
}
Output
(2, 0, 0): true, (0, 3, 0): true
value at the centre: -1
factory QuadricForm.paraboloid(Rational a, Rational b)

A x^{2} + b y^{2} - z = 0 (the paraboloids).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final p = QuadricForm.paraboloid(q(1), q(-1)); // the saddle z = x² − y²
  print('(2, 1, 3) on the saddle: ${p.contains(QV3.ints(2, 1, 3))}');
  // The line (t, t, 0) lies on it entirely.
  print('contains the line through 0 along (1, 1, 0): ${p.containsLine(QV3.zero, QV3.ints(1, 1, 0))}');
        {'label': 'z(x, 0)', 'points': [for (var i = -8; i <= 8; i++) [i / 4, p.value(QV3(q(i, 4), q(0), q(0))).toDouble()]]},
        {'label': 'z(0, y)', 'points': [for (var i = -8; i <= 8; i++) [i / 4, p.value(QV3(q(0), q(i, 4), q(0))).toDouble()]]},
      ]})}');
}
Output
(2, 1, 3) on the saddle: true
contains the line through 0 along (1, 1, 0): true

Properties

formfield
final SymForm form

Methods

valuemethod
Rational value(QV3 x)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final s = QuadricForm.diagonal(q(1), q(1), q(1), q(-1));
  for (final x in [QV3.zero, QV3.ints(1, 0, 0), QV3.ints(1, 1, 1), QV3(q(1, 2), q(1, 2), q(1, 2))]) {
    print('f$x = ${exact(s.value(x))}');
  }
}
Output
f(0, 0, 0) = −1
f(1, 0, 0) = 0
f(1, 1, 1) = 2
f(1/2, 1/2, 1/2) = −1/4
containsmethod
bool contains(QV3 x)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final h = NamedQuadric(QuadricKind.hyperboloidOne, q(1), q(1), q(1)).form;
  print('(1, 0, 0): ${h.contains(QV3.ints(1, 0, 0))}');
  print('(3/5, 4/5, 0): ${h.contains(QV3(q(3, 5), q(4, 5), q(0)))}');
  print('(1, 1, 1): ${h.contains(QV3.ints(1, 1, 1))}');
  print('(0, 0, 0): ${h.contains(QV3.zero)}');
}
Output
(1, 0, 0): true
(3/5, 4/5, 0): true
(1, 1, 1): true
(0, 0, 0): false
QPlane polarPlane(QV3 p)

The polar plane of p (the tangent plane when p is on the surface): M [p, 1].

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final s = QuadricForm.diagonal(q(1), q(1), q(1), q(-1));
  final t = s.polarPlane(QV3(q(2, 3), q(2, 3), q(1, 3)));
  print('tangent plane at (2/3, 2/3, 1/3): n = ${t.n}, k = ${exact(t.k)}');
  final far = s.polarPlane(QV3.ints(0, 0, 2));
  print('polar of (0, 0, 2): n = ${far.n}, k = ${exact(far.k)}  (the plane z = 1/2)');
        'segments': [[-1.2, 0.5, 1.2, 0.5]], 'points': [[0, 2, 'pole']]})}');
}
Output
tangent plane at (2/3, 2/3, 1/3): n = (2/3, 2/3, 1/3), k = −1
polar of (0, 0, 2): n = (0, 0, 2), k = −1  (the plane z = 1/2)
bool containsLine(QV3 p, QV3 u)

The line p + \lambda u lies on the surface for every \lambda: f(p) = 0, B(p, u) = 0 and Q(u) = 0, three exact checks.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final h = NamedQuadric(QuadricKind.hyperboloidOne, q(1), q(1), q(1)).form;
  print('ruling (1,0,0) + λ(0,1,1): ${h.containsLine(QV3.ints(1, 0, 0), QV3.ints(0, 1, 1))}');
  print('other family (0,1,−1): ${h.containsLine(QV3.ints(1, 0, 0), QV3.ints(0, 1, -1))}');
  print('not a ruling (0,1,2): ${h.containsLine(QV3.ints(1, 0, 0), QV3.ints(0, 1, 2))}');
}
Output
ruling (1,0,0) + λ(0,1,1): true
other family (0,1,−1): true
not a ruling (0,1,2): false
QV3? secondMeet(QV3 p, QV3 u)

The second meet of the line through p (on the surface) in direction u: \lambda = -\frac{2B(p, u)}{Q(u)}, rational.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final s = QuadricForm.diagonal(q(1), q(1), q(1), q(-1));
  final north = QV3.ints(0, 0, 1);
  final x = s.secondMeet(north, QV3(q(1, 2), q(1, 3), q(-1)))!;
  print('from the north pole: $x, on the sphere: ${s.contains(x)}');
        'segments': [[0, 1, x.x.toDouble(), x.z.toDouble()]], 'points': [[0, 1, 'N'], [x.x.toDouble(), x.z.toDouble(), 'X']]})}');
}
Output
from the north pole: (36/49, 24/49, −23/49), on the sphere: true
slicemethod
ConicForm slice(PlaneFrame frame)

The conic in which the plane of frame cuts the surface, in the frame's coordinates (u, v): F^{T} M F with F's columns [e_{1}, 0], [e_{2}, 0], [origin, 1].

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final cone = QuadricForm.diagonal(q(1), q(1), q(-9, 16), q(0));
  for (final tau in [q(0), q(1, 4), q(1, 2), q(3, 4)]) {
    final c = cone.slice(PlaneFrame.tilted(tau, q(1)));
    print('τ = ${exact(tau).padRight(3)} ${c.kind.name.padRight(9)} $c');
  }
}
Output
τ = 0   circle    1x² + 0xy + 1y² + 0x + 0y + −9/16 = 0
τ = 1/4 ellipse   1x² + 0xy + 189/289y² + 0x + −375/289y + −1001/4624 = 0
τ = 1/2 parabola  1x² + 0xy + 0y² + 0x + −3/2y + 7/16 = 0
τ = 3/4 hyperbola 1x² + 0xy + −11/25y² + 0x + −21/25y + 351/400 = 0
final class ParabolicMirror

The dish z = \frac{x^{2} + y^{2}}{4f} with focus (0, 0, f).

Constructors

ParabolicMirrorconstructor
ParabolicMirror(this.focal)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final m = ParabolicMirror(q(1));
  print('focus ${m.focus}');
  print('all rays through the focus: ${[for (var k = -5; k <= 5; k++) m.throughFocus(m.hit(q(k, 2), q(1, 3)))].every((b) => b)}');
  // Cross-section y = 0: the dish, incoming rays and reflected rays to the focus.
  final dish = [for (var i = -12; i <= 12; i++) [i / 4, (i / 4) * (i / 4) / 4]];
  final rays = <List<double>>[];
  for (var k = -5; k <= 5; k += 2) {
    final h = m.hit(q(k, 2), q(0));
    rays.add([k / 2, 3, h.x.toDouble(), h.z.toDouble()]);
    rays.add([h.x.toDouble(), h.z.toDouble(), 0, 1]);
  }
        'polygons': [dish], 'segments': rays, 'points': [[0, 1, 'F']]})}');
}
Output
focus (0, 0, 1)
all rays through the focus: true

Properties

focalfield
final Rational focal
focusgetter
QV3 get focus

Methods

hitmethod
QV3 hit(Rational x, Rational y)

Where the ray straight down through (x, y) meets the dish.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final m = ParabolicMirror(q(1));
  print('hit(2, 0) = ${m.hit(q(2), q(0))}');
  print('hit(1/2, 1/3) = ${m.hit(q(1, 2), q(1, 3))}');
  // Cross-section y = 0: the dish, incoming rays and reflected rays to the focus.
  final dish = [for (var i = -12; i <= 12; i++) [i / 4, (i / 4) * (i / 4) / 4]];
  final rays = <List<double>>[];
  for (var k = -5; k <= 5; k += 2) {
    final h = m.hit(q(k, 2), q(0));
    rays.add([k / 2, 3, h.x.toDouble(), h.z.toDouble()]);
    rays.add([h.x.toDouble(), h.z.toDouble(), 0, 1]);
  }
        'polygons': [dish], 'segments': rays, 'points': [[0, 1, 'F']]})}');
}
Output
hit(2, 0) = (2, 0, 1)
hit(1/2, 1/3) = (1/2, 1/3, 13/144)
normalmethod
QV3 normal(QV3 p)

The surface normal there: \nabla(x^{2} + y^{2} - 4f z) = (2x, 2y, -4f).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final m = ParabolicMirror(q(1));
  final p = m.hit(q(2), q(0));
  final n = m.normal(p);
  print('normal at $p: $n');
        'polygons': [[for (var i = -12; i <= 12; i++) [i / 4, (i / 4) * (i / 4) / 4]]],
        'segments': [[2, 1, 2 - n.x.toDouble() / 4, 1 - n.z.toDouble() / 4]], 'points': [[2, 1, 'P']]})}');
}
Output
normal at (2, 0, 1): (4, 0, −4)
reflectmethod
QV3 reflect(QV3 p)

The reflected direction of a ray travelling (0, 0, -1).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final m = ParabolicMirror(q(1));
  for (final x in [q(1), q(2), q(4)]) {
    final p = m.hit(x, q(0));
    print('at $p the ray down reflects to ${m.reflect(p)}');
  }
}
Output
at (1, 0, 1/4) the ray down reflects to (−4/5, 0, 3/5)
at (2, 0, 1) the ray down reflects to (−1, 0, 0)
at (4, 0, 4) the ray down reflects to (−4/5, 0, −3/5)
bool throughFocus(QV3 p)

The reflected ray passes through the focus: (F - P) \times r = 0, exactly.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final m = ParabolicMirror(q(3, 2));
  var all = true;
  for (var a = -4; a <= 4; a++) {
    for (var b = -4; b <= 4; b++) {
      all &= m.throughFocus(m.hit(q(a, 3), q(b, 5)));
    }
  }
  print('81 rational rays, all through the focus exactly: $all');
}
Output
81 rational rays, all through the focus exactly: true
Rational focusParameter(QV3 p)

How far along r the ray reaches the focus (positive: it heads there).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final m = ParabolicMirror(q(1));
  for (final x in [q(1), q(2), q(6)]) {
    final p = m.hit(x, q(0));
    final t = m.focusParameter(p);
    print('from $p: λ = ${exact(t)}, P + λr = ${p + m.reflect(p).scale(t)}');
  }
}
Output
from (1, 0, 1/4): λ = 5/4, P + λr = (0, 0, 1)
from (2, 0, 1): λ = 2, P + λr = (0, 0, 1)
from (6, 0, 9): λ = 10, P + λr = (0, 0, 1)
final class ApolloniusQuadrangle

Apollonius' straightedge construction of the polar of pole from two lines through it (UHG 1 @14:32): the line through the pole and the conic's point \alpha meets the conic again at \gamma, the line through \beta again at \delta; the two other diagonal points of the quadrangle \alpha\beta\gamma\delta, E = \alpha\beta \cdot \gamma\delta and F = \alpha\delta \cdot \beta\gamma, lie on the polar M \cdot \mathrm{pole}. With \alpha, \beta and the pole rational every point is rational: \gamma and \delta are second meets (\lambda = -\frac{2B}{Q}, no root).

Static

ofstaticmethod
static ApolloniusQuadrangle? of(ConicForm conic, QP2 pole, QP2 alpha, QP2 beta)

Null when a line through the pole is tangent or the quadrangle collapses.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

List<double> segOf(QLine l, double lo, double hi) {
  final a = l.a.toDouble(), b = l.b.toDouble(), c = l.c.toDouble();
  if (b.abs() > 1e-12) return [lo, -(a * lo + c) / b, hi, -(a * hi + c) / b];
  return [-c / a, lo, -c / a, hi];
}

void main() {
  final c = ConicForm.coefficients(q(1), q(0), q(1), q(0), q(0), q(-1));
  final pole = (q(2), q(1));
  final a = ApolloniusQuadrangle.of(c, pole, (q(-1), q(0)), (q(0), q(-1)))!;
  print('γ = ${a.gamma}, δ = ${a.delta}');
  print('E = ${a.e}, F = ${a.f}');
  print('diagonal points on the polar: ${a.diagonalsOnPolar}, cross ratio ${a.crossRatioOnLine}');
  List<double> d(QP2 p) => [p.$1.toDouble(), p.$2.toDouble()];
  final pts = [a.alpha, a.beta, a.gamma, a.delta].map(d).toList();
        'segments': [segOf(a.polar, -1.5, 2.5), [2, 1, pts[0][0], pts[0][1]], [2, 1, pts[1][0], pts[1][1]],
          [pts[0][0], pts[0][1], pts[1][0], pts[1][1]], [pts[2][0], pts[2][1], pts[3][0], pts[3][1]]],
        'points': [[2, 1, 'pole'], [...pts[0], 'α'], [...pts[1], 'β'], [...pts[2], 'γ'], [...pts[3], 'δ'], if (a.e != null) [...d(a.e!), 'E']]})}');
}
Output
γ = (4/5, 3/5), δ = (1, 0)
E = (2, -3), F = (1/2, 0)
diagonal points on the polar: true, cross ratio -1

Properties

conicfield
final ConicForm conic
polefield
final QP2 pole
alphafield
final QP2 alpha
betafield
final QP2 beta
gammafield
final QP2 gamma
deltafield
final QP2 delta
efield
final QP2? e

The two diagonal points (null when the pair of sides is parallel: they meet at infinity, still on the polar).

ffield
final QP2? f

The two diagonal points (null when the pair of sides is parallel: they meet at infinity, still on the polar).

polargetter
QLine get polar
bool get diagonalsOnPolar

Both diagonal points lie on the polar, exactly (the polar independence theorem).

QP2? get harmonicPoint

Where the line pole–\alpha meets the polar.

Rational? get crossRatioOnLine

(pole, C; \alpha, \gamma) along the line through the pole and \alpha: -1 exactly.

final class SpacePolarity

The pole and polar of a quadric in space, with Apollonius' harmonic range on a line through the pole.

Constructors

SpacePolarityconstructor
SpacePolarity(this.quadric, this.pole)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final sphere = NamedQuadric(QuadricKind.ellipsoid, q(1), q(1), q(1));
  final sp = SpacePolarity(sphere, QV3.ints(0, 0, 2));
  print('polar plane: n = ${sp.plane.n}, k = ${exact(sp.plane.k)}');
  final cc = sp.contactCircle!;
  print('contact circle: centre ${cc.centre}, quadrance ${exact(cc.quadrance)}');
        'segments': [[0, 2, 0.866, 0.5], [0, 2, -0.866, 0.5], [-0.866, 0.5, 0.866, 0.5]], 'points': [[0, 2, 'pole']]})}');
}
Output
polar plane: n = (0, 0, 2), k = −1
contact circle: centre (0, 0, 1/2), quadrance 3/4

Properties

quadricfield
final NamedQuadric quadric
polefield
final QV3 pole
planegetter
QPlane get plane

The polar plane M·[pole, 1]: the plane of the contact conic of the tangent cone from the pole.

({QV3 centre, Rational quadrance})? get contactCircle

For an ellipsoid: in the scaled coordinates (\frac{x}{a}, \frac{y}{b}, \frac{z}{c}) it is the unit sphere, the pole P' has quadrance Q' = |P'|^{2}, the contact circle's centre is P'/Q' and its quadrance (squared radius) 1 - \frac{1}{Q'}, exact. Its radius is a root. Null when the pole is on or inside the surface (no tangent cone).

Methods

harmonicmethod
({QV3 gamma, QV3 c, Rational crossRatio})? harmonic(QV3 alpha)

The line from the pole through the surface's rational point alpha meets the surface again at \gamma and the polar plane at C: (pole, C; \alpha, \gamma) = -1, exactly. Null for a tangent line.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final sphere = NamedQuadric(QuadricKind.ellipsoid, q(1), q(1), q(1));
  final sp = SpacePolarity(sphere, QV3.ints(0, 0, 2));
  final alpha = QV3(q(2, 3), q(2, 3), q(1, 3));
  final h = sp.harmonic(alpha)!;
  print('γ = ${h.gamma}\nC = ${h.c}\n(P, C; α, γ) = ${exact(h.crossRatio)}');
}
Output
γ = (6/11, 6/11, 7/11)
C = (3/5, 3/5, 1/2)
(P, C; α, γ) = −1
enum QuadricKind

The real, non-degenerate quadric surfaces (and the cone, the degenerate one every conic comes from).

Values

ellipsoid
hyperboloidOne
hyperboloidTwo
ellipticParaboloid
hyperbolicParaboloid
conevalue
cone

Properties

ruledgetter
bool get ruled

Doubly ruled (two families of straight lines) or, for the cone, ruled by its generators.

equationgetter
String get equation

The equation, in plain notation.

final class NamedQuadric

A quadric of kind with rational semi-axes a, b, c.

Constructors

NamedQuadricconstructor
NamedQuadric(this.kind, this.a, this.b, this.c)
Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  for (final k in QuadricKind.values) {
    final s = NamedQuadric(k, q(1), q(2), q(3));
    print('${k.name.padRight(20)} ${k.equation.padRight(26)} ruled: ${k.ruled}');
    if (k == QuadricKind.ellipsoid) print('  (1, 0, 0) on it: ${s.form.contains(QV3.ints(1, 0, 0))}');
  }
}
Output
ellipsoid            x²/a² + y²/b² + z²/c² = 1  ruled: false
  (1, 0, 0) on it: true
hyperboloidOne       x²/a² + y²/b² − z²/c² = 1  ruled: true
hyperboloidTwo       x²/a² + y²/b² − z²/c² = −1 ruled: false
ellipticParaboloid   z = x²/a² + y²/b²          ruled: false
hyperbolicParaboloid z = x²/a² − y²/b²          ruled: true
cone                 x²/a² + y²/b² = z²/c²      ruled: true

Properties

kindfield
final QuadricKind kind
afield
final Rational a
bfield
final Rational b
cfield
final Rational c
formfield
late final QuadricForm form
basegetter
QV3 get base

The point every rational point is projected from (for the kinds parametrised by projection).

Methods

pointmethod
QV3? point(Rational u, Rational v)

The rational point of the parameters (u, v), exact. Ellipsoid and two sheets: the line from the base point (0, 0, c) towards (a u, b v, 0) meets the surface again at \lambda = -\frac{2B(N, D)}{Q(D)} (stereographic projection, no root). One sheet: the point v along the ruling of the waist point u. Paraboloids: the graph. Cone: v along generator u. Null where the line is tangent (a point at infinity).

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final e = NamedQuadric(QuadricKind.ellipsoid, q(2), q(1), q(1));
  for (final (u, v) in [(q(0), q(0)), (q(1), q(0)), (q(1, 2), q(1, 3))]) {
    final p = e.point(u, v)!;
    print('(${exact(u)}, ${exact(v)}) → $p  on it: ${e.form.contains(p)}');
  }
        'points': [for (var i = -6; i <= 6; i++) for (var j = -6; j <= 6; j++) (() { final p = e.point(q(i, 3), q(j, 3))!; return [p.x.toDouble(), p.y.toDouble()]; })()]})}');
}
Output
(0, 0) → (0, 0, −1)  on it: true
(1, 0) → (2, 0, 0)  on it: true
(1/2, 1/3) → (72/49, 24/49, −23/49)  on it: true
pointDmethod
(double, double, double)? pointD(double u, double v)

The same map in doubles ({+}\ {-}\ \times\ \div only), for drawing the rational mesh.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final h = NamedQuadric(QuadricKind.hyperboloidOne, q(1), q(1), q(1));
  final p = h.pointD(0.5, 1)!;
  print('pointD(0.5, 1) = (${p.$1}, ${p.$2}, ${p.$3})');
  print('residual ${hyperboloidResidual(1, 1, 1, p).abs() < 1e-12}');
  // A mesh of lines u = const seen from the side (x, z).
  final segs = <List<double>>[];
  for (var i = -4; i <= 4; i++) {
    final a = h.pointD(i / 4, -1.5)!, b = h.pointD(i / 4, 1.5)!;
    segs.add([a.$1, a.$3, b.$1, b.$3]);
  }
}
Output
pointD(0.5, 1) = (-0.2, 1.4, 1.0)
residual true
rulingmethod
QLine3 ruling(Rational t, int family)

The ruling of parameter t in family family (+1 or -1), exact. One sheet: through the waist point \frac{(a(1 - t^{2}), 2bt, 0)}{1 + t^{2}} in direction (−2at, b(1 - t^{2}), \pm c(1 + t^{2}))/(1 + t^{2}). Saddle: the lines \frac{x}{a} - \frac{y}{b} = t, t(\frac{x}{a} + \frac{y}{b}) = z (family +1) and \frac{x}{a} + \frac{y}{b} = t, t(\frac{x}{a} - \frac{y}{b}) = z (family -1). Cone: its generator. The other kinds contain no real line.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final h = NamedQuadric(QuadricKind.hyperboloidOne, q(1), q(1), q(1));
  final r = h.ruling(q(1, 2), 1);
  print('ruling t = 1/2: point ${r.point}, direction ${r.direction}');
  print('on the surface: ${h.form.containsLine(r.point, r.direction)}');
  final saddle = NamedQuadric(QuadricKind.hyperbolicParaboloid, q(1), q(1), q(1)).ruling(q(1), -1);
  print('saddle ruling: ${saddle.point} + λ${saddle.direction}');
}
Output
ruling t = 1/2: point (3/5, 4/5, 0), direction (−4/5, 3/5, 1)
on the surface: true
saddle ruling: (1/2, 1/2, 0) + λ(1/2, −1/2, 1)
rulingsmethod
List<(int, Rational, QLine3)> rulings({int den = 4, int range = 2})

Rulings for t = \frac{p}{den} (|t| ≤ range) in both families, each checked to lie on the surface exactly.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final h = NamedQuadric(QuadricKind.hyperboloidOne, q(1), q(1), q(2));
  final rs = h.rulings(den: 2, range: 2);
  print('${rs.length} rulings, all on the surface: ${rs.every((r) => h.form.containsLine(r.$3.point, r.$3.direction))}');
  print('ellipsoid has none: ${NamedQuadric(QuadricKind.ellipsoid, q(1), q(1), q(1)).rulings().length}');
  final segs = [
    for (final (fam, _, l) in rs)
      if (fam == 1)
        [for (final s in [-1, 1]) ...[(l.point.x + l.direction.x * q(s)).toDouble(), (l.point.y + l.direction.y * q(s)).toDouble()]],
  ];
}
Output
18 rulings, all on the surface: true
ellipsoid has none: 0
slicemethod
ConicForm slice(PlaneFrame frame)

The plane section by frame: a conic, its kind decided exactly.

Example
import 'package:riptide_conics/riptide_conics.ray';
import 'raya:convert';

void main() {
  final h = NamedQuadric(QuadricKind.hyperboloidOne, q(1), q(1), q(1));
  for (final (tau, d) in [(q(0), q(0)), (q(0), q(2)), (q(1), q(1, 2)), (q(1, 3), q(0))]) {
    final c = h.slice(PlaneFrame.tilted(tau, d));
    print('τ = ${exact(tau)}, offset ${exact(d)}: ${c.kind.name}');
  }
}
Output
τ = 0, offset 0: circle
τ = 0, offset 2: circle
τ = 1, offset 1/2: hyperbola
τ = 1/3, offset 0: ellipse