Rectangle Intersection Test (with C#)
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#)的更多相关文章
- Cesium原理篇:5最长的一帧之影像
如果把地球比做一个人,地形就相当于这个人的骨骼,而影像就相当于这个人的外表了.之前的几个系列,我们全面的介绍了Cesium的地形内容,详见: Cesium原理篇:1最长的一帧之渲染调度 Cesium原 ...
- opencv基本的数据结构(转)
DataType : 将C++数据类型转换为对应的opencv数据类型 enum { CV_8U=0, CV_8S=1, CV_16U=2, CV_16S=3, CV_32S=4, CV_32F=5, ...
- 使用Laya引擎开发微信小游戏(下)
本文由云+社区发表 6. 动画 6.1 创建伞兵对象 在src目录下创建一个新目录role,用来存放游戏中角色. 在role里创建一个伞兵Soldier.ts对象文件. module role{ ex ...
- OpenCV常用数据类型
Point 二维点坐标(x,y) typedef Point3_<int> Point3i; typedef Point3_<float> Point3f; typedef P ...
- 【opencv基础】Rect类的神奇用法
前言 最近看github上源码发现对两个cv::Rect使用相与(&)操作,猛地感觉自己蒙啦,Rect类还有这种神奇用法?!翻看opencv官网Rect类,果然如此! opencv中Rect类 ...
- AS3 在不规则区域内拖动
原理: 1.确保拖动对象在鼠标点上,如果不确定会出现瞬间移动的感觉 2.确保触碰到非通行区域,跳回到没触碰的点 源码: import flash.events.MouseEvent; import f ...
- [ActionScript 3.0] 像素级碰撞检测
package { import flash.display.BitmapData; import flash.display.BlendMode; import flash.display.Disp ...
- opencv 基本数据结构
转自:http://www.cnblogs.com/guoqiaojin/p/3176692.html opencv 基本数据结构 DataType : 将C++数据类型转换为对应的opencv数 ...
- JAVA小游戏之两个物体碰撞产生的碰撞检测
首先必须了解两个物体,在移动时,会有怎样的效果,比如沪我们小时候耍过的坦克大战.看起来很简单,但是写起代码来,复杂的要多: 下面举个例子: // 构造一个新的 Rectangle,其左上角的坐标为 ( ...
随机推荐
- XMPP Server
XMPPFramework,编译失败,@import libxmlSimu后提示:Module 'libxmlSimu' not found XMPP协议实现原理介绍 XMPP协议学习笔记 四.地址格 ...
- BZOJ 3564 信号增幅仪
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3564 题意:给出平面上n个点,画出一个椭圆,椭圆的长轴是短轴的p倍,且长轴的方向为x轴逆时 ...
- Mysql 导入 MSSQL
.安装mysql数据库的ODBC驱动,mysql-connector-odbc--win32.msi .打开控制面板\管理工具\数据源ODBC,在用户DSN中添加一个MySQL ODBC .51数据源 ...
- UVA 10564 十 Paths through the Hourglass
Paths through the Hourglass Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & % ...
- CocoaPods的安装[转载]
[转载] 原地址http://www.tuicool.com/articles/7VvuAr3 觉得很好,很有用 iOS 最新版 CocoaPods 的安装流程 1.移除现有Ruby默认源 $gem ...
- [转]GameObject的Active与InActive
GameObject的Active与InActive 1.Script可以控制InActive的GameObject,但前提是Script所依附的GameObject不能是InActive,一旦为In ...
- 【翻译】《深入解析windows操作系统第6版下册》第10章:内存管理
[翻译]<深入解析windows操作系统第6版下册>第10章:内存管理(第一部分) [翻译]<深入解析windows操作系统第6版下册>第10章:内存管理(第二部分) [翻译] ...
- oracle命令识记
连接数据库 sqlplus /nolog; conn / as sysdba; set ORACLE_SID=实例名; 查看表结构命令 select table_name from user_tabl ...
- hdu 1247 map的使用
http://acm.hdu.edu.cn/showproblem.php?pid=1247 Hat’s Words Time Limit: 2000/1000 MS (Java/Others) ...
- iOS - Swift NSRect 位置和尺寸
前言 结构体,这个结构体用来表示事物的坐标点和宽高度. public typealias NSRect = CGRect public struct CGRect { public var origi ...