From 29ead774a8fca624728e16bf5cd6b84a78d75989 Mon Sep 17 00:00:00 2001 From: Nohus Date: Wed, 29 Jan 2025 21:04:59 +0000 Subject: [PATCH] Improved warp-in formulas on the Useful Formulate page - Grouped warp-in formulas in it's own section - Added the formula for warp-in points of suns - Added Kotlin implementations of large object, sun, and planet warp-in point formulas - Corrected information on which types are using the large object warp-in formula - Updated and added more information to the planet warp-in formula explanation --- docs/guides/useful-formulae.md | 45 +++++++++++++++---- scripts/generate-snippets.py | 2 + snippets/formulae/large-object-warp-in.kt | 8 ++++ snippets/formulae/planet-warp-in.kt | 10 +++++ .../{warp-in.py => planet-warp-in.py} | 0 snippets/formulae/sun-warp-in.kt | 8 ++++ 6 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 snippets/formulae/large-object-warp-in.kt create mode 100644 snippets/formulae/planet-warp-in.kt rename snippets/formulae/{warp-in.py => planet-warp-in.py} (100%) create mode 100644 snippets/formulae/sun-warp-in.kt diff --git a/docs/guides/useful-formulae.md b/docs/guides/useful-formulae.md index 4cba6ca..9b34b59 100644 --- a/docs/guides/useful-formulae.md +++ b/docs/guides/useful-formulae.md @@ -1,30 +1,50 @@ # Useful Formulae -## Ordinary Objects +## Warp-in points + +### Ordinary Objects An ordinary object is any object that does not fall withing any of the other categories described below. Let the 3D vectors $p_d$ and $p_s$ represent the object’s position and the warp’s origin, respectively; and $\vec{v}$ the directional vector from $p_s$ to $p_d$. Let $r$ be the object’s radius. The object’s warp-in point is the vector $p_s + \vec{v} - r\hat{v}$. -## Large Objects -A large object is any celestial body whose radius exceeds 90 kilometres (180 kilometres in diameter), except planets. +In other words, the warping ship arrives at a point between the starting position and the targets' position, at the edge of the targets' radius. + +### Large Objects +A large object is any Celestial (type category 2) with a radius of at least 90 kilometres (180 kilometres in diameter), except wrecks, planets, and suns. Let $x$, $y$, and $z$ represent the object’s coordinates. Let $r$ be the object’s radius. The object’s warp-in point is the vector $\left(x + (r + 5000000)\cos{r} \\, y + 1.3r - 7500 \\, z - (r + 5000000)\sin{r} \\ \right).$ -## Planets +

Example

+ +--8<-- "snippets/formulae/large-object-warp-in.md" + +### Suns + +The warp-in point of a sun is determined by its radius. + +Let $r$ be the sun's radius. + +The sun’s warp-in point is the vector $\left((r + 100000)\cos{r} \\, 0.2r \\, -(r + 100000)\sin{r} \\ \right).$ + +

Example

+ +--8<-- "snippets/formulae/sun-warp-in.md" + +### Planets The warp-in point of a planet is determined by the planet's ID, its location, and radius. -Let $x$, $y$, and $z$ represent the planet's coordinates. Let $r$ be the planet's radius. +Let $x$, $y$, and $z$ represent the planet's coordinates. Let $r$ be the planet's radius, and $p$ be the planet's ID. The planet's warp-in point is the vector $\left(x + d \sin{\theta}, y + \frac{1}{2} r \sin{j}, z - d \cos{\theta}\right)$ where: $$ -d = r(s + 1) + 1000000 +d = r(s + 1) + 10^6 $$ $$ @@ -35,11 +55,20 @@ $$ s|_{0.5 \leq s \leq 10.5} = 20\left(\frac{1}{40}\left(10\log_{10}\left(\frac{r}{10^6}\right) - 39\right)\right)^{20} + \frac{1}{2} $$ -Now, $j$ is a special snowflake. Its value is the Python equivalent of `(random.Random(planetID).random() - 1.0) / 3.0`. +$$ +j = \frac{mt(p) - 1}{3} +$$ + +The function $mt(p)$ represents the first floating point number in range $[0,1)$ generated by a +[Mersenne Twister](https://en.wikipedia.org/wiki/Mersenne_Twister) PRNG seeded with the planet's ID. + +In Python, this is equivalent to `random.Random(p).random()`. Implementations of Mersenne Twisters are widely available +for popular languages, but you need to be careful to match Python's, as not all implementations use the provided seed in +the same way.

Example

---8<-- "snippets/formulae/warp-in.md" +--8<-- "snippets/formulae/planet-warp-in.md" ## Skillpoints needed per level diff --git a/scripts/generate-snippets.py b/scripts/generate-snippets.py index 9d18b19..a3ffb1a 100644 --- a/scripts/generate-snippets.py +++ b/scripts/generate-snippets.py @@ -12,6 +12,7 @@ EXTENSION_MAPPING = { ".py": "Python", ".cs": "C#", + ".kt": "Kotlin", } # The mapping of file extensions to syntax highlighting names. The key is the file @@ -19,6 +20,7 @@ SYNTAX_MAPPING = { ".py": "python", ".cs": "csharp", + ".kt": "kotlin", } # The file extension for the combined markdown file. diff --git a/snippets/formulae/large-object-warp-in.kt b/snippets/formulae/large-object-warp-in.kt new file mode 100644 index 0000000..21d8ce5 --- /dev/null +++ b/snippets/formulae/large-object-warp-in.kt @@ -0,0 +1,8 @@ +import kotlin.math.* + +fun getLargeObjectWarpInPoint(x: Double, y: Double, z: Double, radius: Double): Triple { + val x = (radius + 5000000) * cos(radius) + val y = 1.3 * radius - 7500 + val z = -(radius + 5000000) * sin(radius) + return Triple(x, y, z) +} diff --git a/snippets/formulae/planet-warp-in.kt b/snippets/formulae/planet-warp-in.kt new file mode 100644 index 0000000..7b3ff11 --- /dev/null +++ b/snippets/formulae/planet-warp-in.kt @@ -0,0 +1,10 @@ +import org.apache.commons.math3.random.MersenneTwister +import kotlin.math.* + +fun getPlanetWarpInPoint(planetId: Int, x: Double, y: Double, z: Double, radius: Double): Triple { + val j = (MersenneTwister(intArrayOf(planetId)).nextDouble() - 1) / 3 + val theta = asin((x / abs(x)) * (z / (sqrt(x.pow(2) + z.pow(2))))) + j + val s = (20 * ((10 * log10(radius / 1000000) - 39) / 40).pow(20) + 0.5).coerceIn(0.5, 10.5) + val d = radius * (s + 1) + 1000000 + return Triple(x + sin(theta) * d, y + radius * sin(j) / 2, z - cos(theta) * d) +} diff --git a/snippets/formulae/warp-in.py b/snippets/formulae/planet-warp-in.py similarity index 100% rename from snippets/formulae/warp-in.py rename to snippets/formulae/planet-warp-in.py diff --git a/snippets/formulae/sun-warp-in.kt b/snippets/formulae/sun-warp-in.kt new file mode 100644 index 0000000..7658da6 --- /dev/null +++ b/snippets/formulae/sun-warp-in.kt @@ -0,0 +1,8 @@ +import kotlin.math.* + +fun getSunWarpInPoint(radius: Double): Triple { + val x = (radius + 100000) * cos(radius) + val y = 0.2 * radius + val z = -(radius + 100000) * sin(radius) + return Triple(x, y, z) +}