线段相交 c语言,c++求两个线段的交点

#include

#include

using namespace std;

struct point

{

double x;

double y;

};

struct segment{

point start;

point end;

};

double multi(point a,point b,point c){

return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);

}

int across(segment v1,segment v2){

if(max(v1.start.x,v1.end.x)>=min(v2.start.x,v2.end.x)&&

max(v2.start.x,v2.end.x)>=min(v1.start.x,v1.end.x)&&

max(v1.start.y,v1.end.y)>=min(v2.start.y,v2.end.y)&&

max(v2.start.y,v2.end.y)>=min(v1.start.y,v1.end.y)&&

multi(v2.start,v1.end,v1.start)*multi(v1.end,v2.end,v1.start)>0&&

multi(v1.start,v2.end,v2.start)*multi(v2.end,v1.end,v2.start)>0)

return 1;

return 0;

}

point * intersection(s

你可能感兴趣的:(线段相交,c语言)