做渐变色的网站,怀化同城网站,wordpress3.8 发布模块,产品营销推广我有两条线#xff1a;L1和L2。我想计算两条线之间的角度。 L1具有点#xff1a;{(x1#xff0c;y1)#xff0c;(x2#xff0c;y2)}和L2具有点#xff1a;{(x3#xff0c;y3)#xff0c;(x4#xff0c;y4)}。如何计算这两条线之间形成的角度#xff0c;而不必计算斜率…我有两条线L1和L2。我想计算两条线之间的角度。 L1具有点{(x1y1)(x2y2)}和L2具有点{(x3y3)(x4y4)}。如何计算这两条线之间形成的角度而不必计算斜率我目前遇到的问题是有时我有水平线(沿x轴的线)下面的公式失败(除以零例外)arctan((m1 - m2) / (1 - (m1 * m2)))其中m1和m2分别是线1和线2的斜率。是否有一个公式/算法可以计算两条线之间的角度而不会得到除以0的异常任何帮助将高度赞赏。这是我的代码片段// Calculates the angle formed between two linespublic static double angleBetween2Lines(Line2D line1, Line2D line2){double slope1 line1.getY1() - line1.getY2() / line1.getX1() - line1.getX2();double slope2 line2.getY1() - line2.getY2() / line2.getX1() - line2.getX2();double angle Math.atan((slope1 - slope2) / (1 - (slope1 * slope2)));return angle;}谢谢。