【问题标题】:calculate bearing between two polylines计算两条折线之间的方位角
【发布时间】:2017-10-24 13:37:45
【问题描述】:

我有两条路线作为折线作为坐标列表,例如: [13.072624,52.333508,13.763972,52.679616] [52.679616,13.763972,52.333508,13.072624]

我需要比较两条折线的方向。为此,我想获得它们之间的角度,如果它小于 45°,则返回 true(沿相同方向)。

example of route comparison

我们该怎么做?

【问题讨论】:

  • 获得它们之间的锐角非常容易,但计算相对方位要困难得多

标签: math geolocation geospatial


【解决方案1】:

您需要相互比较的是线段的单位向量。我不知道您使用的是哪种语言或列表的组织方式,但以下伪代码将为您提供方位。

// create end points of the line segments from lists
point0(x0, y0);
point1(x1, y1);
point2(x2, y2);
point3(x3, y3);

// create direction vectors from points
directionA = point1 - point0;
directionB = point3 - point2;

// normalize the direction vectors to have a length of 1
// assuming they are not degenerate
directionA.unitize();
directionB.unitize();

// get the dot product of the two direction vectors
dot = directionA.dot(directionB);

// Because the direction vectors are both unit length
// the dot product will return a value between -1.0 and 1.0
// The arc cosine will give you your angle between 0 and 180
angle = arc_cosine_degree(dot)

然后将角度与您为确定“相同”方向而选择的任何容差进行比较。维基百科对我在伪代码中使用的每个概念(即单位向量、点积、反余弦)都有很好的解释。

祝你好运! GCB

【讨论】:

    猜你喜欢
    • 2019-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-22
    • 2016-10-19
    • 2011-12-28
    • 1970-01-01
    相关资源
    最近更新 更多