判断两条线段是否相交的方法

 1  struct  pos
 2  {
 3        double  x ;
 4        double  y ;
 5  };
 6  struct  line
 7  {
 8       pos st ;
 9       pos end ;
10  };
11  int  n ;
12 
13      
14  double  Multiply(pos p1, pos p2, pos p0)  
15  {  
16        return  ( (p1.x  -  p0.x)  *  (p2.y  -  p0.y)  -  (p2.x  -  p0.x)  *  (p1.y  -  p0.y) );  
17  }   
18      
19  bool  iscross(line L1, line L2)  
20  {  
21        return ( (max(L1.st.x,   L1.end.x)  >=  min(L2.st.x, L2.end.x))  &&   
22           (max(L2.st.x,   L2.end.x)  >=  min(L1.st.x, L1.end.x))  &&   
23           (max(L1.st.y,   L1.end.y)  >=  min(L2.st.y, L2.end.y))  &&   
24           (max(L2.st.y,   L2.end.y)  >=  min(L1.st.y, L1.end.y))  &&   
25           (Multiply(L2.st, L1.end, L1.st)  *  Multiply(L1.end, L2.end, L1.st)  >=   0 &&   
26           (Multiply(L1.st, L2.end, L2.st)  *  Multiply(L2.end, L1.end, L2.st)  >=   0 )  
27           );  
28  }
29 
30 


转载于:https://www.cnblogs.com/vivyli/archive/2010/02/05/1664087.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值