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
double cosh(double x)Cosh and sinh from exp.
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)]]},
]})}');
}cosh(0) = 1.0 cosh(1) = 1.543080634815 cosh² − sinh² at 0.7 = 1.000000000000
double sinh(double x)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)]]},
]})}');
}sinh(0) = 0.0 sinh(1) = 1.175201193644 odd: sinh(−2) = -3.626860408, −sinh(2) = -3.626860408
double distance((double, double, double) a, (double, double, double) b)The Euclidean distance \sqrt{\Delta x^{2} + \Delta y^{2} + \Delta z^{2}}.
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]]})}');
}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.
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)},
]})}');
}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).
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]);
}
}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).
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))]]},
]})}');
}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).
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)))}');
}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.
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]]})}');
}touches at (0.5000, 0.8660) touches at (0.5000, -0.8660) from inside (0.5, 0): []
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).
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))}');
}A(1, 4, 9) = 0 A(1, 1, 1) = 3 A(9, 16, 25) = 576, area² = 36
Rational q(int n, [int d = 1])The rational \frac{n}{d}.
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)}');
}q(3, 4) = 3/4 q(6, 8) reduces: 3/4 q(5) = 5 q(1, 3) + q(1, 6) = 1/2
String exact(Rational r)"−51/4" with a true minus sign.
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))}');
}toString: -51/4 exact: −51/4 exact(1/3 − 1/2) = −1/6
int bitsOf(Rational r)The cost of exactness: the bits of numerator and denominator together.
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;
}
}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
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.
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);
}3/4 ≈ 0.28785570 (95-bit fraction) true
BigInt integerRoot(BigInt n)The integer square root of n \ge 0 by Newton's method on integers (floor of the root).
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()]]},
]})}');
}⌊√99⌋ = 9 ⌊√100⌋ = 10 ⌊√(10^40 + 1)⌋ = 100000000000000000000
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.
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))}');
}√(9/16) = 3/4 √(169/25) = 13/5 √2 = null √(−4) = null
Rational quadrance(QV3 a, QV3 b)The quadrance between two points.
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))}');
}Q(a, b) = 25 Q(a, c) = 409/36
(double, double) dp(QP2 p)Points of the plane as doubles (drawing).
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)))}');
}exact (1/2, −3/4) -> doubles (0.5, -0.75) (0.3333333333333333, 0.6666666666666666)
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.
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), '')]));
}−10/9 x − 1/2 y − 1 x + 3/2 0
(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).
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)]);
}
}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
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).
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']]})}');
}(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.
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)))}');
}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).
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)))}');
}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.
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()]]})}');
}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
typedef QLine3 = ({QV3 point, QV3 direction})A straight line p + \lambda u on a surface.
Classes
ClassicKind
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
circleellipseparabolahyperbolapointlinelinePairClassicSlice
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
ClassicSlice(this.alpha, this.beta, this.offset)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]]},
]})}');
}β = 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).
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}');
}τ = 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
final double alphafinal double betafinal double offsetlate final double clate final double slate final double mlate final double bigClate final double bigElate final double bigFdouble get alphaDegreesdouble get betaDegreesClassicKind get kinddouble get r(double, double) get semiAxesSemi-axes (along u and along v) of an ellipse: \sqrt{R} and \sqrt{\frac{R}{C}}.
List<({double z, double radius, double touch, (double, double, double) focus})> get spheresThe 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
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).
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)]]},
]})}');
}ellipse: largest residual on 64 sampled points below 1e-12: true residual at the centre (0, v₀): -0.860119 (= −R)
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.
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]]});
}
}
}ellipse: 1 branch(es), 61 points each hyperbola: 2 branch(es), 60 points each
SliceKind
enum SliceKind
What the plane cuts from the cone.
Values
circleellipseparabolahyperbolapointDegenerate (the plane through the vertex): the vertex alone, one generator (the plane touches the cone), or two generators.
linelinePairProperties
bool get degenerateConeSlice
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
ConeSlice(this.mu, this.tau, this.offset)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()]]})}');
}τ = 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
final Rational offsetThe tilt's Cayley half-tangent and the plane's distance from the vertex.
late final PlaneFrame framelate final QuadricForm coneRational get spreadGeneratorThe spread between a generator and the axis: s_{\alpha} = \frac{\mu^{2}}{1 + \mu^{2}} (classically \sin^{2}\alpha).
Rational get spreadPlaneThe spread between the plane and the axis: s_{\beta} = c^{2} (classically \sin^{2}\beta).
Rational get eccentricitySquarede^{2} = \frac{1 - s_{\beta}}{1 - s_{\alpha}} = s^{2}(1 + \mu^{2}).
SliceKind get kindFromMatrixThe kind read from the section's matrix instead (det and the 2 \times 2 minor): it agrees with kind always (tested).
QV3 get generatorAtInfinity({Rational quarterDiscriminant, List<Rational?> rational}) get asymptoticParametersThe 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
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.
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]]})}');
}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
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.
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))}');
}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
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.
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)}');
}
}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.
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']]})}');
}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.
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()]]})}');
}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).
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()]]})}');
}from (17/20, 8/15): 25 new rational points all on the conic: true
DandelinSphere
final class DandelinSphere
One sphere inscribed in the cone and touching the plane.
Constructors
DandelinSphere({required this.centre, required this.radius, required this.focus, required this.touchHeight})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]]})}');
}centre (0, 0, 2), radius 6/5, touch height 32/25 z/(1 + μ²) = 32/25
Properties
final Rational touchHeightThe height of the circle where it touches the cone: z \cos^{2}\alpha = \frac{z}{1 + \mu^{2}}.
DandelinSpheres
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
static DandelinSpheres? of(ConeSlice slice)The spheres of slice, or null when the cone isn't Pythagorean or the plane passes through the vertex.
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']]})}');
}κ = 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
final ConeSlice slicefinal List<DandelinSphere> spheresTwo spheres (ellipse, hyperbola; one for a parabola, the other is at infinity). For a circle the two foci meet at the centre.
Rational get sinAlphaRational get cosAlphaRational? get focalConstantThe 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.
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)}');
}
}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.
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))}');
}
}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).
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]]})}');
}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.
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)!)}');
}
}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
QV3
final class QV3
A point or vector of three-dimensional space with rational coordinates.
Constructors
QV3(this.x, this.y, this.z)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}');
}v = (1/2, −3, 2/3) quadrance 349/36, as doubles (0.5, -3.0, 0.6666666666666666) homogeneous [1/2, -3, 2/3, 1]
factory QV3.ints(int x, int y, int z)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))}');
}v = (3, 4, 12), Q = 169 equal to QV3(q(3), q(4), q(12)): true
Static
static final QV3 zeroProperties
final Rational xfinal Rational yfinal Rational zRational get quadranceThe quadrance (squared length): Wildberger's replacement for distance.
bool get isZeroList<Rational> get directionThe homogeneous direction [x, y, z, 0] (a point at infinity).
int get hashCodeMethods
QV3 scale(Rational k)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)}');
}v·(1/2) = (1, −2, 3) v·(−3/4) = (−3/2, 3, −9/2) Q scales by k²: true
Rational dot(QV3 o)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))}');
}a·b = 1 perpendicular: (1, 1, 0)·(1, −1, 5) = 0 spread = 185/189
QV3 cross(QV3 o)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']]})}');
}x × y = (0, 0, 1) u × w = (2, −7/2, −6), perpendicular to both: true
String toString()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)}');
}(−1/2, 3, 0) (1, 2, 3)
Operators
QV3 operator +(QV3 o)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']]})}');
}a + b = (3, 5/2, 1)
QV3 operator -(QV3 o)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}');
}a − b = (3, 4, 0) quadrance(a, b) = Q(a − b) = 25
QV3 operator -()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}');
}−v = (−1/2, 2, −3) v + (−v) is zero: true
bool operator ==(Object other)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}');
}true false usable in sets: 1
QLine
final class QLine
The line a x + b y + c = 0 (homogeneous coordinates [a: b: c]).
Constructors
QLine(this.a, this.b, this.c)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)))}');
}line: x + 2 y − 4 = 0 (2, 1) on it: true
factory QLine.join(QP2 p, QP2 r)The line through two distinct points (the cross product of [x: y: 1]).
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)}');
}join of (1, 1) and (4, 3): −2 x + 3 y − 1 = 0 contains both: true
Properties
final Rational afinal Rational bfinal Rational cMethods
Rational at(QP2 p)A x + b y + c at p: zero exactly when p lies on the line.
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))}');
}
}at (4, 3) = 0 at (0, 1) = −4 at (1/3, 1/4) = 0
bool contains(QP2 p)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)))}');
}line −1/7 x + 1/3 y = 0 (1/3, 1/7): true (7, 3): true (3, 7): false
QP2? meet(QLine o)The meet of two lines, or null when they are parallel (they meet at infinity).
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']]})}');
}meet: (1, 1) parallel lines: null
String toString()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)));
}−10/9 x − 1/2 y − 1 = 0 x + 3/2 = 0
SymForm
final class SymForm
A symmetric n \times n matrix over Q: the quadratic form x^{T} M x on homogeneous coordinates.
Constructors
SymForm(List<List<Rational>> rows)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}');
}
}size 3, det 17/4, rank 3 rejected: not symmetric at (1, 0)
Properties
final List<List<Rational>> mint get sizeint get hashCodeMethods
List<Rational> apply(List<Rational> a)M a.
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(', ')})');
}M (1, −1/2) = (3/2, −1/2)
Rational bilinear(List<Rational> a, List<Rational> b)a^{T} M b (the polar, or bilinear, form).
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)}');
}aᵀ M b = 0 symmetric: true
Rational form(List<Rational> a)a^{T} M a.
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)])}');
}Q(3, 4, 5) = 0 Q(1, 1, 1) = 1
Operators
bool operator ==(Object other)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)]])}');
}a == b: true a == 2a: false
ConicKind
enum ConicKind
What a plane conic is, decided exactly from its matrix.
Values
circleellipseparabolahyperbolaProperties
bool get degenerateConicForm
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
ConicForm(this.form)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)}');
}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)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)},
]})}');
}x² + y² − 1 → circle x² − y − 1 → parabola xy − 1 → hyperbola x² − y² → linePair
Properties
final SymForm formRational get aRational get bRational get cRational get dRational get eRational get fRational get minorAC - \frac{B^{2}}{4}: positive for ellipses, zero for parabolas, negative for hyperbolas (-\tfrac{1}{4} of the discriminant B² − 4AC).
ConicKind get kindThe 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
Rational value(QP2 p)The value at p: zero exactly on the conic.
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()]]},
]})}');
}value at (3, 4) = 0 value at (0, 0) = −25 value at (6, 0) = 11
bool contains(QP2 p)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']]})}');
}(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
QLine polar(QP2 p)The polar of p (Apollonius; the tangent when p is on the conic): the line M [p, 1].
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']]})}');
}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).
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)]})}');
}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.
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']]})}');
}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).
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]]]})}');
}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)
bool isPoleOf(QP2 r, QLine line)Is the point r the pole of line: does M r equal the line up to a scalar?
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)}');
}(2, 1) is the pole of 4 x + 2 y − 2 = 0: true (1, 1) is its pole: false
String toString()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);
}1/4x² + 0xy + 1y² + −1x + 1/2y + −1 = 0 1x² + 0xy + 0y² + 0x + −3/2y + 7/16 = 0
QPlane
final class QPlane
The plane n \cdot X + k = 0 in space.
Constructors
QPlane(this.n, this.k)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)}');
}(1, 1, 1) on it: true (0, 0, 0) gives -3
Properties
final QV3 nfinal Rational kMethods
Rational at(QV3 x)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()]]},
]})}');
}at (5, 5, 1) = 0 at (0, 0, 3/2) = 1 at (0, 0, 0) = −2
bool contains(QV3 x)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)}');
}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.
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))}');
}λ = 4/3 parallel line: null
QV3? meet(QV3 p, QV3 u)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']]})}');
}meet = (7/3, 11/3, 4), on the plane: true
PlaneFrame
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
PlaneFrame(this.origin, this.e1, this.e2, {this.orthonormal = false})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)}');
}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})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']]})}');
}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
final QV3 originfinal QV3 e1final QV3 e2final bool orthonormalE1, e2 and their normal are unit and perpendicular: plane coordinates are isometric.
QPlane get planeMethods
QV3 point(Rational u, Rational v)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)}');
}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).
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}');
}space point (3/4, 1, 5/3) → plane (3/4, 5/3) round trip: true
QuadricForm
final class QuadricForm
A quadric surface as the symmetric 4 \times 4 matrix of [x, y, z, 1].
Constructors
QuadricForm(this.form)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)))}');
}(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.
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)}');
}(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).
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()]]},
]})}');
}(2, 1, 3) on the saddle: true contains the line through 0 along (1, 1, 0): true
Properties
final SymForm formMethods
Rational value(QV3 x)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))}');
}
}f(0, 0, 0) = −1 f(1, 0, 0) = 0 f(1, 1, 1) = 2 f(1/2, 1/2, 1/2) = −1/4
bool contains(QV3 x)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)}');
}(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].
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']]})}');
}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.
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))}');
}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.
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']]})}');
}from the north pole: (36/49, 24/49, −23/49), on the sphere: true
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].
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');
}
}τ = 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
ParabolicMirror
final class ParabolicMirror
The dish z = \frac{x^{2} + y^{2}}{4f} with focus (0, 0, f).
Constructors
ParabolicMirror(this.focal)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']]})}');
}focus (0, 0, 1) all rays through the focus: true
Properties
final Rational focalQV3 get focusMethods
QV3 hit(Rational x, Rational y)Where the ray straight down through (x, y) meets the dish.
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']]})}');
}hit(2, 0) = (2, 0, 1) hit(1/2, 1/3) = (1/2, 1/3, 13/144)
QV3 normal(QV3 p)The surface normal there: \nabla(x^{2} + y^{2} - 4f z) = (2x, 2y, -4f).
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']]})}');
}normal at (2, 0, 1): (4, 0, −4)
QV3 reflect(QV3 p)The reflected direction of a ray travelling (0, 0, -1).
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)}');
}
}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.
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');
}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).
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)}');
}
}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)
ApolloniusQuadrangle
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
static ApolloniusQuadrangle? of(ConicForm conic, QP2 pole, QP2 alpha, QP2 beta)Null when a line through the pole is tangent or the quadrangle collapses.
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']]})}');
}γ = (4/5, 3/5), δ = (1, 0) E = (2, -3), F = (1/2, 0) diagonal points on the polar: true, cross ratio -1
Properties
final ConicForm conicfinal QP2 polefinal QP2 alphafinal QP2 betafinal QP2 gammafinal QP2 deltafinal QP2? eThe two diagonal points (null when the pair of sides is parallel: they meet at infinity, still on the polar).
final QP2? fThe two diagonal points (null when the pair of sides is parallel: they meet at infinity, still on the polar).
QLine get polarbool get diagonalsOnPolarBoth diagonal points lie on the polar, exactly (the polar independence theorem).
Rational? get crossRatioOnLine(pole, C; \alpha, \gamma) along the line through the pole and \alpha: -1 exactly.
SpacePolarity
final class SpacePolarity
The pole and polar of a quadric in space, with Apollonius' harmonic range on a line through the pole.
Constructors
SpacePolarity(this.quadric, this.pole)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']]})}');
}polar plane: n = (0, 0, 2), k = −1 contact circle: centre (0, 0, 1/2), quadrance 3/4
Properties
final NamedQuadric quadricfinal QV3 poleQPlane get planeThe polar plane M·[pole, 1]: the plane of the contact conic of the tangent cone from the pole.
({QV3 centre, Rational quadrance})? get contactCircleFor 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
({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.
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)}');
}γ = (6/11, 6/11, 7/11) C = (3/5, 3/5, 1/2) (P, C; α, γ) = −1
QuadricKind
enum QuadricKind
The real, non-degenerate quadric surfaces (and the cone, the degenerate one every conic comes from).
Values
ellipsoidhyperboloidOnehyperboloidTwoellipticParaboloidhyperbolicParaboloidconeProperties
bool get ruledDoubly ruled (two families of straight lines) or, for the cone, ruled by its generators.
NamedQuadric
final class NamedQuadric
A quadric of kind with rational semi-axes a, b, c.
Constructors
NamedQuadric(this.kind, this.a, this.b, this.c)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))}');
}
}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
final QuadricKind kindfinal Rational afinal Rational bfinal Rational clate final QuadricForm formQV3 get baseThe point every rational point is projected from (for the kinds parametrised by projection).
Methods
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).
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()]; })()]})}');
}(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
(double, double, double)? pointD(double u, double v)The same map in doubles ({+}\ {-}\ \times\ \div only), for drawing the rational mesh.
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]);
}
}pointD(0.5, 1) = (-0.2, 1.4, 1.0) residual true
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.
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}');
}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)
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.
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()]],
];
}18 rulings, all on the surface: true ellipsoid has none: 0
ConicForm slice(PlaneFrame frame)The plane section by frame: a conic, its kind decided exactly.
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}');
}
}τ = 0, offset 0: circle τ = 0, offset 2: circle τ = 1, offset 1/2: hyperbola τ = 1/3, offset 0: ellipse