Rectangle Intersection Test (with C#) by Sebastian Krysmanski
http://manski.net/2011/05/rectangle-intersection-test-with-csharp/

/// <summary>
/// Does axis separation test for a convex quadrilateral.
/// </summary>
/// <param name="x1">Defines together with x2 the edge of quad1 to be checked whether its a separating axis.</param>
/// <param name="x2">Defines together with x1 the edge of quad1 to be checked whether its a separating axis.</param>
/// <param name="x3">One of the remaining two points of quad1.</param>
/// <param name="otherQuadPoints">The four points of the other quad.</param>
/// <returns>Returns <c>true</c>, if the specified edge is a separating axis (and the quadrilaterals therefor don't
/// intersect). Returns <c>false</c>, if it's not a separating axis.</returns>
bool DoAxisSeparationTest(Point x1, Point x2, Point x3, Point[] otherQuadPoints) {
  Vector vec = x2 - x1;
  Vector rotated = new Vector(-vec.Y, vec.X);
  bool refSide = (rotated.X * (x3.X - x1.X)
         + rotated.Y * (x3.Y - x1.Y)) >= ;
  foreach (Point pt in otherQuadPoints) {
    bool side = (rotated.X * (pt.X - x1.X)
          + rotated.Y * (pt.Y - x1.Y)) >= ;
    if (side == refSide) {
      // At least one point of the other quad is one the same side as x3. Therefor the specified edge can't be a
      // separating axis anymore.
      return false;
    }
  }
  // All points of the other quad are on the other side of the edge. Therefor the edge is a separating axis and
  // the quads don't intersect.
  return true;
}

Rectangle Intersection Test (with C#)的更多相关文章

  1. Cesium原理篇:5最长的一帧之影像

    如果把地球比做一个人,地形就相当于这个人的骨骼,而影像就相当于这个人的外表了.之前的几个系列,我们全面的介绍了Cesium的地形内容,详见: Cesium原理篇:1最长的一帧之渲染调度 Cesium原 ...

  2. opencv基本的数据结构(转)

    DataType : 将C++数据类型转换为对应的opencv数据类型 enum { CV_8U=0, CV_8S=1, CV_16U=2, CV_16S=3, CV_32S=4, CV_32F=5, ...

  3. 使用Laya引擎开发微信小游戏(下)

    本文由云+社区发表 6. 动画 6.1 创建伞兵对象 在src目录下创建一个新目录role,用来存放游戏中角色. 在role里创建一个伞兵Soldier.ts对象文件. module role{ ex ...

  4. OpenCV常用数据类型

    Point 二维点坐标(x,y) typedef Point3_<int> Point3i; typedef Point3_<float> Point3f; typedef P ...

  5. 【opencv基础】Rect类的神奇用法

    前言 最近看github上源码发现对两个cv::Rect使用相与(&)操作,猛地感觉自己蒙啦,Rect类还有这种神奇用法?!翻看opencv官网Rect类,果然如此! opencv中Rect类 ...

  6. AS3 在不规则区域内拖动

    原理: 1.确保拖动对象在鼠标点上,如果不确定会出现瞬间移动的感觉 2.确保触碰到非通行区域,跳回到没触碰的点 源码: import flash.events.MouseEvent; import f ...

  7. [ActionScript 3.0] 像素级碰撞检测

    package { import flash.display.BitmapData; import flash.display.BlendMode; import flash.display.Disp ...

  8. opencv 基本数据结构

    转自:http://www.cnblogs.com/guoqiaojin/p/3176692.html opencv 基本数据结构   DataType : 将C++数据类型转换为对应的opencv数 ...

  9. JAVA小游戏之两个物体碰撞产生的碰撞检测

    首先必须了解两个物体,在移动时,会有怎样的效果,比如沪我们小时候耍过的坦克大战.看起来很简单,但是写起代码来,复杂的要多: 下面举个例子: // 构造一个新的 Rectangle,其左上角的坐标为 ( ...

随机推荐

  1. SqlSever基础 convert 将类型为字符的一列转成Int类型后进行排序

    镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...

  2. 【leetcode❤python】 58. Length of Last Word

    #-*- coding: UTF-8 -*-#利用strip函数去掉字符串去除空格(其实是去除两边[左边和右边]空格)#利用split分离字符串成列表class Solution(object):   ...

  3. shell 随机从文件中抽取若干行

    shuf -n5 main.txt sort -R main.txt | head -5 awk -vN=5 -vC="`wc -l file`" 'BEGIN{srand();w ...

  4. servlet&jsp高级:第一部分

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  5. C语言文法定义与C程序的推导过程

    program à external_declaration | program external_declaration <程序> ->  <外部声明> |  < ...

  6. zoj 1453 Surround the Trees(凸包求周长)

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=453 Time Limit: 2 Seconds      Memory ...

  7. Deep Learning: Activation Function

    Sigmoid Function ReLU Function Tanh Function

  8. C# 线程(三):如何操纵一个线程

    From : http://kb.cnblogs.com/page/42529/ 下面我们就动手来创建一个线程,使用Thread类创建线程时,只需提供线程入口即可.(线程入口使程序知道该让这个线程干什 ...

  9. JUnit 简单的使用 (学习转载)

    JUnit4使用Java5中的注解(annotation),以下是JUnit4常用的几个annotation: @Before:初始化方法   对于每一个测试方法都要执行一次(注意与BeforeCla ...

  10. c++复习一:复数运算的简单实现。

    复数运算的简单实现. 程序很简单了.基本忘光了复数,重新了解了基本概念.如何在平面表示一个复数,复数的长度|x|=开根 a^2+b^2.和四则运算. 程序基本点: 封装和抽象: 1)封装成员数据,私有 ...