Drawing countries on top of a 3D sphere from set of boundaries
in
Programming Questions
•
2 years ago
Hello all,
I'm trying to draw countries on top of a 3D sphere. I've created the following classes (in bold): For each
Country, I have a list of
Landmasses. Each
Landmass has a set of
Coordinates (lat long) which define the landmasses border. So in 2D this is all fine, i map the coordinates to x,y points on my sketch based on some projection and i've got the result i want. However, the same approach doesn't work as well in 3D.
I have successfully converted the lat,long coordinates onto x, y, z using the following formulae
- x = radius * (float) Math.sin(latRad) * (float) Math.cos(lngRad);
- y = radius * (float) Math.sin(latRad) * (float) Math.sin(lngRad);
- z = radius * (float) Math.cos(latRad);
my draw() function for a landmass looks like:
- public void draw(PApplet p) {
- p.strokeWeight(1);
- p.stroke(107,177,209,255);
- p.beginShape();
- for (int i = 0; i < this.borders.length; i++) {
- Coordinate c = this.borders[i];
- p.vertex(c.x, c.y, c.z);
- }
- p.endShape(p.CLOSE);
- }
However, this method, while really intuitive, doesn't produce convex shapes. If i place these shapes on top of a sphere, small landmasses are drawn just fine. However, the surfaces of larger countries such as Russia or Canada are drawn with ridges and they cross the sphere they're drawn upon:
What i'd like to have is a method that given a set of boundary points, it would compute a mesh that follows the convex shape of a sphere. I've had a look at toxi's amazing toxic libs, but i haven't been able to use them successfully. Is this a 3D convex hull problem?
Cheers
1