日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

POJ 1584 A Round Peg in a Ground Hole(点到直线距离,圆与多边形相交,多边形是否为凸)...

發(fā)布時(shí)間:2023/12/13 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ 1584 A Round Peg in a Ground Hole(点到直线距离,圆与多边形相交,多边形是否为凸)... 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題意:給出一個(gè)多邊形和一個(gè)圓,問是否是凸多邊形,若是則再問圓是否在凸多邊形內(nèi)部。

分3步:

1、判斷是否是凸多邊形

2、判斷點(diǎn)是否在多邊形內(nèi)部

3、判斷點(diǎn)到各邊的距離是否大于等于半徑

上代碼:

#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");elseprintf("PEG WILL FIT\n");}return 0; }

版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。

轉(zhuǎn)載于:https://www.cnblogs.com/wanglaoda/p/4937161.html

總結(jié)

以上是生活随笔為你收集整理的POJ 1584 A Round Peg in a Ground Hole(点到直线距离,圆与多边形相交,多边形是否为凸)...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。