I have the following setup of items in real life:
The radar is static, which means it always has the same position. The A
-item can move and its position can be whatever. From the radar I can read the x
and y
coordinates of A
in relation to the radar. I have written the following classes to describe the position of each item:
public class Position {
public enum Direction {
EAST, WEST, NORTH, SOUTH
};
public final Direction latitudeDirection, longitudeDirection;
public final float latitude, longitude, altitude;
public Position(Direction latitudeDirection, Direction longitudeDirection,
float latitude, float longitude, float altitude) {
this.latitudeDirection = latitudeDirection;
this.longitudeDirection = longitudeDirection;
this.latitude = latitude;
this.longitude = longitude;
this.altitude = altitude;
}
public Position(float radarX, float radarY) {
// TODO: Implement the question here
this.altitude = Config.RADAR_POSITION.altitude;
}
}
class Config {
// Position of the radar
public static final Position RADAR_POSITION = new Position(
Position.Direction.NORTH, // Latitude direction
Position.Direction.EAST, // Longitude direction
55.0f, // Latitude
13.0f, // Longitude
60.0f); // Altitude
// Facing direction of the radar in degrees. 0° is north, advancing
// clockwise.
public static final float RADAR_FACING_DIRECTION = 10.0f;
}
Now given the geographic coordinates of the radar, the x
and y
coordinates of A
relative to the radar and the facing direction of the radar relative to the North, how can I calculate the absolute geographic coordinates of A
?
The curvature of the earth is not an issue since the maximum value of x
and/or y
cannot be more than a couple hundred meters.
As an example, you can use trigonometric functions to create triangles to find coordinates of A:
In this case, Ax = (y)(cos 10) - (x)(cos 80), and you could work out Ay similarly.
This way, you are never stuck in degrees, you are simply working in meters.
The robust solution is Vishal's comment in the OP, which was posted whilst I was drawing and scanning:
xnew = x * cos(theta) - y * sin(theta);
ynew = x * sin(theta) + y * cos(theta);
In general, you can use the following steps:
There are many ressources for such transformations, check this, for instance: http://www.gmat.unsw.edu.au/snap/gps/clynch_pdfs/coordcvt.pdf
You can also introduce a scene coordinate system, if needed (ENU). Here is a fairly good overview describing the relation of UTM, ECEF, ENU and geodotic coordinates(Lat/lon/h): http://www.dirsig.org/docs/new/coordinates.html
If you need sample code for ECEF to/from Geodetic conversion, have a look at the matlab code, http://www.mathworks.de/de/help/map/ref/ecef2geodetic.html, or use a library like GDAL (http://www.gdal.org/)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With