Given two lines L1 and L2, How can I determine whether they are parallel or not? Here L1 contains (x1,y1)(x2,y2) and L2 contains (X3,y3)(x4,y4)
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3821 |
3 | Benq | 3736 |
4 | Radewoosh | 3631 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3388 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
Given two lines L1 and L2, How can I determine whether they are parallel or not? Here L1 contains (x1,y1)(x2,y2) and L2 contains (X3,y3)(x4,y4)
Название |
---|
I find the nicest way is to use cross product. This avoids any potential division by zero.
Let $$$L_1$$$ be defined by points $$$P_1$$$ and $$$P_2$$$ and $$$L_2$$$ be defined by points $$$P_3$$$ and $$$P_4$$$. Then $$$(P_2 - P_1) \times (P_4 - P_3) = 0$$$ if and only if $$$L_1$$$ and $$$L_2$$$ are parallel. Of course, when using floating points you would rather check if the absolute value of the cross product is less than some very small number, probably something like $$$\epsilon = 10^{-9}$$$.