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. android“设置”里的版本号

    在文件 packages/apps/Settings/src/com/android/settings/DeviceInfoSettings.java 中 setStringSummary(" ...

  2. 【leetcode❤python】Ransom Note

    #-*- coding: UTF-8 -*- class Solution(object):       def canConstruct(self, ransomNote, magazine):   ...

  3. ubuntu Linux 测试PHP却提示下载文件的解决办法

    ubuntu Linux 测试PHP却提示下载文件的解决办法   一般这种情况都是在刚刚开始配置环境时出现的, 输入 sudo a2enmod php5  看提示如果出现“$ This module ...

  4. Lambda表达式之Python

    一.lambda函数 1.lambda函数基础: lambda函数也叫匿名函数,即,函数没有具体的名称,而用def创建的方法是有名称的.如下: """命名的foo函数&q ...

  5. Socket通信常用方法

    使用tcp协议,链接服务器的方法 /// <summary> /// 连接使用tcp协议的服务端 /// </summary> /// <param name=" ...

  6. 先来个xmpp学习连接

    http://my.oschina.net/SoulJa/blog?catalog=3340253&temp=1468228088114 http://my.oschina.net/iOSli ...

  7. hdu 1700 Points on Cycle(坐标旋转)

    http://acm.hdu.edu.cn/showproblem.php?pid=1700 Points on Cycle Time Limit: 1000/1000 MS (Java/Others ...

  8. C# DataGridView控件绑定数据后清空数据

    //1.this.dataGridView1.DataSource = null;//会将DataGridView的列也删掉 //2.this.dataGridView1.Columns.Clear( ...

  9. T-SQL over()函数在单个表中的聚合

    Sales.OrderValues是一个视图,在这里作为测试表. 现在想实现,每个订单的数据行新增两个列,totalvalue(所有订单的总金额),custtotalvalue(当前订单的custid ...

  10. Java中String,StringBuffer,StringBuilder的区别及其使用

    由于笔试面试经常会问到这个问题,所以在这里先把这些问题搞清楚. String:自JDK1.0开始即有,源码中对String的描述: "Strings are constant; their ...