c语言两个矩形相交部分坐标,c语言:编写程序判断两个平行于坐标轴的矩形是否相交...

匿名用户

1级

2014-10-30 回答

typedef struct RECTANGULAR

{

int x1;//平行于y轴的一条边坐标,下面同理

int y1;

int x2;

int y2;

}*prect_typedef,rect_typedef;

rect_typedef rect1,rect2;

//比较两个矩形,如果其中一个矩形的某一个顶点在另外一个矩形里面,说明两个相交,返回TURE

int compare_rect(prect_typedef rect1,prect_typedef rect2)

{

int ret_val = 0;

int i = 0;

if(rect2->x1 > rect2->x2)

{

//比较rect1 x1

if(rect1->x1 > rect2->x2 && rect1->x1 < rect2->x1)

{

if(rect2->y1 > rect2->y2)

{

//比较rect1 y1

if((rect1->y1 > rect2->y2 && rect1->y1 < rect2->y1))

{

return 1;

}

//比较rect1 y2

if((rect1->y2 > rect2->y2 && rect1->y2 < rect2->y1))

{

return 1;

}

}

else

{

//比较rect1 y1

if((rect1->y1 > rect2->y1 && rect1->y1 < rect2->y2))

{

return 1;

}

//比较rect1 y2

if((rect1->y2 > rect2->y1 && rect1->y2 < rect2->y2))

{

return 1;

}

}

}

//比较rect1 x2

if(rect1->x2 > rect2->x2 && rect1->x2 < rect2->x1)

{

if(rect2->y1 > rect2->y2)

{

//比较rect1 y1

if((rect1->y1 > rect2->y2 && rect1->y1 < rect2->y1))

{

return 1;

}

//比较rect1 y2

if((rect1->y2 > rect2->y2 && rect1->y2 < rect2->y1))

{

return 1;

}

}

else

{

//比较rect1 y1

if((rect1->y1 > rect2->y1 && rect1->y1 < rect2->y2))

{

return 1;

}

//比较rect1 y2

if((rect1->y2 > rect2->y1 && rect1->y2 < rect2->y2))

{

return 1;

}

}

}

}

else

{

//比较rect1 x1

if(rect1->x1 > rect2->x1 && rect1->x1 < rect2->x2)

{

if(rect2->y1 > rect2->y2)

{

//比较rect1 y1

if((rect1->y1 > rect2->y2 && rect1->y1 < rect2->y1))

{

return 1;

}

//比较rect1 y2

if((rect1->y2 > rect2->y2 && rect1->y2 < rect2->y1))

{

return 1;

}

}

else

{

//比较rect1 y1

if((rect1->y1 > rect2->y1 && rect1->y1 < rect2->y2))

{

return 1;

}

//比较rect1 y2

if((rect1->y2 > rect2->y1 && rect1->y2 < rect2->y2))

{

return 1;

}

}

}

//比较rect1 x2

if(rect1->x2 > rect2->x1 && rect1->x2 < rect2->x2)

{

if(rect2->y1 > rect2->y2)

{

//比较rect1 y1

if((rect1->y1 > rect2->y2 && rect1->y1 < rect2->y1))

{

return 1;

}

//比较rect1 y2

if((rect1->y2 > rect2->y2 && rect1->y2 < rect2->y1))

{

return 1;

}

}

else

{

//比较rect1 y1

if((rect1->y1 > rect2->y1 && rect1->y1 < rect2->y2))

{

return 1;

}

//比较rect1 y2

if((rect1->y2 > rect2->y1 && rect1->y2 < rect2->y2))

{

return 1;

}

}

}

}

return 0; //不相交

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值