1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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);
}
}
}
|