44## 向量与点的基本算法
55
66``` c++
7-
7+ # define dcmp ( x ) (fabs(x) < eps? 0:((x) <0?-1:1))
88struct Point{
99 double x,y;
1010 Point(double _ x=0,double _ y=0): x (_ x),y(_ y){}
@@ -33,7 +33,7 @@ double Area2(Point A,Point B,Point C){return Cross(B-A,C-A);}
3333## 点和直线
3434
3535```c++
36- Point GetLineIntersection(Point & P,Vector & v, Point & Q,Vector w){
36+ Point GetLineIntersection(Point P,Vector v, Point Q,Vector w){
3737 //计算交点,当v,w平行时无效
3838 Point u = P-Q;
3939 double t = Cross(v,u) / Cross(v,w);
@@ -45,17 +45,17 @@ double Dis2Line(Point &P,Point & A,Point & B){
4545 Vector u2 = B-A;
4646 return abs(Cross(u1,u2)/Length(u2));
4747}
48- Point GetLineProjection(Point & P,Point & A,Point & B){
48+ Point GetLineProjection(Point P,Point A,Point B){
4949 //the projection Point Q of P to Line A,B;
5050 Vector v = B-A;
5151 return A+ v*(Dot(v,P-A)/Dot(v,v));
5252}
53- bool SegInsertion(Point & A1,Point & A2,Point & B1,Point & B2){
53+ bool SegInsertion(Point A1,Point A2,Point B1,Point B2){
5454 double c1 = Cross(A2-A1,B1-A1),c2 = Cross(A2-A1,B2-A1);
5555 double c3 = Cross(B2-B1,A1-B1),c4 = Cross(B2-B1,A2-B1);
5656 return dcmp(c1)*dcmp(c2) <0 && dcmp(c3)*dcmp(c4) <0;
5757}
58- bool onSegment(Point & P,Point & A,Point & B){
58+ bool onSegment(Point P,Point A,Point B){
5959 return dcmp(Cross(A-P,B-P))==0 && dcmp(Dot(A-P,B-P)) <0;
6060}
6161```
0 commit comments