矩形重叠

看过某司一道笔试题:给\(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. thinkphp中array_diff运行无效 Invalid opcode 153/1/8

    经本人查证,发现是thinkPHP优化导致的与array_diff冲突.thinkPHP 报的错:Invalid opcode 153/1/8.有谁知道原理的,说说,让俺也明白.

  2. Linux(Fedora)系统下配制8086汇编环境

    1.到www,nasm.us下载nasm 2.解压并安装nasm #tar -xzvf nasm-2.11.08.tar.gz #cd nasm-2.11.08 #./configure #make ...

  3. Spring Boot 和 Spring Cloud 应用内存如何管理?

    在整体应用架构中,非生产环境情况下,一般 1GB 或者 2GB 的 RAM 就足够了.如果我们将这个应用程序划分为 20 或 30 个独立的微服务,那么很难期望 RAM 仍将保持在 1GB 或 2GB ...

  4. 常用App用户体验找茬

    冯晓云: 哔哩哔哩手机客户端:视频播放只允许横屏全屏:还有长视频的“5分钟诅咒”,遇到网速不好的时候是个大写的悲剧: 必应词典UWP版本:主页新闻链接跳转后,一些页面不支持划词取译,当然本身各个页面也 ...

  5. stand up meeting 12/9/2015

    part 组员 今日工作 工作耗时/h 明日计划 工作耗时/h UI 冯晓云  --------------    --  -----------  -- PDF Reader 朱玉影 SDK终于差不 ...

  6. Ubuntu搭建Redis 集群

    1.源码编译 查看需要下载版本:http://download.redis.io/releases/ 本人保存路径:/usr/local/soft/ wget http://download.redi ...

  7. 19.SpringCloud实战项目-SpringCloud整合Alibaba-Nacos配置中心

    SpringCloud实战项目全套学习教程连载中 PassJava 学习教程 简介 PassJava-Learning项目是PassJava(佳必过)项目的学习教程.对架构.业务.技术要点进行讲解. ...

  8. Linux学习笔记(四)帮助命令

    帮助命令 man info help --help man 英文原意:format and display the on-line manual pages 功能:显示联机帮助手册 语法:man 选项 ...

  9. Apache solr velocity模块 漏洞复现

    0x01 Solr简单介绍 Solr是建立在Apache Lucene ™之上的一个流行.快速.开放源代码的企业搜索平台. Solr具有高度的可靠性,可伸缩性和容错能力,可提供分布式索引,复制和负载平 ...

  10. 排序1 - 选择排序 & 插入排序

    请原谅我没有按照之前图片的分类来介绍排序算法,先说最简单的两种排序算法(冒泡略过),选择排序和插入排序,之前老是容易记混.默认输出升序的序列啊,哈哈. 选择排序 对于输入长度为n的数组,一共比较n-1 ...