标签:
<span style="font-size:18px;">点到直线距离,直线相交交点,线段相交,向量点乘,向量叉乘,三角形有向面积,点到直线距离。</span>
struct point{ double x,y; point(double x=0,double y=0):x(x),y(y) { } }; typedef point V; struct circle{ point c; double r; circle(point c,double r):c(c),r(r){} point Point(double a){ return point(c.x+cos(a)*r,+c.y+sin(a)*r); } }; struct line{ point c; V v; }; V operator + (V a,V b){ return V(a.x+b.x,a.y+b.y);} V operator - (V a,V b){ return V(a.x-b.x,a.y-b.y);} V operator * (V a,double p){return V(a.x*p,a.y*p);} V operator / (V a,double p){return V(a.x/p,a.y/p);} bool operator < (const V& a,const V& b){ return a.x<b.x||(a.x==b.x&&a.y<b.y); } const double eps = 1e-10; int dcmp(double x){ if(fabs(x)<eps) return 0; else return x<0?-1:1; } bool operator == (const point& a,const point& b){ return dcmp(a.x-b.x)==0&&dcmp(a.y-b.y)==0; } double dot(V a,V b){return a.x*b.x+a.y*b.y; } double length(V a){return sqrt(dot(a,a));} double angle(V a,V b){return acos(dot(a,b)/length(a)/length(b)); } double cross(V a,V b){return a.x*b.y-a.y*b.x; } double area2(point a,point b,point c){return cross(b-a,c-a); } /*two line change point返回两线交点(保证有唯一交点)*/ point twolineispoint(point p,V v,point q,V w){ V u=p-q; double t=cross(w,u)/cross(v,w); return p+v*t; } /*线段是否相交*/ bool segmentmeet(point a1,point a2,point b1,point b2){ double c1=cross(a2-a1,b1-a1),c2=cross(a2-a1,b2-a1), c3=cross(b2-b1,a1-b1),c4=cross(b2-b1,a1-b1); return dcmp(c1)*dcmp(c2)<0&&dcmp(c3)*dcmp(c4)<0; } /*点到直线距离*/ point pointtoline(point p,point a,point b){ V v1=b-a,v2=p-a; return fabs(cross(v1,v2))/length(v1); }
标签:
原文地址:http://blog.csdn.net/wangzhen_yu/article/details/44177755