POJ 1584 A Round Peg in a Ground Hole(点到直线距离,圆与多边形相交,多边形是否为凸)
来源:互联网 发布:白金数据 电影天堂 编辑:程序博客网 时间:2024/05/22 14:17
题意:给出一个多边形和一个圆,问是否是凸多边形,若是则再问圆是否在凸多边形内部。
分3步:
1、判断是否是凸多边形
2、判断点是否在多边形内部
3、判断点到各边的距离是否大于等于半径
上代码:
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>using namespace std;#define maxn 2000#define eps 10E-8struct Point{ double x, y; Point operator-(const Point &a) const { Point ret; ret.x = x - a.x; ret.y = y - a.y; return ret; }} point[maxn], peg;double pegr;int n;int dblcmp(double a){ if (fabs(a) < eps) return 0; return a >0?1 : -1;}double xmult(const Point &a, const Point &b){ return a.x * b.y - b.x * a.y;}void input(){ scanf("%lf%lf%lf", &pegr, &peg.x, &peg.y); for (int i =0; i < n; i++) scanf("%lf%lf", &point[i].x, &point[i].y); int t =0; int i =0; while (i < n && t ==0) { t = dblcmp(xmult(point[(i +1)%n] - point[i], point[(i +2)%n] - point[i])); i++; } if (t <0) reverse(point, point + n);}bool convex(){ for (int i =0; i < n; i++) if (dblcmp(xmult(point[(i +1)%n] - point[i], point[(i +2)%n] - point[(i +1)%n])) <0) return false; return true;}bool inconvex(){ for (int i =0; i < n; i++) if (dblcmp(xmult(point[(i +1)%n] - point[i], peg - point[(i +1)%n])) <=0) return false; return true;}double dist(const Point &a, const Point &b){ Point p; p = a - b; return sqrt(p.x * p.x + p.y * p.y);}bool ok(){ for (int i =0; i < n; i++) if (dblcmp(abs(xmult(peg - point[i], point[(i +1)%n] - point[i]))/dist(point[i], point[(i +1)%n]) - pegr) <0) return false; return true;}int main(){ while (scanf("%d", &n) != EOF) { if (n<3) break; input(); if (!convex()) printf("HOLE IS ILL-FORMED\n"); else if (!inconvex()||!ok()) printf("PEG WILL NOT FIT\n"); else printf("PEG WILL FIT\n"); } return 0;}
0 0
- POJ 1584 A Round Peg in a Ground Hole(点到直线距离,圆与多边形相交,多边形是否为凸)
- POJ 1584 A Round Peg in a Ground Hole(点到直线距离,多边形是否为凸)
- poj 1584 A Round Peg in a Ground Hole 多边形凸性判断,点与多边形位置关系,圆与多边形位置关系
- POJ 1584:A Round Peg in a Ground Hole _判断点是否在多边形内(5种方法)
- A Round Peg in a Ground Hole(POJ1584点在多边形内+是否为凸多边形)
- POJ 1584 A Round Peg in a Ground Hole(凸多边形判断+点与多边形的位置关系)
- POJ 1584 A Round Peg in a Ground Hole(凸包判定,多边形计算与判定)
- POJ A Round Peg in a Ground Hole <凸包判断以及点与多边形的相对位置>
- POJ-1584-A Round Peg in a Ground Hole-计算几何-凸多边形+多边形包含圆
- poj 1584 A Round Peg in a Ground Hole 判断多边形是否为凸多边形 + 圆心是否在凸多边形内 + 圆是否在凸多边形内部
- POJ 1584-A Round Peg in a Ground Hole(计算几何-凸包、点到线段距离)
- POJ1584 A Round Peg in a Ground Hole 判断多边形是否为凸多边形,判断凸多边形是否在圆内
- poj1584 A Round Peg in a Ground Hole 凸多边形判断 和多边形与圆的位置
- poj_1584 A Round Peg in a Ground Hole(凸包判断凸多边形+判断点在多边形内)
- POJ 1584 A Round Peg in a Ground Hole(是否凸包 && 圆是否在凸包内)
- poj 1584 A Round Peg in a Ground Hole(判断凸多边形+圆是否在凸多边形内)
- POJ 1584 A Round Peg in a Ground Hole 圆是否包含在凸包内
- POJ 1584 A Round Peg in a Ground Hole(判断凸多边形,点到线段最短距离)
- ListView.setOnItemClickListener无效问题的解决
- JAVA学习笔记(二) - 运算符
- 关于iOS和OS X废弃的API你需要知道的一切
- WPF-MVVM模式学习笔记5——NotificationObject学习
- 延时执行
- POJ 1584 A Round Peg in a Ground Hole(点到直线距离,圆与多边形相交,多边形是否为凸)
- 【图片压缩】使用canvas,html5进行图片压缩
- Android Studio和ADT中导入jar包和so文件
- [几行Matlab代码之]pairwise distances
- BI商业智能培训系列——(一)概述
- 便利初始化函数与便利构造器
- 整理牛人看文献的方法
- C# UDP编程简介
- 开通博客