gpt4 book ai didi

math - 从点计算文档的倾斜度?

转载 作者:行者123 更新时间:2023-12-02 04:08:26 26 4
gpt4 key购买 nike

假设您有一个PDF文档。

在该文档上,您已经确定了对应于两个(lat,lng)坐标的两个(x,y)坐标。

您如何计算文档的倾斜度-即文档顶部的指南针方向是什么?

编辑:

当我在发布的答案中使用公式时,它不会返回我期望的结果。例如:

The sample data look like y x (lat lng). 

The 1st test should be due north (0) and the 2nd should be due south (pi).

The first point is 0.000000 0.000000 (30.000000 60.000000)
The second point is 0.000000 200.000000 (30.000000 120.000000)
Theta is -0.000000

The first point is 0.000000 200.000000 (30.000000 60.000000)
The second point is 0.000000 0.000000 (30.000000 120.000000)
Theta is -0.000000

我在用:
float rho = atan(
(-y1 + y2) /
(-x1 + x2)
);

float theta = atan(
((lat2 - lat1 )*cos(rho) + (long1 - long2)*sin(rho))/
((long1 - long2)*cos(rho) + (lat1 - lat2 )*sin(rho))
);

最佳答案

1)如果角度为0->,则表示它指向东方! (或者您必须在方程式中反转y和x)。

2)在两种情况下,您都被零除。这等于无限,在大多数编程语言中,它将导致崩溃。如果没有,它将至少引入一些舍入误差。对于两个x坐标尝试使用不同的值而不是0 ...

您可能要考虑:


float rho;
int denominator = -x1 + x2;
if(denominator == 0.0)
rho = (-y1 + y2 > 0) ? pi/2.0 : -pi/2.0;
else
rho = (-y1 + y2) / denominator;

关于math - 从点计算文档的倾斜度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6416194/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com