diff options
Diffstat (limited to 'src/MapView.js')
-rw-r--r-- | src/MapView.js | 62 |
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); + } + } +} |