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.
Page Index Toggle Pages: 1
Lat/Lon -> Sphere (Read 1533 times)
Lat/Lon -> Sphere
Oct 30th, 2007, 11:52pm
 
Hey, does anyone know of any good resources to figure out how to map lat/lon coords to a spherical texture map?  Based on this thread ( http://processing.org/discourse/yabb_beta/YaBB.cgi?board=OpenGL;action=display;num=1159148484;start=14#14 ) I've gotten a spherical texture map of a globe working nicely, and now am trying to figure out how to place some lat/lon markers on it.  Sadly, I've been having some difficult finding any good resources on the topic.

thanks for any help,
w
Re: Lat/Lon -> Sphere
Reply #1 - Oct 31st, 2007, 12:37am
 
It depends how the texture is mapped onto the sphere to some extent.

The longtitude can be directly translated into the x-coord of the image, texX=width/2+(width/2*(long/180)) (assuming you're going from -180' to 180'

The latitude depends on what projection was used to map the texture to the sphere. If it's a cylindrical projection, then texY=height/2+(height/2*sin(lat)), otherwise if it's a spherical projection where a pixel in the texture subtends the same angle no matter it's value, then it's similar to the longtitude: texY=height/2+(height/2*(lat/180))

So it's fairly simple, just try both and see which works.

I coudl of course be completely wrong, but I think those are the formulae you need.
Re: Lat/Lon -> Sphere
Reply #2 - Oct 31st, 2007, 12:09pm
 
Hi,

Adapted this from a sketch I did some time ago.

See if it helps...

All the best,

Rui

--//--

import processing.opengl.*;

int latNo;
int longNo;
int rad;

void setup() {
 size(500, 500, OPENGL);
 background(22);

 latNo = 10;
 longNo = 10;
 rad = 200;
}

void draw() {
 noFill();
 strokeWeight(1);
 stroke(185);
 translate(width / 2., height / 2, 0);
 for(int i = 0; i < latNo; i++) {
   pushMatrix();
   rotateY((TWO_PI / latNo) * i * -1);
   arc(0, 0, rad * 2, rad * 2, HALF_PI + PI, HALF_PI);
   popMatrix();
 }
 rotateX(PI/2);
 for(int i = 0; i < longNo; i++) {
   float dif = (PI / (longNo + 2)) * int((i - (longNo / 2.) - 0.5) + 1);
   pushMatrix();
   translate(0, 0, sin(dif) * rad);
   ellipse(0, 0, cos(dif) * rad * 2, cos(dif) * rad * 2);
   popMatrix();
 }
}
Re: Lat/Lon -> Sphere
Reply #3 - Oct 31st, 2007, 12:18pm
 
where it reads lat it should be long and vice versa... to early ;)
Page Index Toggle Pages: 1