Torus colatitude formula documentation - Freeciv Ticket #43665 on OSDNhttps://osdn.net/projects/freeciv/ticket/43665The map_colatitude() function in server/generator/mapgen_topology.c contains a formula for torus topologies (permalink) documented only with the comment
/* This projection makes poles with a shape of a quarter-circle along * "P" and the equator as a straight line along "/". * * This is explained more fully in RT 8624; the discussion can be found at * http://thread.gmane.org/gmane.games.freeciv.devel/42648 */ return MAX_COLATITUDE * (1.5 * (x * x * y + x * y * y) - 0.5 * (x * x * x + y * y * y) + 1.5 * (x * x + y * y));Since the referenced bug tracker is long dead (and not in the Wayback Machine), the Gmane link out of date (and the HTTP frontend doesn't seem to exist anymore), and – as far as I can discern – there's no actual explanation of the formula in what's left of the original discussion (at least none that I could find), this comment needs an update. For the sake of future-proofing, it would probably be prudent to put the explanation directly into a comment next to the formula this time (or at least somewhere within the repository itself).
I was able to reverse engineer the formula (with a bit of luck and a lot of trial and error):
The formula is lerp(1.5 (x2 + y2), (x+y)2, (x+y)), where lerp(a,b,t) = a * (1-t) + b * t is the linear interpolation function.
The first interpoland is 1.5 times the squared pythagorean distance from the pole
This gives circular lines of latitude
I don't know where the factor of 1.5 comes from / what it's for – I'm assuming it's compensating for something
The second interpoland is the squared manhattan distance from the pole
This gives straight lines of latitude parallel to the equator
The interpolation factor is the manhattan distance from the pole
This goes from 0 at the pole, where the pythagorean distance wins out and we get a circular polar region...
...to 1 at the equator, where the manhattan distance wins out and we get straight tropics
The colatitude grows with the square of the distance to the poles (rather than linearly, as it does for other topologies)
The area within a certain distance of a pole also grows with the square of that distance (on torus maps), so the colatitude grows with the area
This keeps areas within a given range of colatitudes (i.e. with a given climate) relatively consistent with non-torus maps, where both colatitude and area grow linearly with distance to the pole
This leaves open two questions:
Do we know where exactly the formula, in particular the factor 1.5, comes from? The only thing I found in the original discussion was a text document in a weird encoding that looked promising, but didn't lead anywhere.
Where should we best put this documentation? I'm gravitating toward "comment in the code right next to the formula".
Fri, 21 Jan 2022 00:18:48 +0900Tue, 01 Feb 2022 12:17:14 +09002022-01-21 00:18 Aktualisiert von: alienvalkyriehttps://osdn.net/projects/freeciv/ticket/43665#12505:43665:1642691928<ul class="changes"><li>New Ticket "Torus colatitude formula documentation" created</li></ul>https://osdn.net/projects/freeciv/ticket/43665#12505:43665:1642691928Fri, 21 Jan 2022 00:18:48 +09002022-01-21 00:22 Aktualisiert von: alienvalkyriehttps://osdn.net/projects/freeciv/ticket/43665#12505:43665:1642692172<ul class="changes"><li>File <em>0001-Comment-fix-Explain-torus-topology-colatitude-formul.patch (File ID: 8373)</em> is attached</li></ul>https://osdn.net/projects/freeciv/ticket/43665#12505:43665:1642692172Fri, 21 Jan 2022 00:22:52 +09002022-01-30 19:02 Aktualisiert von: alienvalkyriehttps://osdn.net/projects/freeciv/ticket/43665#12505:43665:1643536944<ul class="changes"><li><strong>Lösung</strong> Update from <em>Keine</em> to <em>Gefixt</em></li></ul>https://osdn.net/projects/freeciv/ticket/43665#12505:43665:1643536944Sun, 30 Jan 2022 19:02:24 +09002022-01-30 20:03 Aktualisiert von: cazfihttps://osdn.net/projects/freeciv/ticket/43665#12505:43665:1643540635<ul class="changes"><li><strong>Meilenstein</strong> Update from <em>(Keine)</em> to <em><a href="/projects/freeciv/ticket/milestone/2680">3.0.0 (closed)</a></em></li><li><strong>Lösung</strong> Update from <em>Gefixt</em> to <em>Accepted</em></li></ul><div class="sfjp-comment"><h4>Kommentar</h4><div class="body"><div class="wiki-compact"><p>It's a comment-only change, so there's no real reason not to accept it even during S3_0 code freeze, especially before RC1.
</p><p>(Given the available Resolution values in osdn, we use "Accepted" to mark that the review period begins)</p></div></div><div class="footer"></div></div>
https://osdn.net/projects/freeciv/ticket/43665#12505:43665:1643540635Sun, 30 Jan 2022 20:03:55 +09002022-02-01 12:17 Aktualisiert von: cazfihttps://osdn.net/projects/freeciv/ticket/43665#12505:43665:1643685434<ul class="changes"><li><strong>Status</strong> Update from <em>Offen</em> to <em>Geschlossen</em></li><li><strong>Lösung</strong> Update from <em>Accepted</em> to <em>Gefixt</em></li><li><strong>Verantwortlicher</strong> Update from <em>(Keine)</em> to <em>cazfi</em></li></ul>https://osdn.net/projects/freeciv/ticket/43665#12505:43665:1643685434Tue, 01 Feb 2022 12:17:14 +0900