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)
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 | 3690 |
2 | jiangly | 3647 |
3 | Benq | 3581 |
4 | orzdevinwang | 3570 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | Radewoosh | 3509 |
8 | ecnerwala | 3486 |
9 | jqdai0815 | 3474 |
10 | gyh20 | 3447 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | maomao90 | 173 |
2 | awoo | 164 |
3 | adamant | 163 |
4 | TheScrasse | 159 |
5 | nor | 157 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 152 |
8 | Petr | 146 |
8 | orz | 146 |
10 | pajenegod | 145 |
Название |
---|
You can get the slope of each of the two lines. slope = (y2-y1)/(x2-x1). If the two slopes are equal, then the two lines are parallel.
I have already tried so many times.
https://codeforces.com/group/MWSDmqGsZm/contest/223338/problem/V
i dont think this is correct since if x2-x1=0 then division by 0
yes. and, it's not the actual theory for this problem
I think it's useful to rely on Google to search for things like this, anyway. If you need to check they are parallel or not you can see if the slope of L1 and L2 are equal or not.
L1 Slope = (y2 — y1) / (x2 — x1);
L2 Slope = (y4 — y3) / (x4 — x3);
If L1 Slope == L2 Slope is a parallel.
Some information that may interest you :CLICK HERE
I already use that theory. but it gives me wrong answer on test case 3
Try thit :-
cross product :- First we calculates the directional vectors for the two line.
L X1=x2-x1 and L Y1=y2-y1 --> 1
L X2=x4-x3 and L Y2=Y4-Y3 --> 2
Now we use the cross product to checks if the cross product of these two directional vectors is equal to zero .
( lx1 * ly2 ) == ( lx2 * ly1 )
if is True so is a parallel, otherwise is not.
Thank you bro!
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}$$$.