3、ointoperator-(constPoint&b)const{returnPoint(x-b.x,y-b.y);}Pointoperator*(doublea){returnPoint(x*a,y*a);}Pointoperator/(doublea){returnPoint(x/a,y/a);}doublelen2(){//返回长度的平方returnsqr(x)+sqr(y);}doublelen(){//返回长度returnsqrt(len2());}Pointchange_len(doubler){//转化为长度为r的向量doublel=len();
4、if(dcmp(l)==0)return*this;//零向量返回自身r/=l;returnPoint(x*r,y*r);}Pointrotate_left(){//顺时针旋转90度returnPoint(-y,x);}Pointrotate_right(){//逆时针旋转90度returnPoint(y,-x);}Pointrotate(Pointp,doubleang){//绕点p逆时针旋转angPointv=(*this)-p;doublec=cos(ang),s=sin(ang);returnPoint(p.x+v.x*c-v.y*s,p.y+v.x*
5、s+v.y*c);}Pointnormal(){//单位法向量doublel=len();returnPoint(-y/l,x/l);}};doublecross(Pointa,Pointb){//叉积returna.x*b.y-a.y*b.x;}doubledot(Pointa,Pointb){//点积returna.x*b.x+a.y*b.y;}doubledis(Pointa,Pointb){//两个点的距离Pointp=b-a;returnp.len();}doublerad_degree(doublerad){//弧度转化为角度returnrad/p
6、i*180;}doublerad(Pointa,Pointb){//两个向量的夹角returnfabs(atan2(fabs(cross(a,b)),dot(a,b)));}boolparallel(Pointa,Pointb){//向量平行doublep=rad(a,b);returndcmp(p)==0
7、
8、dcmp(p-pi)==0;}//************直线线段structLine{Points,e;//直线的两个点Line(){}Line(Point_s,Point_e):s(_s),e(_e){}//一个点和倾斜角确定直线Line(Point
9、p,doubleang){s=p;if(dcmp(ang-pi/2)==0){e=s+Point(0,1);}elsee=s+Point(1,tan(ang));}//ax+by+c=0确定直线Line(doublea,doubleb,doublec){if(dcmp(a)==0){s=Point(0,-c/b);e=Point(1,-c/b);}elseif(dcmp(b)==0){s=Point(-c/a,0);e=Point(-c/a,1);}else{s=Point(0,-c/b);e=Point(1,(-c-a)/b);}}voidinput(){s
10、.input();e.input();