#include<stdio.h> int main() { double x,y,x0,y0,x1,y1,x2,y2,x3,y3,k1,k2; scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x0,&y0,&x1,&y1,&x2,&y2,&x3,&y3); k1=(y0-y1)/(x0-x1); k2=(y2-y3)/(x2-x3); x=(k1*x0-k2*x2+y2-y0)/(k1-k2); y=y0+(x-x0)*k1; printf("%lf %lf\n",x,y); return 0; }
#include<stdio.h> int main() { double x,y,x0,y0,x1,y1,x2,y2,x3,y3,k1,k2; scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x0,&y0,&x1,&y1,&x2,&y2,&x3,&y3); k1=(y0-y1)/(x0-x1); k2=(y2-y3)/(x2-x3); x=(k1*x0-k2*x2+y2-y0)/(k1-k2); y=y0+(x-x0)*k1; if ( ( ( (x>x0)&&(x<x1))&&( (y>y0)&&(y<y1) )||( (x<x0)&&(x>x1))&&( (y<y0)&&(y>y1) ) )&& ( ( (x>x2)&&(x<x3))&&( (y>y2)&&(y<y3) )||( (x<x2)&&(x>x3))&&( (y<y2)&&(y>y3) ) ) ) { printf("该两条线段相交\n"); printf("%lf %lf\n",x,y); } else printf("该两条线段不相交\n"); return 0; }
[此贴子已经被作者于2020-7-29 08:28编辑过]