Intersecting Lines POJ - 1269

题目链接:Intersecting Lines

思路

题意:给出你两条直线,求出这两条直线的关系,平行输出NONE,重合输出LINE,相交输出交点POINT x y
模板题,理解直线关系的求法即可。

直线与直线的位置关系

	//`点和直线关系`
	//`1  在左侧`
	//`2  在右侧`
	//`3  在直线上`
	int relation(Point p) {
		int c = sgn((p - s) ^ (e - s));
		if (c < 0)return 1;
		else if (c > 0)return 2;
		else return 3;
	}
	//`两向量平行(对应直线平行或重合)`
	bool parallel(Line v) {
		return sgn((e - s) ^ (v.e - v.s)) == 0;
	}
	//`两直线关系`
	//`0 平行`
	//`1 重合`
	//`2 相交`
	int linecrossline(Line v) {
		if ((*this).parallel(v))
			return v.relation(s) == 3;
		return 2;
	}

主函数

int main(){
	int t;
	scanf("%d",&t);
	puts("INTERSECTING LINES OUTPUT");
	while(t--){
		double x1,y1,x2,y2,x3,y3,x4,y4;
		scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
		Line t1,t2;
		t1.s.x=x1;	t1.s.y=y1;
		t1.e.x=x2;	t1.e.y=y2;
		
		t2.s.x=x3;	t2.s.y=y3;
		t2.e.x=x4;	t2.e.y=y4;
		int flag=t1.linecrossline(t2);
		if(flag==0)	puts("NONE");
		else if(flag==1)	puts("LINE");
		else if(flag==2){
			Point temp=t1.crosspoint(t2);
			printf("POINT %.2f %.2f\n",temp.x,temp.y);
		}
	}
	puts("END OF OUTPUT");
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值