如何找到两个具有不同位置的矩形选择中点的位置对应关系

huangapple go评论80阅读模式
英文:

How to find the position correspondence of a point in 2 rectangular selections with different position

问题

Here's the translation of the code and context you provided:

这是你提供的代码和相关上下文的翻译:

这是情况,
我有3种不同的坐标,rectangleOld、rectangleNew和pointIntoRectangleOld,所以 ->

rectangleOld = [
  [-23374.69715123405, 6706811.7857385],
  [-23516.832747730223, 6706811.7857385],
  [-23516.832747730223, 6706948.18295946],
  [-23374.69715123405, 6706948.18295946],
  [-23374.69715123405, 6706811.7857385]
];

pointIntoRectangleOld = [-23440.522912441458, 6706879.939226517];

rectangleNew = [
  [-22869.755094112752, 6706693.921604385],
  [-23011.890690608925, 6706693.921604385],
  [-23011.890690608925, 6706830.318825345],
  [-22869.755094112752, 6706830.318825345],
  [-22869.755094112752, 6706693.921604385],
]

根据这些信息,我该如何计算新矩形中应该放置一个新点的位置,该位置与旧矩形中的第一个点位置完全相同?

我正在使用Java进行开发,我已经尝试了这个,但似乎不起作用:

double lat1 = Double.parseDouble(coordinateOldx);
double lat2 = Double.parseDouble(plantPosX);
double xPosPlant = lat1 - lat2;
double long1 = Double.parseDouble(coordinateOldy);
double long2 = Double.parseDouble(plantPosY);
double yPosPlant = long1 - long2;
System.out.println(xPosPlant);
System.out.println(yPosPlant);
            
double latnew = Double.parseDouble(coordinateNewx);
latnew = latnew + xPosPlant;
double longNew = Double.parseDouble(coordinateNewy);
longNew = longNew + yPosPlant;

latNew和longNew应该是该点的坐标x/y,我尝试从新旧矩形的一个角度开始,但不起作用。

请注意,这段代码似乎缺少变量coordinateOldxplantPosXcoordinateOldyplantPosY的定义。如果你需要更多帮助,请提供这些变量的定义以及详细的问题描述。

英文:

That's the situation,
I've 3 kind of different coordinates, the rectangleOld,rectangleNew and pointIntoRectangleOld so ->

rectangleOld = [
  [-23374.69715123405, 6706811.7857385],
  [-23516.832747730223, 6706811.7857385],
  [-23516.832747730223, 6706948.18295946],
  [-23374.69715123405, 6706948.18295946],
  [-23374.69715123405, 6706811.7857385]
];

pointIntoRectangleOld = [-23440.522912441458,6706879.939226517];

rectangleNew = [
  [-22869.755094112752, 6706693.921604385],
  [-23011.890690608925, 6706693.921604385],
  [-23011.890690608925, 6706830.318825345],
  [-22869.755094112752, 6706830.318825345],
  [-22869.755094112752, 6706693.921604385],
]

Given this information, how can I calculate where should be the position of a new point in the new rectangle that has the exact same position as the first one in the old rectangle?

I'm developing in java, and I've trivially tried this, but it doesn't seem to work:

double lat1=Double.parseDouble(coordinateOldx);
double lat2=Double.parseDouble(plantPosX);
double xPosPlant=lat1-lat2;
double long1=Double.parseDouble(coordinateOldy);
double long2=Double.parseDouble(plantPosY);
double yPosPlant=long1-long2;
System.out.println(xPosPlant);
System.out.println(yPosPlant);
            
double latnew=Double.parseDouble(coordinateNewx);
latnew=latnew + xPosPlant;
double longNew=Double.parseDouble(coordinateNewy);
longNew=longNew + yPosPlant;

latNew and longNew should be the coordinate x/y of the point, i tried starting from a single angle of the new and old rectangle but is not working.

答案1

得分: 1

在球面上,"矩形"存在一些特殊情况,但你可以进行以下操作:

计算点在第一个矩形中的相对位置。
将这个相对位置重新计算为第二个矩形中的绝对坐标。

要获取第一个矩形中的(u,v)坐标(范围为0到1),请使用相对角点:

u = (plant.lat - rectOld[0].lat) / (rectOld[2].lat - rectOld[0].lat)
v = (plant.lon - rectOld[0].lon) / (rectOld[2].lon - rectOld[0].lon)

而对于新坐标:

plantNew.lat = rectNew[0].lat + u * (rectNew[2].lat - rectNew[0].lat)
plantNew.lon = rectNew[0].lon + v * (rectNew[2].lon - rectNew[0].lon)

英文:

There are some peculiarities for "rectangles" at the sphere, but you can do the next:

Calculate relative position of point in the first rectangle.
Recalculate this relative position into absolute coordinates int he second rectangle.

To get (u,v) coordinates (range 0..1) in the first rectangle, use opposite corners

 u = (plant.lat - rectOld[0].lat) / (rectOld[2].lat - rectOld[0].lat)
 v = (plant.lon - rectOld[0].lon) / (rectOld[2].lon - rectOld[0].lon)

And for new coordinates

plantNew.lat = rectNew[0].lat + u * (rectNew[2].lat - rectNew[0].lat)
plantNew.lon = rectNew[0].lon + v * (rectNew[2].lon - rectNew[0].lon)

huangapple
  • 本文由 发表于 2023年7月18日 14:34:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76710071.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定