Mapping a 3D Sphere with GPS data possible?

edited December 2016 in Library Questions

Hello I'm totally new to this forum but I've been using Processing for 6 months now in terms of my Design study, so I'm not really used to the technical jargon of the programming world.

I have a Vision of a Project for this Semester that I simply started to sketch but I don't know if it's even possible.

As for now all I have is a Globe that I can view from different angles through PeasyCam. For my Project I want specific Emojis tweeted around the Globe shown at the Location they come from on my Globe. (Live Data Visualization)

Is it even possible? Because as for now I haven't found anything similar done in Processing on the net. Is there a Tool/Library or whatever to map the GPS date in my 3D Globe?

I know its not much so far but this is the code for my Globe

import peasy.*;
import peasy.org.apache.commons.math.*;
import peasy.org.apache.commons.math.geometry.*;

Planet earth;  

PeasyCam cam;
PImage img;
PImage bg;

void setup() {
  size (1000, 600, P3D);
  img = loadImage("World3.jpg");
  //int i = 10;

  cam = new PeasyCam(this, 200);
  earth = new Planet(50);
}

void draw() {
  bg = loadImage("Black.png");
  background(bg);
  lights();
  earth.show();
}

______



class Planet {
  float radius;
  float angle;
  float distance;
  Planet [] planets;
  float orbitSpeed;
  PVector v;



  PShape globe;

  Planet (float r) {           
    v = PVector.random3D();
    radius = r;
    noStroke();
    noFill();
    globe = createShape(SPHERE, radius);
    globe.setTexture(img);
  }

  void show () {
    pushMatrix();
    noStroke();
    fill(255);
    //rotate(angle);
    translate(v.x, v.y, v.z);
    shape(globe);
    popMatrix();
  }
}

Thanks in advance!

Tagged:

Answers

  • Format your code. To do so, edit your post, select your code and hit ctrl+o

    You should try the unfolding map library/ Install it through the library manager in Processing. Documentation at http://unfoldingmaps.org/

    With your current code, ou can map your GPS points in your images before you use it as a texture for your sphere. To map latitudes and longitudes along the image's width and height, you can use the map function https://processing.org/reference/map_.html

    Kf

  • Or, since you're going to have latitudes and longitudes, you can directly calculate the position.
    Latitude is like the angle between the position vector and the x-y plane.
    Longitude is also similar, search for it online.

  • @kfrajer Latitudes and longitudes are kind of just angles, so I don't see how you can just use map().

  • @Lord_of_the_Galaxy what do you mean by directly calculating the position? How do I do that?

    thanks for answering :)

  • edited December 2016

    How would you plot an angle in an image? You project the angle into a 2D space. Then you use setTexture to plot it on the surface of the sphere. To clarify your previous point:

    Latitude is like the angle between the position vector and the x-y plane.

    That is incorrect. That is actually what longitude is.

    Kf

  • edited December 2016

    @kfrajer That depends on what you mean by the x-y plane. I meant the plane passing through the full length of the equator(equatorial plane?), but I guess that may be taken as some other plane by you(and others, sorry). In any case, the longitude is the angle between the projection of the position vector on the equatorial plane and the axis of the earth. That is precisely the reason why longitudes do not form full circles, whereas latitudes do. Also, the length of each longitudinal line is the same, whereas the latitudes' length range from the length of the equator to nothing at the poles. So no, this-

    Latitude is like the angle between the position vector and the x-y plane.

    Couldn't possibly be the definition of longitudes.
    Another note, longitudes require an artificial reference (curved)line decided by us humans(not really us, but some guys), whereas latitudinal reference is more physically determinable.

  • @BellaG4L Could I think about it a bit? I think I had some book telling me how to do this, but I must search for it. Maybe someone will find the solution before me, but I'll try.

  • @Lord_of_the_Galaxy thanks a lot!! As a designer I really don't have the opportunity to look it up in a reliable Book so thank u so much! We'll see how far this question takes me :)

  • Notice that above line (that you quote) is your comment. That is exactly what I am trying to correct.

    That depends on what you mean by the x-y plane. I meant the plane passing through the full length of the equator(equatorial plane?)

    You are correct in the above statement. So why are we talking about this? My question to you @Lord_of_the_Galaxy, do you know how to represent latitudes and longitudes in 2D? in a globe in 3D?

    This conversation is going off topic. Please let the owner of this post manage this discussion. I am addressing his/her issues.

    Kf

  • edited December 2016

    Yeah sorry, it was off the discussion. And yes, I do recollect having seen how to convert two angles in 3D with a radius to calculate position. And I'm also ignoring the fact that the earth is slightly flattened at the poles because a little inaccuracy is all right I guess.
    Let's just forget about trying to properly map latitudes and longitudes into an image, as I have no idea and it is probably very complex.

  • To clarify here in this post:

    the latitudes' length range from the length of the equator to nothing at the poles

    The above statement is true for a globe (aka. 3D shape) but not for the image, a 2D object. This is the reason why you can use map() for this solution. The magic of this trick is that when you use setTexture() on a sphere, the 2D image is projected into the globe. Then 2D mapped latitude coordinates will be properly/correctly represented on the surface of the sphere. Latitude points close the the middle plane of the image will be plot on the equator and latitude coordinates in the top edge and bottom edge of the image will be map to where the globe's poles are. This trick means that as latitude coordinates get closer to the poles, they will experience more distortion and therefore, they will less accurate. Nevertheless for the sake of this exercise, it will do a good job.

    Using unfolding maps is more accurate. Now thinking about it, I am not sure if they have the option to display data on a globe. I believe all their work (and hidden calculations) are done in 2D.

    Kf

  • I didn't know that, but just note that it won't be adequate if you want the whatever-you-want-to-display-at-coordinates to be in itself a 3D shape and not seem pasted on the globe.

  • edited December 2016

    OK, figured it out.
    Some assumptions-

    • The axis of the earth is the Y axis, with South Pole being positive Y.
    • The Z axis is the line that will pass through the centre of the earth, the equator and the prime meridian.
    • The angles (latitude and longitude) are in radians.
    • 'r' is the radius of the earth.
    • Positive latitude means south and negative north.
    • Positive longitude means east and negative west.

    For the y coordinates -

    float y = r * sin(latitude);

    For the x coordinates -

    float x = r * cos(latitude) * sin(longitude);

    For the z coordinates -

    float z = r * cos(latitude) * cos(longitude);.

    P.S. I didn't have time to check if it works, so please tell me.

Sign In or Register to comment.