int on_a_line(double ax,double ay,double bx,double by,double cx,double cy) { double dx1,dy1,dx2,dy2
int on_a_line(double ax,double ay,double bx,double by,double cx,double cy) { double dx1,dy1,dx2,dy2
上述代码能证明 闪电共线
#include
#define DELTA 1e-9
int on_a_line(double ax,double ay,double bx,double by,double cx,double cy)
{
double dx1,dy1,dx2,dy2,res;
dx1=bx-ax;dy1=by-ay;dx2=cx-bx;dy2=cy-by;res=dx1*dy2-dy2*dx1;
return res-DELTA;
}
int same(double p1x,double p1y,double p2x,double p2y,double ax,double ay,double bx,double by)
{
double dx,dy,dx1,dy1,dx2,dy2,res;
dx=bx-ax;dy=by-ay;dx1=p1x-ax;dy1=p1y-ay;dx2=p2x-bx;dy2=p2y-by;res=(dx*dy1-dy*dx1)*(dx*dy2-dy*dx2);
return res>0;
}
int main(){
double px,py,ax,ay,bx,by,cx,cy;
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&px,&py,&ax,&ay,&bx,&by,&cx,&cy);
if(on_a_line(ax,ay,bx,by,cx,cy)) printf("delegate\n"); else if(!same(px,py,ax,ay,bx,by,cx,cy)||!same(px,py,bx,by,ax,ay,cx,cy)||!same(px,py,cx,cy,ax,ay,bx,by)) printf("out\n");
else if(on_a_line(px,py,bx,by,cx,cy)||on_a_line(px,py,ax,ay,cx,cy)||on_a_line(px,py,ax,ay,bx,by)) printf("on\n");
else printf("in\n");
return 0;
}
能.这里用到数学上的一个证明方法:若p1,p2,p3为平面上的三点,则三点共线的充要条件为向量:P1XP2=0,其中P1=p1-p2,P2=p2-p3.具体请参考相关数学教材.至于return语句为什么不返回res==0,这里主要涉及到程序所要求的精...