We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › map coordinates to a sphere
Page Index Toggle Pages: 1
map coordinates to a sphere (Read 2201 times)
map coordinates to a sphere
May 25th, 2005, 8:20pm
 
hello processing - people!

we're planning to do the following:

we have a set of world-coordinates like

W 32" 12'; N 12" 43'
W 132" 12'; N 24" 85'

and so on..

we want to map those coordinate to a sphere displaying the world map as a texture.

since our project is running on the java platform processing.org seems to be the right tool.

does anyone of you know if something like this is possible with processing.org?

thanks & best regards,

robin
Re: map coordinates to a sphere
Reply #1 - Jun 13th, 2005, 3:45pm
 
You need to map a point (u,v), your latitude and longitude to a sphere point (x,y,z). Decide on a relatively close estimate for the earth's circumference, say r = 6378km at the equator. The longitude angle is given by Theta = 2*pi*u. The latitude angle is given by Phi = pi*(v-0.5). If you are starting with latitude and longitude the points (x,y,z) on the sphere can be calculated by: x = r*sin(theta)cos(phi)  y = r*sin(phi) and z = r*cos(theta)cos(phi)

Simply iterate through your longitude and latitude coordinates and plot the 3d points (x,y,z).

Good luck

Rob
Re: map coordinates to a sphere
Reply #2 - Jun 13th, 2005, 3:47pm
 
BTW, the radius is arbitrary. If you are doing a 1:1 model my value for r is good, but you can just make it a unit sphere, r=1, if you simply want to plot the points relative to eachother.

Rob
Re: map coordinates to a sphere
Reply #3 - Aug 9th, 2005, 7:40am
 
Hi, Im trying to do something very similar, which is simply map a texture to a sphere. I dont see a way to do this easily with any 'built in'/'free' spherical mapping solution, so I am trying to port this code ( http://www.codeguru.com/Cpp/G-M/opengl/texturemapping/article.php/c5589/#more ) to processing. I am able to draw my sphere just fine, but I am missing a few peices, namely the author of the original code calls :

Code:

NormalVector(u,v,w,n);
glNormal3dv(n);

which I am assuming makes a normal vector from the 3 coordinate vectors u,v,w, and then runs glNormal3d(n) on the vector, before drawing the textures.

What can I do in processing that mimics this?

here is my altered code, for what its worth. Any help is appreciated!

Code:

//
// code ported from http://www.codeguru.com/Cpp/G-M/opengl/texturemapping/article.php/c5589/
//

float PI = 3.14159265359;
float TWOPI = 6.28318530718;
float DE2RA = 0.01745329252;
float RA2DE = 57.2957795129;
float FLATTENING = 1.0/298.26;
float PIOVER2 = 1.570796326795;


void sphereWithTexture(PImage texture, int detail, float radius)
{
beginShape(TRIANGLES);
texture(texture);
fill(200,200,200,100);
int NumLatitudes = detail;
int NumLongitudes = detail;

float start_lat = -90;
float start_lon = 0.0;
float R = radius;

float lat_incr = 180.0 / NumLatitudes;
float lon_incr = 360.0 / NumLongitudes;

int row, col;

for (col = 0; col < NumLongitudes; col++)
{
float phi1 = (start_lon + col * lon_incr) * DE2RA;
float phi2 = (start_lon + (col + 1) * lon_incr) * DE2RA;
for (row = 0; row < NumLatitudes; row++)
{
float theta1 = (start_lat + row * lat_incr) * DE2RA;
float theta2 = (start_lat + (row + 1) * lat_incr) * DE2RA;

float[] u = new float[3];
u[0] = R * cos(phi1) * cos(theta1); //x
u[1] = R * sin(theta1); //y
u[2] = R * sin(phi1) * cos(theta1); //z

float[] v = new float[3];
v[0] = R * cos(phi1) * cos(theta2); //x
v[1] = R * sin(theta2); //y
v[2] = R * sin(phi1) * cos(theta2); //z

float[] w = new float[3];
w[0] = R * cos(phi2) * cos(theta2); //x
w[1] = R * sin(theta2); //y
w[2] = R * sin(phi2) * cos(theta2); //z

// normal(u,v,w); // yeah, that totally doesnt work...
vertex(u[0],u[1],u[2], (180.0 - phi1*RA2DE)/360.0, (theta1 + PIOVER2)*RA2DE/180.0);
vertex(v[0],v[1],v[2], (180.0 - phi1*RA2DE)/360.0, (theta2 + PIOVER2)*RA2DE/180.0);
vertex(w[0],w[1],w[2], (180.0 - phi2*RA2DE)/360.0, (theta2 + PIOVER2)*RA2DE/180.0);

v[0] = R * cos(phi2) * cos(theta1); //x
v[1] = R * sin(theta1); //y
v[2] = R * sin(phi2) * cos(theta1); //z

//normal(u,v,w);
vertex(u[0],u[1],u[2], (180.0 - phi1*RA2DE)/360.0, (theta1 + PIOVER2)*RA2DE/180.0);
vertex(v[0],v[1],v[2], (180.0 - phi1*RA2DE)/360.0, (theta2 + PIOVER2)*RA2DE/180.0);
vertex(w[0],w[1],w[2], (180.0 - phi2*RA2DE)/360.0, (theta1 + PIOVER2)*RA2DE/180.0);

} // end NumLatitudes for loop
} // end NumLongitudes for loop
endShape();
}
Re: map coordinates to a sphere
Reply #4 - Aug 9th, 2005, 5:48pm
 
by adding textureMode(NORMALIZE); im able to get some texturing on the sphere, but it doesnt seem quite right... any hints anyone?
Page Index Toggle Pages: 1