programdemos/manifold-tour/manifold-tour.xtl

Manifold tour: five spaces this repository's experiments live on, the circle, the sphere, the torus, the Swiss roll and the Poincare disk, each drawn from its map (its own coordinates) into the space around it, and on each one measurement of what a manifold is: two points near each other are nearly as far apart along the space as through it (locally flat), two points far apart are not; on the roll, near through the air can be far along the sheet; on the disk, near the rim a small step on paper is a long way. Nothing is trained.

source · imports mf: libs/Manifold/src/Manifold.xtl; tr: work/xetal-libraries/libs/Trig/src/Trig.xtl; ch: work/xetal-libraries/libs/Check/src/Check.xtl work/xetal-libraries/libs/Check/src/Check.xtlm

Pi : Float

value · line 15
Pi ← p̲i @

deg : Float

value · line 16
deg ← Pi ÷ 180.0

ᵘp̲airs : (Num a, Num b) => a -> b -> Float

function · line 21

a ᵘp̲airs b: a and b side by side, one (a, b) row per item (the rows of a map). A general pairing belongs in X_eTaL-libraries: a workaround here until it is asked for (docs/plan.md, G3b).

ᵘp̲airs ← { a b → o̲\ (2 c̲at t̲ally a) r̲eshape (f̲loat a) c̲at f̲loat b }

ᵘr̲ound : Int -> Float

function · line 24

ᵘr̲ound m: m + 1 angles evenly round a full turn, 0 to 2 pi, the first repeated last: a closed wire line.

ᵘr̲ound ← { m → (2.0 × Pi ÷ f̲loat m) × (f̲loat r̲ange m + 1) − 1.0 }

ᵘe̲ach : Int -> a -> a

function · line 26

n ᵘe̲ach v: every item of v repeated n times, in v's order.

ᵘe̲ach ← { n v → r̲avel o̲\ (n c̲at t̲ally v) r̲eshape v }

ᵘt̲imes : Int -> a -> a

function · line 28

n ᵘt̲imes v: v whole, n times over.

ᵘt̲imes ← { n v → r̲avel (n c̲at t̲ally v) r̲eshape v }

ᵘl̲ength : Float -> Float

function · line 31

ᵘl̲ength M: the length of the wire line through the rows of M, segment by segment (measured along the wire, not the curve).

ᵘl̲ength ← { M → '+ r̲/ s̲qrt '+ r̲/₂ ((1 d̲rop M) − -1 d̲rop M) ^ 2.0 }

ᵘs̲traight : (Num a, Num b) => a -> b -> Float

function · line 34

p ᵘs̲traight q: the straight-line distance, through whatever surrounds the space.

ᵘs̲traight ← { p q → s̲qrt '+ r̲/ ((f̲loat p) − f̲loat q) ^ 2.0 }

ᵘt̲wo : Num a => a -> Float

function · line 37

ᵘt̲wo M: for the two points (rows) of M on the sphere or the circle, the straight line through it and the distance along it.

ᵘt̲wo ← { M → ((1 s̲elect M) ᵘs̲traight 2 s̲elect M) c̲at (1 s̲elect M) ᵐᶠs̲phereDistance 2 s̲elect M }

ᵘl̲onLat : Num a => a -> Float

function · line 40

ᵘl̲onLat P: points of the sphere back onto its map, (longitude, latitude) in degrees: where a drawn arc runs on the flat view.

ᵘl̲onLat ← { P → (((2 s̲elect₂ P) ᵗʳa̲tan2 1 s̲elect₂ P) ᵘp̲airs ᵗʳa̲sin 3 s̲elect₂ P) ÷ deg }

The circle: one dimension, drawn in two

circleAngles : Float

value · line 44
circleAngles ← ᵘr̲ound 72
Used in: circle, dims

circle : Float

value · line 45
circle ← ᵐᶠc̲irclePoints circleAngles

circleNearA : Float

value · line 48

Two points a tenth of a radian apart, and two 2.5 radians apart: the chord through the disk and the arc along the circle, for each.

circleNearA ← 0.0 0.1
Used in: circleNear

circleFarA : Float

value · line 49
circleFarA ← 0.0 2.5
Used in: circleFar

circleNear : Float

value · line 50
circleNear ← ᵐᶠc̲irclePoints circleNearA

circleFar : Float

value · line 51
circleFar ← ᵐᶠc̲irclePoints circleFarA

circleNearD : Float

value · line 52
circleNearD ← ᵘt̲wo circleNear

circleFarD : Float

value · line 53
circleFarD ← ᵘt̲wo circleFar

The sphere: two dimensions, drawn in three

parallelLL : Float

value · line 60

The map's wire lines: five parallels (latitudes -60 to 60 degrees, 48 segments round) and twelve half meridians (every 30 degrees of longitude, pole to pole in 24 segments), as (longitude, latitude).

parallelLL ← (5 ᵘt̲imes ᵘr̲ound 48) ᵘp̲airs 49 ᵘe̲ach (30.0 × deg) × -2.0 -1.0 0.0 1.0 2.0
Used in: parallels, dims

meridianLL : Float

value · line 61
meridianLL ← (25 ᵘe̲ach (30.0 × deg) × (f̲loat r̲ange 12) − 1.0) ᵘp̲airs 12 ᵘt̲imes (7.5 × deg) × (f̲loat r̲ange 25) − 13.0
Used in: meridians

parallels : Float

value · line 62
parallels ← ᵐᶠs̲pherePoints parallelLL

meridians : Float

value · line 63
meridians ← ᵐᶠs̲pherePoints meridianLL

sphereDeg : Float

value · line 67

Three points by longitude and latitude in degrees: p, q near it (6 degrees east, 3 north), r far from it; the chord through the sphere and the great circle along it, p to q and p to r; the arcs.

sphereDeg ← 3 2 r̲eshape 20.0 30.0 26.0 33.0 110.0 -35.0

sphereLL : Float

value · line 68
sphereLL ← deg × sphereDeg
Used in: spherePts

spherePts : Float

value · line 69
spherePts ← ᵐᶠs̲pherePoints sphereLL

sphereNearD : Float

value · line 70
sphereNearD ← ᵘt̲wo 2 t̲ake spherePts

sphereFarD : Float

value · line 71
sphereFarD ← ᵘt̲wo (1 s̲elect spherePts) c̲at 3 s̲elect spherePts

sphereNearArc : Float

value · line 72
sphereNearArc ← (1 s̲elect spherePts, 2 s̲elect spherePts) ᵐᶠs̲phereArc 12

sphereFarArc : Float

value · line 73
sphereFarArc ← (1 s̲elect spherePts, 3 s̲elect spherePts) ᵐᶠs̲phereArc 48

sphereNearArcLL : Float

value · line 74
sphereNearArcLL ← ᵘl̲onLat sphereNearArc

sphereFarArcLL : Float

value · line 75
sphereFarArcLL ← ᵘl̲onLat sphereFarArc

workedDiff : Float

value · line 80

The chord from p to q worked in full: the differences coordinate by coordinate, their squares, the sum (the chord is its square root); and the length of p + q, from which the great circle is 2 atan2(|p - q|, |p + q|).

workedDiff ← (1 s̲elect spherePts) − 2 s̲elect spherePts

workedSq : Float

value · line 81
workedSq ← workedDiff ^ 2.0

workedSum : Float

value · line 82
workedSum ← '+ r̲/ workedSq

workedPlus : Float

value · line 83
workedPlus ← s̲qrt '+ r̲/ ((1 s̲elect spherePts) + 2 s̲elect spherePts) ^ 2.0

The torus: two dimensions, drawn in three, with a hole

radii : Float

value · line 87
radii ← 3.0 1.0

torusRingsUV : Float

value · line 90

Six rings round the hole (v every 60 degrees, 48 segments) and twelve round the tube (u every 30 degrees, 24 segments), as (u, v).

torusRingsUV ← (6 ᵘt̲imes ᵘr̲ound 48) ᵘp̲airs 49 ᵘe̲ach (60.0 × deg) × (f̲loat r̲ange 6) − 1.0
Used in: torusRings, dims

torusTubesUV : Float

value · line 91
torusTubesUV ← (25 ᵘe̲ach (30.0 × deg) × (f̲loat r̲ange 12) − 1.0) ᵘp̲airs 12 ᵘt̲imes ᵘr̲ound 24
Used in: torusTubes

torusRings : Float

value · line 92
torusRings ← radii ᵐᶠt̲orusPoints torusRingsUV

torusTubes : Float

value · line 93
torusTubes ← radii ᵐᶠt̲orusPoints torusTubesUV

torusRimLengths : Float

value · line 96

The outer ring (v = 0) and the inner ring (v = 180 degrees): the same line of the map, measured along the wire.

torusRimLengths ← (ᵘl̲ength 49 t̲ake torusRings) c̲at ᵘl̲ength 49 t̲ake 147 d̲rop torusRings

The Swiss roll: a flat sheet rolled up, in three dimensions

rollT : Float

value · line 104

The sheet: t from 1.5 pi to 4.5 pi (a turn and a half), h from -6 to 6. Five lines along the roll (60 segments) and thirteen across it (straight, 2 points), as (t, h); and the map they unroll to, (the length along the sheet, h).

rollT ← (1.5 × Pi) + (Pi ÷ 20.0) × (f̲loat r̲ange 61) − 1.0
Used in: rollAlongTH

rollAlongTH : Float

value · line 105
rollAlongTH ← (5 ᵘt̲imes rollT) ᵘp̲airs 61 ᵘe̲ach -6.0 -3.0 0.0 3.0 6.0

rollAcrossTH : Float

value · line 106
rollAcrossTH ← (2 ᵘe̲ach (1.5 × Pi) + (Pi ÷ 4.0) × (f̲loat r̲ange 13) − 1.0) ᵘp̲airs 13 ᵘt̲imes -6.0 6.0

rollAlong : Float

value · line 107
rollAlong ← ᵐᶠr̲ollPoints rollAlongTH

rollAcross : Float

value · line 108
rollAcross ← ᵐᶠr̲ollPoints rollAcrossTH

rollAlongMap : Float

value · line 109
rollAlongMap ← (ᵐᶠr̲ollAlong 1 s̲elect₂ rollAlongTH) ᵘp̲airs 2 s̲elect₂ rollAlongTH
Used in: dims

rollAcrossMap : Float

value · line 110
rollAcrossMap ← (ᵐᶠr̲ollAlong 1 s̲elect₂ rollAcrossTH) ᵘp̲airs 2 s̲elect₂ rollAcrossTH

rollTH : Float

value · line 114

Three points of the sheet: a, b a little farther round, c one full turn farther round at the same height, so that it sits right above a's turn: through the air and along the sheet, a to b and a to c.

rollTH ← 3 2 r̲eshape (5.2 0.0 5.5 0.0) c̲at (5.2 + 2.0 × Pi) c̲at 0.0

rollPts : Float

value · line 115
rollPts ← ᵐᶠr̲ollPoints rollTH

rollMap : Float

value · line 116
rollMap ← (ᵐᶠr̲ollAlong 1 s̲elect₂ rollTH) ᵘp̲airs 2 s̲elect₂ rollTH

rollNearD : Float

value · line 117
rollNearD ← ((1 s̲elect rollPts) ᵘs̲traight 2 s̲elect rollPts) c̲at (1 s̲elect rollTH) ᵐᶠr̲ollDistance 2 s̲elect rollTH

rollFarD : Float

value · line 118
rollFarD ← ((1 s̲elect rollPts) ᵘs̲traight 3 s̲elect rollPts) c̲at (1 s̲elect rollTH) ᵐᶠr̲ollDistance 3 s̲elect rollTH

The Poincare disk: two dimensions, flat on the page, with its own ruler

rim : Float

value · line 125

The rim (not part of the disk: points of the disk never reach it), and the disk's ruler laid along a diameter: the points 0, 1, 2, 3, 4 and 5 apart from the middle by the disk's distance.

rim ← ᵐᶠc̲irclePoints ᵘr̲ound 90
Used in: dims

ruler : Float

value · line 126
ruler ← (t̲anh (0.0 1.0 2.0 3.0 4.0 5.0) ÷ 2.0) ᵘp̲airs 6 r̲eshape 0.0

rulerD : Float

value · line 127
rulerD ← '{ k → 0.0 0.0 ᵐᶠb̲allDistance k s̲elect ruler } e̲ach r̲ange 6

diskFar : Float

value · line 131

Two points near the rim, 20 degrees apart round it (at the top, off the ruler), and the same two drawn in toward the middle: on paper and by the disk's distance, for each; and the geodesics between them.

diskFar ← 0.95 × ᵐᶠc̲irclePoints deg × 80.0 100.0

diskNear : Float

value · line 132
diskNear ← 0.1 × ᵐᶠc̲irclePoints deg × 80.0 100.0

diskFarD : Float

value · line 133
diskFarD ← ((1 s̲elect diskFar) ᵘs̲traight 2 s̲elect diskFar) c̲at (1 s̲elect diskFar) ᵐᶠb̲allDistance 2 s̲elect diskFar

diskNearD : Float

value · line 134
diskNearD ← ((1 s̲elect diskNear) ᵘs̲traight 2 s̲elect diskNear) c̲at (1 s̲elect diskNear) ᵐᶠb̲allDistance 2 s̲elect diskNear

diskFarGeo : Float

value · line 135
diskFarGeo ← (1 s̲elect diskFar, 2 s̲elect diskFar) ᵐᶠb̲allGeodesic 24

diskNearGeo : Float

value · line 136
diskNearGeo ← (1 s̲elect diskNear, 2 s̲elect diskNear) ᵐᶠb̲allGeodesic 24

geo1 : Float

value · line 138

Three more geodesics, to see their shape: a diameter, and two arcs.

geo1 ← (-0.9 0.0, 0.9 0.0) ᵐᶠb̲allGeodesic 24

geo2 : Float

value · line 139
geo2 ← (-0.5 0.6, 0.7 0.2) ᵐᶠb̲allGeodesic 24

geo3 : Float

value · line 140
geo3 ← (0.0 -0.9, 0.6 -0.6) ᵐᶠb̲allGeodesic 24

The dimensions

dims : Float

value · line 149

Each space's intrinsic dimension (how many coordinates its map has: the circle's map is a list of angles, the others' are pairs) and its ambient dimension (how many coordinates the space it is drawn in has), read off the arrays' shapes: one row per space, the circle, the sphere, the torus, the roll, the disk.

dims ← ((t̲ally s̲hape circleAngles) c̲at (2 s̲elect s̲hape parallelLL) c̲at (2 s̲elect s̲hape torusRingsUV) c̲at (2 s̲elect s̲hape rollAlongMap) c̲at 2 s̲elect s̲hape rim) ᵘp̲airs (2 s̲elect s̲hape circle) c̲at (2 s̲elect s̲hape parallels) c̲at (2 s̲elect s̲hape torusRings) c̲at (2 s̲elect s̲hape rollAlong) c̲at 2 s̲elect s̲hape rim