两行之间的角度从行的一侧开始 [英] Angle between two lines beginning at one side of the line

查看:175
本文介绍了两行之间的角度从行的一侧开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两行,每行用x和y坐标表示两行。第一点(线开始的地方) 是相等的,这意味着我有3个点A,B和C,其中一条线从A到B,另一个从A到C.然后我想要计算从第一行右侧开始的两条线之间的角度。结果不一定准确我实际上只需要知道这个角度是否比180°(π弧度)大小于。感谢您的帮助 - 您无需编写任何代码,伪代码和/或解释将会非常棒。 记法:

  A:=(a1,a1)。 
B:=(b1,b2)。
C:=(c1,c2)。

然后矩阵的行列式D

  1 a1 a2 
1 b1 b2
1 c1 c2

确定 C 位于定向线 AB 的左侧还是右侧[比照。计算几何 - Berg,van Kreveld,Overmars,Schwarzkopf - 第1章练习1.4 a)]

现在,可以从第2行和第3行中减去第1行:
p>

  1 a1 a2 
0 b1 -a1 b2-a2
0 c1 -a1 c2-a2

并从第一列计算 D 得到:

 (b1-a1)*(c2-a2)> (c1-a1)*(b2-a2)

作为表示 C 位于 AC 的左边或者不在。当然,位于右侧(或左侧)意味着该角度是< 180元(分数> 180元)



示例

  A =(0,0)
B =(0,1)
C =(1,0)

然后 AB 是垂直线段(y轴), C 显然在它的右侧。条件

 (b1-a1)*(c2-a2)> (c1-a1)*(b2-a2)ineq(1)

变成:

  0> 1 

false ,这意味着 C 不在 AB 左边(如预期)



<可视化



为了可视化条件,我们可以将三点 A B C 直到 A 变成(0,0)。这是一个无害的转换,因为ineq(1)中的条件从<$ c的坐标中减去 a1 a2 $ c> B 和 C 。 (1)变成:

< c1 * b2 ineq(2)

现在让我们看到三个点(现在忽略棕色线相对于 C'=(c'1,c'2)):



产品 b1 * c2 是红色矩形的区域。产品 c1 * b2 是GREEN矩形的面积。图片显示RED< GREEN表示 C 在右边。



现在,小心地将 C ,比方说 C',并可视化新的RED和GREEN矩形。只要 C 在右侧,不平等就会保持有效。



还不确定吗?那么,编写一个程序,可以在改变 C 的位置时动态地重现这张图片,瞧! (或者学习更多的数学知识并解决本书的练习;)

注意:注意这些矩形有一个符号。在图片中,他们都有一个积极的领域,但是,一般来说,产品 b1 * c2 b2 * c1 会有一个标志。


I have two lines specified by two points with x and y coordinate each. The first point (where the lines begin) is equal meaning that I have 3 points A, B and C where one line is from A to B and the other one from A to C. I would then want to calculate the angle between the two lines starting at the right side of the first line. The result needn't be accurate I actually only need to know if this angle is greater or less than 180° (π rad). Thanks for any help - you needn't write any code, pseudocode and/or explanation would be great.

解决方案

Let's define some notation:

A := (a1, a1).
B := (b1, b2).
C := (c1, c2).

Then the determinant D of the matrix

1 a1 a2
1 b1 b2
1 c1 c2

determines whether C lies left or right of the directed line AB [cf. Computational Geometry - Berg, van Kreveld, Overmars, Schwarzkopf - Chapter 1, Exercise 1.4 a)]

Now, you can subtract row 1 from rows 2 and 3:

1 a1     a2
0 b1-a1 b2-a2
0 c1-a1 c2-a2

and calculate D from the first column to get:

(b1-a1)*(c2-a2) > (c1-a1)*(b2-a2)

as the condition representing whether Clies on the left of AC or not. Of course, lying on the right (resp. left) means that the angle is < 180 (resp. > 180)

Example

A = (0, 0)
B = (0, 1)
C = (1, 0)

Then AB is the vertical segment (y axis) and C is clearly on its right side. The condition

(b1-a1)*(c2-a2) > (c1-a1)*(b2-a2)           ineq(1)

becomes:

0 > 1

which is false, meaning that C is not on the left of AB (as expected)

Visualization

To visualize the condition we can translate the three points A, B and C until A becomes (0,0). This is an innocuous transformation because the condition in ineq(1) subtracts a1 and a2 from the coordinates of B and C. With this translation ineq(1) becomes:

b1*c2 > c1*b2                              ineq(2)

Now, lets visualize the three points (ignore for now the brown lines relative to C' = (c'1, c'2)):

The product b1*c2 is the area of the RED rectangle. The product c1*b2 is the area of the GREEN rectangle. The picture shows that RED < GREEN meaning that C is on the right.

Now, mentally move C around, say to C' and visualize the new RED and GREEN rectangles. The inequality remains valid as long as C is on the right.

Not convinced yet? Well, write a program that dynamically reproduces this picture while you change the position of C and voila! (Or study some more Mathematics and solve the book's exercise ;)

Note: Be aware that these rectangles have a sign. In the picture they both have a positive area, however, in general, the products b1*c2 and b2*c1 will have a sign.

这篇关于两行之间的角度从行的一侧开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆