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,其左上角的坐标为 ( ...
随机推荐
- SqlSever基础 union all 联合查询,简单的组合 两个查询结果拼在一起
镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...
- van Emda Boas
van Emda Boas维护了一个整数集合[0,Max)(无重复),其中Max必须等于2的正整数次幂.它支持以下操作:(1)插入一个数字;(2)删除一个数字:(3)询问某一个数字在不在这个集合中:( ...
- BZOJ 1513 [POI2006]Tet-Tetris 3D
题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1513 题意:三维空间,有一些立方体在垂直下落.立方体的左下角坐标(x,y)以及长宽 ...
- SQL查看一张表中是否存在记录
今天在QQ群众讨论到一个问题,记录下下来,一边以后用的时候可以翻阅 总结除了三种方法 --方法1,,这一种方法不行,,错误的认识了,@@ROWCOUNT,,,唉,,学艺不精,,丢人啊 SELECT T ...
- 使用OmniGraffle制作原型图
原型图设计是一个艺术创作的过程,所以我们应当使用能够提高工作效率.激发创作灵感的工具,让工具为创作服务,而不是为创作去学习如何使用工具.从这一点上说,我觉得Mac下的很多软件做的非常好,OmniGra ...
- Web开发, 跳转时出现java.lang.ClassNotFoundException
发生这种状况一般都是由于类找不到,要么是web.xml没有配对位置,要么是类没有放好
- SQL Server小技巧【1】
1.SQL防止修改数据时引起多用户并发,当一条数据被一个用户锁定的时候其他用户将无法修改,除非将其释放. UPDATE TABLENAME WITH(ROWLOCK) SET 字段='Value' W ...
- nginx使用ssl模块配置HTTPS支持
默认情况下ssl模块并未被安装,如果要使用该模块则需要在编译时指定–with-http_ssl_module参数,安装模块依赖于OpenSSL库和一些引用文件,通常这些文件并不在同一个软件包中.通常这 ...
- Java、fileless恶意软件威胁桌面安全
工作原理:用户访问一个受侵的网站,不小心下载了最新类型的恶意软件.如果你的杀毒软件运行良好的话,就会阻止下载,至少能够检测到并隔离硬盘上的入侵文件.但是如果硬盘上没有文件监测呢?如果恶意软件只入侵内存 ...
- Spring读书笔记-----使用Spring容器(二)
一.使用ApplicationContext 前面介绍了,我们一般不会使用BeanFactory实例作为Spring容器,而是使用ApplicationContext实例作为容器,它增强了BeanFa ...