Skip to content

Commit b713a5e

Browse files
committed
修改函数参数引用
1 parent 405bc6d commit b713a5e

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

computationGeometry/planeGeometry.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
21
struct Point{
32
double x,y;
4-
Point(double _x,double _y):x(_x),y(_y){}
5-
}
3+
Point(double _x=0,double _y=0):x(_x),y(_y){}
4+
};
65
typedef Point Vector;
76

8-
Vector operator + (Vector &A,Vector & B){return Vector(A.x+B.x,A.y+B.y);}
9-
Vector operator - (Vector &A,Vector & B){return Vector(A.x-B.x,A.y-B.y);}
10-
Vector operator * (Vector &A,double a){return Vector(a*A.x,a*B.x);}
11-
Vector operator / (Vector &A,double p){return A*(1/p);}
12-
bool operator < (const Point & A,const Point & B){return mp(A.x,A.y) < mp(B.x,B.y);}
13-
bool operator == (const Point &A,const Point & B){return !dcmp(A.x-B.x) && !dcmp(A.y-B.y);}
14-
double Dot(Vector & A, Vector & B){return A.x*B.x-A.y*B.y;}
7+
Vector operator + (Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);}
8+
Vector operator - (Vector A,Vector B){return Vector(A.x-B.x,A.y-B.y);}
9+
Vector operator * (Vector A,double a){return Vector(a*A.x,a*A.y);}
10+
Vector operator / (Vector A,double p){return A*(1/p);}
11+
bool operator < (const Point A,const Point B){return mp(A.x,A.y) < mp(B.x,B.y);}
12+
bool operator == (const Point A,const Point B){return !dcmp(A.x-B.x) && !dcmp(A.y-B.y);}
13+
double Dot(Vector A, Vector B){return A.x*B.x-A.y*B.y;}
1514
double Length(Vector & A){return sqrt(Dot(A,A));}
1615
double Angle(Vector &A,Vector & B){return acos(Dot(A,B)/Length(A)/Length(B));}
1716
Vector Rotate(Vector &A,double rad){return Vector(A.x*cos(rad)-sin(rad)*A.y,A.x*sin(rad)+A.y*cos(rad));}
1817
Vector Normal(Vector A){//A 的单位法向量
1918
double L = Length(A);
2019
return Vector(-A.y/L,A.x/L);
2120
}
22-
double Cross(Vector &A,Vector &B){return A.x*B.y-A.y*B.x;}
23-
double Area2(Point &A,Point & B,Point &C){return Cross(B-A,C-A);}
24-
//直线和点
21+
double Cross(Vector A,Vector B){return A.x*B.y-A.y*B.x;}
22+
double Area2(Point A,Point B,Point C){return Cross(B-A,C-A);}
23+
2524
Point GetLineIntersection(Point &P,Vector & v, Point & Q,Vector w){
2625
//计算交点,当v,w平行时无效
2726
Point u = P-Q;
@@ -34,9 +33,9 @@ double Dis2Line(Point &P,Point & A,Point & B){
3433
Vector u2 = B-A;
3534
return abs(Cross(u1,u2)/Length(u2));
3635
}
37-
double GetLineProjection(Point &P,Point &A,Point & A){
36+
Point GetLineProjection(Point &P,Point &A,Point & B){
3837
//the projection Point Q of P to Line A,B;
39-
Vector u = B-A;
38+
Vector v = B-A;
4039
return A+ v*(Dot(v,P-A)/Dot(v,v));
4140
}
4241
bool SegInsertion(Point &A1,Point &A2,Point &B1,Point &B2){
@@ -47,11 +46,10 @@ bool SegInsertion(Point &A1,Point &A2,Point &B1,Point &B2){
4746
bool onSegment(Point & P,Point &A,Point &B){
4847
return dcmp(Cross(A-P,B-P))==0 && dcmp(Dot(A-P,B-P)) <0;
4948
}
50-
//多边形
5149

50+
//多边形
5251

53-
double polygonArea(Point *P,int n){
54-
//多边形面积P为按顺序给出的点
52+
double polygonArea(Point *p,int n){
5553
double area =0;
5654
for(int i=1 ; i<n-1 ; ++i)
5755
area += Cross(p[i]-p[0],p[i+1]-p[0]);

0 commit comments

Comments
 (0)