Math 计算两条多段线之间的方向角

Math 计算两条多段线之间的方向角,math,geolocation,geospatial,Math,Geolocation,Geospatial,我得到了两条作为多段线的路线作为坐标列表,例如: [13.072624,52.333508,13.763972,52.679616] [52.679616,13.763972,52.333508,13.072624] 我需要比较两条多段线的方向。为此,我想得到它们之间的角度,如果角度小于45°,则返回真值(沿同一方向) 我们如何才能做到这一点?您需要相互比较的是线段的单位向量。我不知道您使用的是哪种语言,也不知道列表是如何组织的,但下面的伪代码将为您提供方向 // create end poi

我得到了两条作为多段线的路线作为坐标列表,例如: [13.072624,52.333508,13.763972,52.679616] [52.679616,13.763972,52.333508,13.072624]

我需要比较两条多段线的方向。为此,我想得到它们之间的角度,如果角度小于45°,则返回真值(沿同一方向)


我们如何才能做到这一点?

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

// 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

很容易得到它们之间的锐角,但计算相对方位要困难得多。