矩形重叠

看过某司一道笔试题:给\(n\)个矩形左下和右上坐标(不能斜放),求重叠最多处矩形个数。

这道题本身不难:可以遍历所有矩形边界组成的点,计算该点被多少矩形包围,从而选出最大值。

由此引申出一个问题:判断两个矩形重叠

  • 如果正向思考,会有很多种情况:包含、重叠某个角、交叉...

    那么如果逆向思考:什么情况两个矩形不重叠?无非就是\(A(p_1, p_2)\)在\(B(p_3, p_4)\)的上下左右:

\[(p_2.y>=p_3.y)\vee(p_4.y>=p_1.y)\vee(p_3.x>=p_2.x)\vee(p_1.x>=p_4.x)
\]

取反后用De Morgan's law化简就是重叠的情况:

\[(p_2.y<p_3.y)\wedge(p_4.y<p_1.y)\wedge(p_3.x<p_2.x)\wedge(p_1.x<p_4.x)
\]

线段交点

联立方程组求解当然没问题,也可以用几何的方法解:



易知,\(\frac{AO}{BO}=\frac{AE}{BF}=\frac{S_{ACD}}{S_{BCD}}\),两个三角形面积可以用叉积求得,又\(\vec{AO}=\frac{AO}{AB}\vec{AB}=\frac{AO}{AO+BO}\vec{AB}\),所以\(\vec{O'O}=\vec{O'A}+\vec{AO}\),即可求得\(O\)点坐标。

向量旋转



三角变换可得:

\[\vec b=(xcos\alpha-ysin\alpha,ycos\alpha+xsin\alpha)
\]

多边形面积



三角剖分:

\[S_{ABCDEF}=\frac{\vec{OA}\times\vec{OB}+\vec{OB}\times\vec{OC}+...+\vec{OF}\times\vec{OA}}{2}
\]

即:

\[S=A_n\times A_1+\sum_{i=1}^{n-1}A_i\times A_{i+1}=x_ny_1-y_nx_1+\sum_{i=1}^{n-1}x_iy_{i+1}-y_ix_{i+1}
\]

凸包

包围所有给定点并且周长最小的多边形。


reference

洛谷日报#142 计算几何初步

Computational Geometry的更多相关文章

  1. Computational Geometry Template_Polygon

    #include <stdlib.h> #include <math.h> #include <iostream> #define MAXN 1000 #defin ...

  2. Computational Geometry Template

    顿时觉得神清气爽!! #include <iostream> #include <math.h> #define eps 1e-8 #define zero(x) (((x)& ...

  3. 2D Circular Geometry Kernel ( Geometry Kernels) CGAL 4.13 -User Manual

    1 Introduction The goal of the circular kernel is to offer to the user a large set of functionalitie ...

  4. 2D and 3D Linear Geometry Kernel ( Geometry Kernels) CGAL 4.13 -User Manual

    1 Introduction CGAL, the Computational Geometry Algorithms Library, is written in C++ and consists o ...

  5. OpenSUSE下编译安装OpenFoam

    在不是Ubuntu系统下安装OpenFoam,需要采用编译安装的方式.以下以OpenSuSE为例进行编译安装. 1 软件包准备 需要下载两个程序包: OpenFOAM-4.x-version-4.1. ...

  6. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  7. 中国计算机学会CCF推荐国际学术会议

    中国计算机学会推荐国际学术会议 (计算机系统与高性能计算) 一.A类 序号 会议简称 会议全称 出版社 网址 1 ASPLOS Architectural Support for Programmin ...

  8. Visulalize Boost Voronoi in OpenSceneGraph

    Visulalize Boost Voronoi in OpenSceneGraph eryar@163.com Abstract. One of the important features of ...

  9. Visulalization Voronoi in OpenSceneGraph

    Visulalization Voronoi in OpenSceneGraph eryar@163.com Abstract. In mathematics a Voronoi diagram is ...

随机推荐

  1. 了解这5大K8S管理服务,为你节省50%的部署时间!

    Kubernetes已然成为IT世界的重要组成部分,并且仍在不断地发展壮大,现阶段,Kubernetes已经可以帮助企业进行微服务训练,加速企业数字化转型.尽管Kubernetes是一款如此令人印象深 ...

  2. 22.4 Extends --super 和 this 的区别

    /* * this和super的区别 this:当前对象的引用 调用子类的成员变量 调用子类的成员方法 在子类的构造方法第一行调用子类其他构造方法 super:子类对象的父类引用 调用父类的成员变量 ...

  3. NumPy学习2:基本运算

    数组相减: a = array([20, 30, 40, 50])print ab = arange(4)print bc = a-bprint c 结果: [20 30 40 50][0 1 2 3 ...

  4. webWMS开发过程记录(五)- 详细设计之系统界面框架设计

    界面区域划分 使用frameset分了上中下三个区域 上:显示系统名称和用户信息,以及一些提示信息(需通过Ajax定时更新提示信息),显示高度固定 中:再次使用frameset分成左右区域 左:显示导 ...

  5. lua使用笔记2:Linux 中安装php的lua扩展

    安装lua扩展的前提是lua已经安装好,如果没有安装,参照 1.http://pecl.php.net/package/lua 下载lua扩展 或者Linux下直接输入 wget http://pec ...

  6. python3购物车

    python3实现购物车小程序,优化后将程序分成函数,用文件注册和验证用户名密码. #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 20 ...

  7. web form常用控件

    表单元素一共12个分三大类 文本类<input type="text" />             文本框<input type="password& ...

  8. atom跨平台超好用的markdown实时预览

    https://atom.io/ sublime有预览markdown的插件,但仅限于每次在浏览器中预览,想要找一个能够实时在软件中预览的,终于发现了atom. 很多功能以插件的形式安装,theme也 ...

  9. Python - Python算法之冒泡算法的超简单实现

    [原创]转载请注明作者Johnthegreat和本文链接 冒泡排序在算法中算是最简单也最容易实现的,这里介绍一个非常简单实现的代码: def bubble_sort(ls): for first in ...

  10. 浅析Java7中的ConcurrentHashMap

    引入ConcurrentHashMap 模拟使用hashmap在多线程场景下发生线程不安全现象 import java.util.HashMap; import java.util.Map; impo ...