Last active
March 27, 2023 15:50
-
-
Save jairusjoer/b061dbfe704e1c7d10b9648dea8cfcd5 to your computer and use it in GitHub Desktop.
Create an array of globe coordinates based on a limited amounts of points.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const rasterGlobe = (limit = 1000, x1 = -180, y1 = -180) => { | |
type Coordinates = { x: number; y: number }; | |
let base = Math.pow(limit, 1 / 2); | |
let root = Math.floor(base); | |
let data: Array<Coordinates> = []; | |
const rasterLine = (x2: number) => { | |
for (let i = 0; i < root; i++) { | |
let y = y1 + ((y1 * -2) / (root - 1)) * i; | |
data.push({ x: x2, y: parseInt(y.toFixed(5)) }); | |
} | |
}; | |
for (let i = 0; i < root; i++) { | |
let x = x1 + ((x1 * -2) / (root - 1)) * i; | |
rasterLine(parseInt(x.toFixed(5))); | |
} | |
return data; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment