从旧坐标和x和y计算新坐标

时间:2022-07-23 21:21:24

I have the following setup of items in real life:

我在现实生活中有以下项目设置:

从旧坐标和x和y计算新坐标

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:

雷达是静态的,这意味着它总是具有相同的位置。 A项可以移动,它的位置可以是任何东西。从雷达我可以读取A相对于雷达的x和y坐标。我编写了以下类来描述每个项目的位置:

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?

现在给出雷达的地理坐标,A相对于雷达的x和y坐标以及雷达相对于北方的面向方向,如何计算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.

地球的曲率不是问题,因为x和/或y的最大值不能超过几百米。

6 个解决方案

#1


1  

I think it should be possible to do it this way: Convert the x and y coordinates to polar coordinates r and theta, (with the radar as the origin). Subtract the radar's rotation, and convert back to cartesian coordinates. Then you just have to convert to latitude and longitude and add the coordinates of the radar.

我认为应该可以这样做:将x和y坐标转换为极坐标r和theta(以雷达为原点)。减去雷达的旋转,然后转换回笛卡尔坐标。然后你只需要转换为纬度和经度并添加雷达的坐标。

double r = Math.hypot(radarX, radarY);
double theta = Math.atan2(radarY, radarX);
theta -= Math.toRadians(Config.RADAR_FACING_DIRECTION);
float x = (float) r * Math.cos(theta);
float y = (float) r * Math.sin(theta);
longitude = metersToLongitude(Config.RADAR_POSITION, y) + Config.RADAR_POSITION.longitude;
latitude = metersToLatitude(Config.RADAR_POSITION, x) + Config.RADAR_POSITION.latitude;

I found formulae for the length of a degree of latitude and longitude on Wikipedia. A degree of latitude is the same everywhere but longitude gets smaller near the poles.

我在*上找到了纬度和经度长度的公式。纬度在任何地方都是相同的,但经度在极点附近变小。

static float metersToLatitude(Position near, float meters) {
    return meters / 110.6*1000;
}

static float metersToLongitude(Position near, float meters) {
    float lat = Math.toRadians(near.latitude);
    return meters /
        (111132.954 - 559.822 * Math.cos(2*lat) + 1.175 * Math.cos(4*lat));
}

Unfortunately this doesn't seem to work and I can't figure out why.

不幸的是,这似乎不起作用,我无法弄清楚为什么。

If you want to express your coordinates in positive degrees east/west/north/south you'll also have to check if they're negative and invert them and the direction in that case.

如果你想以东/西/北/南的正度表示你的坐标,你还必须检查它们是否为负并反转它们和那种情况下的方向。

#2


3  

As an example, you can use trigonometric functions to create triangles to find coordinates of A:

例如,您可以使用三角函数创建三角形以查找A的坐标:

从旧坐标和x和y计算新坐标

In this case, Ax = (y)(cos 10) - (x)(cos 80), and you could work out Ay similarly.

在这种情况下,Ax =(y)(cos 10) - (x)(cos 80),你可以类似地计算出Ay。

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:

强大的解决方案是Vishal在OP中的评论,该评论是在我绘图和扫描时发布的:

xnew = x * cos(theta) - y * sin(theta); 
ynew = x * sin(theta) + y * cos(theta);

#3


2  

In general, you can use the following steps:

通常,您可以使用以下步骤:

  1. transform your radar position (lat, lon, height) into metric earth centered earth fixed xyz-system (ECEF)
  2. 将您的雷达位置(纬度,经度,高度)转换为公制地球中心地球固定xyz系统(ECEF)

  3. You can then use/combine any rotation and translation arguments/matrices, which describe radar rotation and object position, in this metric system
  4. 然后,您可以在此度量系统中使用/组合任何描述雷达旋转和对象位置的旋转和平移参数/矩阵

  5. back transform newly acquired xzy coordinates to lat/lon/h
  6. 将新获取的xzy坐标转换为lat / lon / h

There are many ressources for such transformations, check this, for instance: http://www.gmat.unsw.edu.au/snap/gps/clynch_pdfs/coordcvt.pdf

这种转换有很多资源,请查看,例如: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

如果需要,您还可以引入场景坐标系(ENU)。以下是描述UTM,ECEF,ENU和地理坐标(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/)

如果您需要ECEF到/来自Geodetic转换的示例代码,请查看matlab代码,http://www.mathworks.de/de/help/map/ref/ecef2geodetic.html,或使用像GDAL这样的库( http://www.gdal.org/)

#4


1  

Does this help for conversion? http://en.wikipedia.org/wiki/Geodetic_system#From_geodetic_to_ECEF ?

这有助于转换吗? http://en.wikipedia.org/wiki/Geodetic_system#From_geodetic_to_ECEF?

#5


1  

Finally I solved it. The code is attached below. Since Samuel Edwin Ward's answer is the one that inspired me, I will accept his answer.

最后我解决了。代码附在下面。由于塞缪尔·埃德温·沃德的答案是激励我的,我会接受他的回答。

public Position(float radarX, float radarY) {

    // Convert A's position to distance and bearing in relation to the North 
    double objDistance = (Math.hypot(radarX, radarY) / 6367500 /* Mean earth radius */);
    double objBearing = (Math.atan2(radarY, radarX) + Math.toRadians(Config.RADAR_BEARING));

    // Convert the Radar's geographic coordinates to radians
    double latitudeRadar = Math.toRadians(Config.RADAR_POSITION.latitude);
    double longitudeRadar = Math.toRadians(Config.RADAR_POSITION.longitude);

    // Calculate A's geographic coordinates in radians
    double latitudeObject = Math.asin(Math.sin(latitudeRadar)*Math.cos(objDistance) + 
            Math.cos(latitudeRadar)*Math.sin(objDistance)*Math.cos(objBearing));
    double longitudeObject = longitudeRadar + Math.atan2(Math.sin(objBearing)*Math.sin(objDistance)*Math.cos(latitudeRadar), 
            Math.cos(objDistance)-Math.sin(latitudeRadar)*Math.sin(latitudeObject));

    // Normalize to -180 ... +180 degrees
    longitudeObject = (longitudeObject+3*Math.PI) % (2*Math.PI) - Math.PI;  

    // Set the A's coordinates in degrees
    this.latitude = (float) Math.toDegrees(latitudeObject);
    this.longitude = (float) Math.toDegrees(longitudeObject);

    // Set the rest of the arguments
    this.latitudeDirection = Config.RADAR_POSITION.latitudeDirection;
    this.longitudeDirection = Config.RADAR_POSITION.longitudeDirection;
    this.altitude = Config.RADAR_POSITION.altitude;
}

#6


0  

You rotate all coordinates in the local system of the radar -10° and are then able to just add the radar's x/y coordinates to the A object coordinates.

您可以旋转雷达本地系统中的所有坐标-10°,然后只需将雷达的x / y坐标添加到A对象坐标。

#1


1  

I think it should be possible to do it this way: Convert the x and y coordinates to polar coordinates r and theta, (with the radar as the origin). Subtract the radar's rotation, and convert back to cartesian coordinates. Then you just have to convert to latitude and longitude and add the coordinates of the radar.

我认为应该可以这样做:将x和y坐标转换为极坐标r和theta(以雷达为原点)。减去雷达的旋转,然后转换回笛卡尔坐标。然后你只需要转换为纬度和经度并添加雷达的坐标。

double r = Math.hypot(radarX, radarY);
double theta = Math.atan2(radarY, radarX);
theta -= Math.toRadians(Config.RADAR_FACING_DIRECTION);
float x = (float) r * Math.cos(theta);
float y = (float) r * Math.sin(theta);
longitude = metersToLongitude(Config.RADAR_POSITION, y) + Config.RADAR_POSITION.longitude;
latitude = metersToLatitude(Config.RADAR_POSITION, x) + Config.RADAR_POSITION.latitude;

I found formulae for the length of a degree of latitude and longitude on Wikipedia. A degree of latitude is the same everywhere but longitude gets smaller near the poles.

我在*上找到了纬度和经度长度的公式。纬度在任何地方都是相同的,但经度在极点附近变小。

static float metersToLatitude(Position near, float meters) {
    return meters / 110.6*1000;
}

static float metersToLongitude(Position near, float meters) {
    float lat = Math.toRadians(near.latitude);
    return meters /
        (111132.954 - 559.822 * Math.cos(2*lat) + 1.175 * Math.cos(4*lat));
}

Unfortunately this doesn't seem to work and I can't figure out why.

不幸的是,这似乎不起作用,我无法弄清楚为什么。

If you want to express your coordinates in positive degrees east/west/north/south you'll also have to check if they're negative and invert them and the direction in that case.

如果你想以东/西/北/南的正度表示你的坐标,你还必须检查它们是否为负并反转它们和那种情况下的方向。

#2


3  

As an example, you can use trigonometric functions to create triangles to find coordinates of A:

例如,您可以使用三角函数创建三角形以查找A的坐标:

从旧坐标和x和y计算新坐标

In this case, Ax = (y)(cos 10) - (x)(cos 80), and you could work out Ay similarly.

在这种情况下,Ax =(y)(cos 10) - (x)(cos 80),你可以类似地计算出Ay。

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:

强大的解决方案是Vishal在OP中的评论,该评论是在我绘图和扫描时发布的:

xnew = x * cos(theta) - y * sin(theta); 
ynew = x * sin(theta) + y * cos(theta);

#3


2  

In general, you can use the following steps:

通常,您可以使用以下步骤:

  1. transform your radar position (lat, lon, height) into metric earth centered earth fixed xyz-system (ECEF)
  2. 将您的雷达位置(纬度,经度,高度)转换为公制地球中心地球固定xyz系统(ECEF)

  3. You can then use/combine any rotation and translation arguments/matrices, which describe radar rotation and object position, in this metric system
  4. 然后,您可以在此度量系统中使用/组合任何描述雷达旋转和对象位置的旋转和平移参数/矩阵

  5. back transform newly acquired xzy coordinates to lat/lon/h
  6. 将新获取的xzy坐标转换为lat / lon / h

There are many ressources for such transformations, check this, for instance: http://www.gmat.unsw.edu.au/snap/gps/clynch_pdfs/coordcvt.pdf

这种转换有很多资源,请查看,例如: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

如果需要,您还可以引入场景坐标系(ENU)。以下是描述UTM,ECEF,ENU和地理坐标(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/)

如果您需要ECEF到/来自Geodetic转换的示例代码,请查看matlab代码,http://www.mathworks.de/de/help/map/ref/ecef2geodetic.html,或使用像GDAL这样的库( http://www.gdal.org/)

#4


1  

Does this help for conversion? http://en.wikipedia.org/wiki/Geodetic_system#From_geodetic_to_ECEF ?

这有助于转换吗? http://en.wikipedia.org/wiki/Geodetic_system#From_geodetic_to_ECEF?

#5


1  

Finally I solved it. The code is attached below. Since Samuel Edwin Ward's answer is the one that inspired me, I will accept his answer.

最后我解决了。代码附在下面。由于塞缪尔·埃德温·沃德的答案是激励我的,我会接受他的回答。

public Position(float radarX, float radarY) {

    // Convert A's position to distance and bearing in relation to the North 
    double objDistance = (Math.hypot(radarX, radarY) / 6367500 /* Mean earth radius */);
    double objBearing = (Math.atan2(radarY, radarX) + Math.toRadians(Config.RADAR_BEARING));

    // Convert the Radar's geographic coordinates to radians
    double latitudeRadar = Math.toRadians(Config.RADAR_POSITION.latitude);
    double longitudeRadar = Math.toRadians(Config.RADAR_POSITION.longitude);

    // Calculate A's geographic coordinates in radians
    double latitudeObject = Math.asin(Math.sin(latitudeRadar)*Math.cos(objDistance) + 
            Math.cos(latitudeRadar)*Math.sin(objDistance)*Math.cos(objBearing));
    double longitudeObject = longitudeRadar + Math.atan2(Math.sin(objBearing)*Math.sin(objDistance)*Math.cos(latitudeRadar), 
            Math.cos(objDistance)-Math.sin(latitudeRadar)*Math.sin(latitudeObject));

    // Normalize to -180 ... +180 degrees
    longitudeObject = (longitudeObject+3*Math.PI) % (2*Math.PI) - Math.PI;  

    // Set the A's coordinates in degrees
    this.latitude = (float) Math.toDegrees(latitudeObject);
    this.longitude = (float) Math.toDegrees(longitudeObject);

    // Set the rest of the arguments
    this.latitudeDirection = Config.RADAR_POSITION.latitudeDirection;
    this.longitudeDirection = Config.RADAR_POSITION.longitudeDirection;
    this.altitude = Config.RADAR_POSITION.altitude;
}

#6


0  

You rotate all coordinates in the local system of the radar -10° and are then able to just add the radar's x/y coordinates to the A object coordinates.

您可以旋转雷达本地系统中的所有坐标-10°,然后只需将雷达的x / y坐标添加到A对象坐标。