zoukankan      html  css  js  c++  java
  • 判断两矩形是否相交

     1 //判断矩形是否相交
    2 bool FMath::IsRectIntersect(const FRect& rect1, const FRect& rect2)
    3 {
    4 bool bResult = true;
    5
    6 double dWidthRectA;
    7 double dHeightRectA;
    8
    9 double dWidthRectB;
    10 double dHeightRectB;
    11
    12 //方便计算,中心点坐标为实际坐标的2倍
    13 CPoint centerRectA;
    14 CPoint centerRectB;
    15
    16 //bottom的y坐标比top的大
    17 dWidthRectA = rect1.GetBottomRight().GetX() - rect1.GetTopLeft().GetX();
    18 dHeightRectA = rect1.GetBottomRight().GetY() - rect1.GetTopLeft().GetY();
    19
    20 dWidthRectB = fabs(rect2.GetBottomRight().GetX() - rect2.GetTopLeft().GetX());
    21 dHeightRectB = fabs(rect2.GetBottomRight().GetY() - rect2.GetTopLeft().GetY()) ;
    22
    23 centerRectA.x = GetDoubleInt(rect1.GetTopLeft().GetX()/2 + rect1.GetBottomRight().GetX()/2);
    24 centerRectA.y = GetDoubleInt(rect1.GetTopLeft().GetY()/2 + rect1.GetBottomRight().GetY()/2);
    25
    26 centerRectB.x = GetDoubleInt(rect2.GetTopLeft().GetX()/2 + rect2.GetBottomRight().GetX()/2);
    27 centerRectB.y = GetDoubleInt(rect2.GetTopLeft().GetY()/2 + rect2.GetBottomRight().GetY()/2);
    28
    29
    30 //判断两个矩形的中心坐标的水平和垂直距离
    31 if ( (fabs(double(centerRectA.x - centerRectB.x)) <= (dWidthRectA + dWidthRectB))
    32 && (fabs(double(centerRectA.y - centerRectB.y)) <= (dHeightRectA + dHeightRectB)) )
    33 {
    34 bResult = true;
    35 }
    36 else
    37 {
    38 bResult = false;
    39 }
    40
    41 return bResult;
    42
    43 }
  • 相关阅读:
    Kafka的Controller
    kafka 为什么能那么快?高效读写数据,原来是这样做到的
    kafka的消费
    kafka的数据同步原理ISR、ACK、LEO、HW
    kafka 工作流程及文件存储机制
    kafka的简单架构
    Sangfor AC在线用户显示大量公网IP
    H3C抓包命令
    Android- 音量控制
    call指令的地址是怎么计算出来的。
  • 原文地址:https://www.cnblogs.com/hbf369/p/2281554.html
Copyright © 2011-2022 走看看