T9的空间

You will never walk alone!

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  69 随笔 :: 0 文章 :: 28 评论 :: 0 Trackbacks

直接用直线方程Ax+By+C=0来判断的

Source Code

Problem: 
1269  User: Torres 
Memory: 196K  Time: 0MS 
Language: C
++  Result: Accepted 

Source Code 
#include
<iostream>
#include
<cmath>
using namespace std;
typedef 
struct point{
    
double x,y;
    point(
double a=0,double b=0)
    
{x=a;y=b;}
}
point;
typedef 
struct line{
    
double A,B,C;
    line(point a,point b)
    
{
        A
=-(b.y-a.y);
        B
=b.x-a.x;
        C
=a.x*(b.y-a.y)-a.y*(b.x-a.x);
    }

}
line;
point l12;
//要求的交点
int isintersect(line l1,line l2)
{
    
if(l1.A*l2.B==l2.A*l1.B){
        
if(l1.A==0&&l2.A==0&&l1.C*l2.B==l2.C*l1.B||
            l1.B
==0&&l2.B==0&&l1.C*l2.A==l2.C*l1.A)
            
return 1;
        
else if(l1.A!=0&&l2.B!=0&&l1.B*l2.C==l1.C*l2.B)return 1;
        
else return -1;
    }

    
else {
        l12.x
=(l2.B*l1.C-l1.B*l2.C)/(l2.A*l1.B-l1.A*l2.B);
        l12.y
=(l2.A*l1.C-l1.A*l2.C)/(l1.A*l2.B-l2.A*l1.B);
        
return 0;
    }

}

int main()
{
    
int ca;
    point s1,e1,s2,e2;
    
//freopen("in.txt","r",stdin);

    scanf(
"%d",&ca);
        printf(
"INTERSECTING LINES OUTPUT\n");
    
while(ca--){
        scanf(
"%lf%lf%lf%lf",&s1.x,&s1.y,&e1.x,&e1.y);
        scanf(
"%lf%lf%lf%lf",&s2.x,&s2.y,&e2.x,&e2.y);
        line l1(s1,e1),l2(s2,e2);
        
int flag=isintersect(l1,l2);
        
if(flag==-1)printf("NONE\n");
        
else if(flag==1)printf("LINE\n");
        
else printf("POINT %.2lf %.2lf\n",l12.x,l12.y);
    }

    printf(
"END OF OUTPUT\n");
    
return 0;
}


posted on 2008-09-24 21:29 Torres 阅读(218) 评论(0)  编辑 收藏 引用 所属分类: Computation Geometry

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理