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 & HelpSyntax Questions › Mapping points on an imaginary sphere
Page Index Toggle Pages: 1
Mapping points on an imaginary sphere (Read 459 times)
Mapping points on an imaginary sphere
Oct 29th, 2008, 9:35am
 
I am trying to write a planetarium software and I want to be able to map the positions of stars onto a sphere. The view would be based at the centre of the invisible sphere and stars would be mapped onto the relevant position on the sphere using their Right Ascension and Declination co-ordinates. I then want to be able to roll that sphere around and see the stars and constellations move around.

Can anyone help with how I may go about doing this please?
Re: Mapping points on an imaginary sphere
Reply #1 - Nov 3rd, 2008, 8:49pm
 
This sounds like a typical problem of converting between different projections.

If you can get your star map stored in a format where x and y positions are between 0 and 1, you can pipe them into a spherical mapping that will place them in 3D world space and then just provide processing with X and Y rotations to change your view.

This is probably the simplest way to do this:
Quote:
float starMapX[] = null;
float starMapY[] = null;

void setup()
{
  size(640,480,P3D);
  
  final int starCount = 1000;
  starMapX = new float[starCount];
  starMapY = new float[starCount];
  for( int i=0; i<starCount; ++i )
  {
    starMapX[i] = random(0,1);
    starMapY[i] = random(0,1);
  }
}

float rot;
void draw()
{
  background (0);
  stroke     (255);

  // Some basic settings
  final float TWOPI            = 2.0f * PI;
  final float radius           = 150.0f;
  final float sphere_origin_x  =  width/2;
  final float sphere_origin_y  =  height/2;
  final float sphere_origin_z  =  width/2;
  
  rot += 0.01f;

  pushMatrix();
  
    translate ( sphere_origin_x,
                sphere_origin_y,
                sphere_origin_z );
    rotateX   ( rot );
    rotateY   ( rot * 3.0 );

    // For each star position in (x,y) cylindrical format, convert to world coordinates
    for( int i=0; i<starMapX.length; ++i )
    {
      float lat          = starMapX[i] * TWOPI;
      float lon          = starMapY[i] * TWOPI - PI;
    
      float star_world_x = sin(lat) * cos(lon) * radius;
      float star_world_y = sin(lon)            * radius;
      float star_world_z = cos(lat) * cos(lon) * radius;
    
      point ( star_world_x,
              star_world_y,
              star_world_z );
    }
    
  popMatrix();    
}



Re: Mapping points on an imaginary sphere
Reply #2 - Nov 4th, 2008, 10:20am
 
no, actually processing can do all the math for you:
Code:

float starMapX[] = null;
float starMapY[] = null;
float radius = 150;
float rot;
float sphere_origin_x;
float sphere_origin_y;
float sphere_origin_z;

void setup()
{
size(640,480,P3D);

final int starCount = 1000;
starMapX = new float[starCount];
starMapY = new float[starCount];
for( int i=0; i<starCount; ++i )
{
starMapX[i] = random(0,TWO_PI);
starMapY[i] = random(0,TWO_PI);
}

sphere_origin_x = width/2;
sphere_origin_y = height/2;
sphere_origin_z = width/2;
}

void draw()
{
background (0);
stroke (255);

rot += 0.01f;

pushMatrix();

translate ( sphere_origin_x, sphere_origin_y, sphere_origin_z );
rotateX ( rot );
rotateY ( rot * 3.0 );

for( int i=0; i<starMapX.length; ++i )
{
pushMatrix();

rotateX( starMapX[i] );
rotateY( starMapY[i] );
translate( radius, 0, 0 );

point ( 0,0,0 );

popMatrix();
}

popMatrix();
}


F
Re: Mapping points on an imaginary sphere
Reply #3 - Nov 5th, 2008, 10:31am
 
That will put random stars around a sphere but will not put the position of a star on that sphere in the correct place according to its RA and DEC co-ordinates.
Page Index Toggle Pages: 1