Skip to content

Instantly share code, notes, and snippets.

@jairusjoer
Last active March 27, 2023 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jairusjoer/b061dbfe704e1c7d10b9648dea8cfcd5 to your computer and use it in GitHub Desktop.
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.
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