summaryrefslogtreecommitdiff
path: root/src/MapView.js
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-03-31 17:17:27 -0500
committersanine <sanine.not@pm.me>2023-03-31 17:17:27 -0500
commit673e9c13aea6cd1b11f5ca3e1f6edd474bbb1a19 (patch)
tree5764ff2cfd6b8dea3b615a1bb2f1dc1c078b07e7 /src/MapView.js
parent8aa6645f2311de78f74b35f804cc45c7fcf38f57 (diff)
implement nice map grid
Diffstat (limited to 'src/MapView.js')
-rw-r--r--src/MapView.js62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/MapView.js b/src/MapView.js
new file mode 100644
index 0000000..a08d6b7
--- /dev/null
+++ b/src/MapView.js
@@ -0,0 +1,62 @@
+import Canvas from './Canvas.js';
+import { Mat3, Vec3, Point, Shape } from './Geometry.js';
+
+
+const yAxis = new Vec3(0, 1, 0);
+const zAxis = new Vec3(0, 0, 1);
+
+
+function radians(degrees) {
+ return degrees * (Math.PI/180);
+}
+
+function Circle(p0, axis, subdiv) {
+ const rotationMatrix = new Mat3().rotation(axis, 2*Math.PI/(subdiv-1));
+ const points = [p0];
+ for (let i=0; i<subdiv-1; i++) {
+ const point = rotationMatrix.mulv(points[i]);
+ points.push(point);
+ }
+ return new Shape(points);
+}
+
+export class MapGrid {
+ constructor(latDiv, longDiv, circleDiv=50) {
+ // create latitudes
+ this.latitudes = [];
+ // equator
+ this.latitudes.push(Circle(
+ new Point(0, radians(0)).normal(), yAxis, circleDiv
+ ));
+ for (let angle=latDiv; angle<90; angle += latDiv) {
+ // positive (north)
+ this.latitudes.push(Circle(
+ new Point(0, radians(angle)).normal(), yAxis, circleDiv
+ ));
+ // negative (south)
+ this.latitudes.push(Circle(
+ new Point(0, radians(-angle)).normal(), yAxis, circleDiv
+ ));
+ }
+
+ // create longitudes
+ this.longitudes = [];
+ for (let angle=0; angle<180; angle += longDiv) {
+ console.log(angle);
+ const point = new Point(radians(angle), 0).normal();
+ const axis = point.cross(yAxis).normalize();
+ this.longitudes.push(Circle(
+ point, axis, circleDiv
+ ));
+ }
+ }
+
+ render(ct, view) {
+ for (let latitude of this.latitudes) {
+ latitude.render(ct, view);
+ }
+ for (let longitude of this.longitudes) {
+ longitude.render(ct, view);
+ }
+ }
+}