0%

Intersecting Lines(两线是否相交)

思路讲解

image

详细解释了一下这个式子是怎么来的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// p+tv=q+sw
// (p-q) x w+tv x w = 0
// t=-(p-q)x w/(vxw)
// 传入的是方向式
Point getintersect(Point p,Point v,Point q,Point w){
Point u=p-q;
ld t=cross(w,u)/cross(v,w);
return p+v*t;
}
inline void __(){
Point a,b,c,d;
cin>>a>>b>>c>>d;
Point ab=b-a,cd=d-c;
if(!sgn(cross(ab,cd))){
Point bc=c-b,ad=d-a;
if(!sgn(cross(bc, ad))){
cout<<"LINE\n";
return;
}
cout<<"NONE\n";
return;
}
Point res=getintersect(a, ab, c, cd);
cout<<"POINT "<<fsp(2)<<res.real()<<" "<<res.imag()<<"\n";
}

AC代码

https://vjudge.net/solution/63256517

心路历程(WA,TLE,MLE……)