poj 1269 Intersecting Lines (基础数学几何 直线位置)
程序员文章站
2022-03-02 10:21:06
...
给你两条直线(前几次wa都理解成线段了),求 位置状况
1.相离(如果是直线也就是平行)
2.共线
3.相交
附上AC代码
#include <stdio.h>
#include <math.h>
struct point{
double x , y;
};
struct line{
point l , r;
}t1,t2;
double xmul(point t,point l,point r){
double x1 , x2 , y1 , y2;
x1 = l.x - t.x; y1 = l.y - t.y;
x2 = r.x - t.x; y2 = r.y - t.y;
return x1 * y2 - x2 * y1;
}
point solve(point u1,point u2,point v1,point v2){
point ret = u1;
double t = ((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))
/((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
ret.x += (u2.x - u1.x) * t;
ret.y += (u2.y - u1.y) * t;
return ret;
}
int n;
int main(){
scanf("%d",&n);
printf("INTERSECTING LINES OUTPUT\n");
for(int i = 0 ; i < n ; i++){
scanf("%lf%lf%lf%lf",&t1.l.x,&t1.l.y,&t1.r.x,&t1.r.y);
scanf("%lf%lf%lf%lf",&t2.l.x,&t2.l.y,&t2.r.x,&t2.r.y);
if(xmul(t2.l,t1.l,t1.r)==0&&xmul(t2.r,t1.l,t1.r)==0){
printf("LINE\n");
}else if(xmul(t2.l,t1.l,t1.r)==xmul(t2.r,t1.l,t1.r)){
printf("NONE\n");
}else{
point ans = solve(t1.l,t1.r,t2.l,t2.r);
printf("POINT %.2lf %.2lf\n",ans.x,ans.y);
}
}
printf("END OF OUTPUT\n");
return 0;
}
推荐阅读
-
Intersecting Lines POJ - 1269(判断直线相交(交点)、平行、重合)
-
[POJ1269]Intersecting Lines(计算几何-叉积)
-
poj 1269 Intersecting Lines 【直线相交】
-
POJ 1269 Intersecting Lines (两直线位置关系+求交点)
-
POJ 1269 Intersecting Lines (叉积 -- 判断直线位置)
-
POJ 1269 Intersecting Lines (两直线位置关系)
-
【POJ - 1269 】Intersecting Lines (计算几何,直线间的位置关系)
-
简单几何(直线位置) POJ 1269 Intersecting Lines
-
POJ 1269 Intersecting Lines(计算几何) (两线段位置)
-
Intersecting Lines POJ - 1269(计算几何判断直线位置关系+求直线交点)