python - 从两个坐标和角恢复第三个坐标
问题描述
我有 3 个地理坐标
first_coordinate = [55.266346, 25.053268]
second_coordinate = [55.266472, 25.053311]
third_coordinate = [55.266370, 25.0532]
然后我将它们转换为 EPSG:3997:
def convert(point):
return Point(transformer.transform(point[0], point[1]))
first_point_in_meters = convert(first_coordinate)
second_point_in_meters = convert(second_coordinate)
third_point_in_meter = convert(third_coordinate)
然后尝试使用以下方法确定原点第三坐标:
def calculate_third_point(Ax, Ay, Cx, Cy, b, c, A, alt):
uACx = (Cx - Ax) / b
uACy = (Cy - Ay) / b
if alt:
uABx = uACx * math.cos(A) - uACy * math.sin(A)
uABy = uACx * math.sin(A) + uACy * math.cos(A)
Bx = Ax + c * uABx
By = Ay + c * uABy
else:
uABx = uACx * math.cos(A) + uACy * math.sin(A)
uABy = - uACx * math.sin(A) + uACy * math.cos(A)
Bx = Ax + c * uABx
By = Ay + c * uABy
return Point([Bx, By])
并将这 2 个坐标转换回 EPSG:4326。但最近的坐标距离原点 2 米
one distance: 2.6033912103159342 m.
anther distance: 19.215538365617018 m.
我做错了什么?
完整代码:
import math
import numpy as np
from pyproj import Transformer
from shapely.geometry import Point
transformer_4326 = Transformer.from_crs(3997, 4326, always_xy=True)
transformer = Transformer.from_crs(4326, 3997, always_xy=True)
def calculate_third_point(Ax, Ay, Cx, Cy, b, c, A, alt):
uACx = (Cx - Ax) / b
uACy = (Cy - Ay) / b
if alt:
uABx = uACx * math.cos(A) - uACy * math.sin(A)
uABy = uACx * math.sin(A) + uACy * math.cos(A)
Bx = Ax + c * uABx
By = Ay + c * uABy
else:
uABx = uACx * math.cos(A) + uACy * math.sin(A)
uABy = - uACx * math.sin(A) + uACy * math.cos(A)
Bx = Ax + c * uABx
By = Ay + c * uABy
return Point([Bx, By])
def find_angle(rone, rtwo, rthree):
one = np.array(rone)
two = np.array(rtwo)
three = np.array(rthree)
ba = one - two
bc = three - two
cosine_angle = np.dot(ba, bc) / (np.linalg.norm(ba) * np.linalg.norm(bc))
angle = np.arccos(cosine_angle)
return np.degrees(angle)
def convert(point):
return Point(transformer.transform(point[0], point[1]))
first_coordinate = [55.266346, 25.053268]
second_coordinate = [55.266472, 25.053311]
third_coordinate = [55.266370, 25.0532]
first_point_in_meters = convert(first_coordinate)
second_point_in_meters = convert(second_coordinate)
third_point_in_meter = convert(third_coordinate)
angle = find_angle(third_point_in_meter, second_point_in_meters, first_point_in_meters)
distance = first_point_in_meters.distance(second_point_in_meters)
distance2 = first_point_in_meters.distance(third_point_in_meter)
one = calculate_third_point(
first_point_in_meters.x,
first_point_in_meters.y,
second_point_in_meters.x,
second_point_in_meters.y,
distance,
distance2,
angle,
True)
another = calculate_third_point(
first_point_in_meters.x,
first_point_in_meters.y,
second_point_in_meters.x,
second_point_in_meters.y,
distance,
distance2,
angle,
False)
print("one distance: {0} m.".format(one.distance(third_point_in_meter)))
print("anther distance: {0} m.".format(another.distance(third_point_in_meter)))
解决方案
推荐阅读
- ios - 这个应用程序如何立即请求后台位置权限?
- python - Django - 多对多字段排序问题
- android - 获取适用于 android 10 的永久唯一设备 ID
- android - Android 11 - java.lang.IllegalStateException 不允许启动服务意图:应用处于后台 uid UidRecord{}
- android - Android Studio 4.1 getString 从 build.gradle 中的 resValue
- javascript - d3.js data.columns 不存在?
- git - 直接新建一个断开连接的git分支
- python - 在多个条件下求和
- javascript - 在 Reat js 中使用来自状态的验证时无法修改文本字段
- gnuplot - Gnuplot:如何将 pm3d 绘图继续到设定范围之外?