This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Obtain GeoDataCoordinates from lat and lon with meter offset

Tags: None
(comma "," separated)
Beacon11
Registered Member
Posts
35
Karma
0
I have two object locations: A vehicle location, given in latitude/longitude/altitude, and an object detected by the vehicle, given as an X/Y/Z offset from the vehicle in meters. Using this information, does Marble have the faculties to get the latitude/longitude/altitude of the detected object?

I would like to use GeoDataCoordinates to hold both of these locations so I can paint them on the map, but I don't see any functions to help me turn the offsets into a GeoDataCoordinates. I would appreciate any assistance!
User avatar
Earthwings
KDE Developer
Posts
172
Karma
1
OS
There's no ready-made function, but the math behind it should look like below, with the input being
  • lon1, lat1, alt1: vehicle position
  • bearing: vehicle rotation towards north, in rad
  • x, y, z: object position in vehicle coordinates (x points forward, y left, z upward)
  • R: earth radius in the same unit as x, y, z. In Marble you can use EARTH_RADIUS or model()->planet()->radius(), both defined in meter
Code: Select all
brng = atan(y/x) - bearing
d = sqrt(y*y+x*x)
lat2 = asin(sin(lat1)*cos(d/R) + cos(lat1)*sin(d/R)*cos(brng));
lon2 = lon1 + atan2(sin(brng)*sin(d/R)*cos(lat1), cos(d/R)-sin(lat1)*sin(lat2));
alt2 = alt1 + z

Output is lon2, lat2, alt2
See also http://www.movable-type.co.uk/scripts/latlong.html
Beacon11
Registered Member
Posts
35
Karma
0
Earthwings, I apologize, I neglected to check the "notify me" box! Thank you very much for your prompt response :) .

I realize that I left one specification out: I said the x/y/z was offset from the vehicle in meters, but it's actually in north/east/up, which simplifies things a bit. Combining that with your solution, my code looks like the following:

Code: Select all
const qreal planetRadius = model()->planet()->radius();

float offsetLatitude = vehicleLocation.latitude + objectLocation.yOffset/planetRadius;
float offsetLongitude = vehicleLocation.longitude + objectLocation.xOffset/(planetRadius*cos(offsetLatitude*M_PI/180));
float offsetAltitude = vehicleLocation.altitude + objectLocation.zOffset;


It seems to work well. How does it look?


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell