We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I realize that seems like well-travelled path (and it is in most respects) but I'm trying to do the classic "place points on a globe based on lat/long". The difference between the more traditional approach using a sphere with a texture map, is that I want something with printable geometry at the end of it, so I've turned to Hemesh. I want to find a face on a globe that corresponds to a globe and extrude it and I want the globe to have meaningful land/ocean geometry. So far I've got a globe but I can't seem to figure out any reliable way to find faces that would correspond to a lat/long on that globe. So far I've got the following:
You can see the mesh has the continents, which is what I want, but I can't reliably determine the starting orientation or position of the mesh, which makes it (or I think makes it) really hard to figure out where any points might be.
This is the code I'm scribbled up:
import peasy.test.*;
import peasy.org.apache.commons.math.*;
import peasy.*;
import peasy.org.apache.commons.math.geometry.*;
import wblut.math.*;
import wblut.processing.*;
import wblut.core.*;
import wblut.hemesh.*;
import wblut.geom.*;
HE_Mesh mesh;
WB_Render render;
float currentLatitude = 52.524268;
float currentLongitude = 13.40629;
float EARTH_RADIUS = 300.0;
PeasyCam cam;
SphericalCoordinate place;
void setup() {
size(800, 800, P3D);
cam = new PeasyCam(this, 600);
HEC_FromOBJFile c = new HEC_FromOBJFile("/Users/jnoble/Desktop/Globe_Cleaned_Mirrored_NoPole.obj");
mesh = new HE_Mesh(c);
mesh.scale(1000);
render=new WB_Render(this);
place = new SphericalCoordinate(currentLatitude, currentLongitude, 1000);
PVector pos = place.getCartesianPos();
WB_Point pt = new WB_Point( pos.x, pos.y, pos.z );
pt.add(mesh.getCenter());
println(pt);
double minDist = 100000.0;
HE_Face closest;
for ( HE_Face f : mesh.getFacesAsList () ) {
//if(f.getLabel() == #ff0000 ) {
WB_Point n = f.getFaceCenter();
if( n.getDistance3D( pt ) < minDist ) {
//closest = f;
f.setLabel( #ff0000 );
minDist = n.getDistance3D( pt );
}
}
}
void draw() {
background(255);
lights();
stroke(0);
render.drawEdges(mesh);
noStroke();
for ( HE_Face f : mesh.getFacesAsList () ) {
noStroke();
fill( f.getLabel() );
render.drawFace( f );
}
stroke(255,0,0);
render.drawBoundaryEdges(mesh);
}
I think I'm thinking about this all wrong though. I'm sort of roughly familiar with hemesh and only now really starting to dive in, is there something simple and amazing I'm missing or a far better approach that someone knows of?
Answers
Hi Joshua,
easiest way I can see, is to create a ray from the center through the lat/lon point and get the face where it intersects. I'll cook up some code to show you how.
Cheers,
F.
Thanks so much Frederik!