xxxxxxxxxx
47
class Circ {
constructor(lon, lat, r) {
this.lon = lon;
this.lat = lat;
this.pos = this.lonlat2pos(lon, lat);
this.r = r;
}
lonlat2pos(lon, lat) {
return (new createVector(width / (2 * PI) * (PI + this.lon), height / (PI) * (this.lat)))
}
update() {
this.pos = this.lonlat2pos(this.lon, this.lat);
}
show(mode) {
if (mode == 1) {
const dtheta = 0.01;
stroke(255);
strokeWeight(2);
for (let theta = 0; theta <= 2 * PI; theta += dtheta) {
for (let xi = -1; xi <= 1; xi++) {
for (let yi = 0; yi <= 0; yi++) {
line(this.pos.x + this.r * cos(theta) + xi * width,
this.pos.y + this.r * sin(theta) + yi * height,
this.pos.x + this.r * cos(theta - dtheta) + xi * width,
this.pos.y + this.r * sin(theta - dtheta) + yi * height);
}
}
}
}
}
move(dlon, dlat) {
this.lon = (this.lon + dlon + 2 * PI) % (2 * PI);
if (this.lat + dlat > PI) {
this.lat = 2 * PI - dlat - this.lat;
this.lon = (PI+this.lon)%(2*PI);
} else if (this.lat + dlat < 0) {
this.lat = - this.lat - dlat;
this.lon = (PI+this.lon)%(2*PI);
} else {
this.lat = this.lat + dlat;
}
}
}