Author Topic: Sphärische in Kartesische Koordinaten umwandeln  (Read 4651 times)

Offline mxtra

  • byte
  • *
  • Posts: 3
    • View Profile
Sphärische in Kartesische Koordinaten umwandeln
« on: October 14, 2013, 06:57:52 pm »
Ich komme irgendwie mit dem Koordinatensystem nicht ganz klar. Ich möchte geografische Koordinaten in die entsprechenden kartesischen Koordinaten umwandeln. Dafür habe ich folgenden Code geschrieben:

   
Code: [Select]
public static SimpleVector geoToCart(double lat, double lon,double R)
{

                lat = lat*0.01745329251;
lon = lon*0.01745329251;

float x = (float) (R * Math.sin(lon) * Math.cos(lat));
float y = (float) (R * Math.sin(lon) * Math.sin(lat));
float z = (float) (R * Math.cos(lon));

SimpleVector ret = new SimpleVector();
ret.x = x;
ret.y = y;
ret.z = z;
return ret;
}

Aufgrund der unterschiedlichen Koordinatensysteme (?) klappt das natürlich nich nicht, aber leider kriege ich das nicht angepasst.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Sphärische in Kartesische Koordinaten umwandeln
« Reply #1 on: October 14, 2013, 08:14:52 pm »
Einfach y und z negieren?

Offline mxtra

  • byte
  • *
  • Posts: 3
    • View Profile
Re: Sphärische in Kartesische Koordinaten umwandeln
« Reply #2 on: October 14, 2013, 08:30:20 pm »
Danke, die geographische Länge wird tatsächlich korrekt übernommen, dafür wird aber die Breite ignoriert

Code: [Select]
SimpleVector vector = SunCalc.geoToCart(0,180,  18);
bringt ein richtiges Resultat,
Code: [Select]
SimpleVector vector = SunCalc.geoToCart(50,180,  18);bringt allerdings das selbe Resultat.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Sphärische in Kartesische Koordinaten umwandeln
« Reply #3 on: October 14, 2013, 08:43:50 pm »
Aber das liegt doch dann an deiner Umrechung an sich und nicht am Koordinatensystem... ???

Offline mxtra

  • byte
  • *
  • Posts: 3
    • View Profile
Re: Sphärische in Kartesische Koordinaten umwandeln
« Reply #4 on: October 14, 2013, 10:01:07 pm »
Aber das Code-Snippet hat ja mal funktioniert. (Für ein anderes Projekt, aber gleicher Anspruch) Ich verstehe nicht warum das jetzt nicht mehr geht.

Ich denke fast, dass um die z-Achse gedreht wird, was natürlich nicht sichtbar wäre. Allerdings habe ich keine "Vertauschung" gefunden, die funktioniert.


Hiermit geht es:
Code: [Select]
public static SimpleVector geoToCart(double latitude, double longitude,double r)
{


latitude  =  latitude *0.01745329251f;
                longitude =  longitude*0.01745329251f;

float x = (float) (r * Math.cos(latitude) * Math.cos(longitude));
float y = (float) (r * Math.cos(latitude) * Math.sin(longitude));
float z = (float) (r * Math.sin(latitude));

SimpleVector ret = new SimpleVector();
ret.x =  y;
ret.y = -z;
ret.z = -x;

return ret;
}
« Last Edit: October 14, 2013, 11:29:42 pm by mxtra »