判断圆和矩形是否相交C - Rectangle and Circle
Description
Note: we call them intersect even if they are just tangent. The circle is located by its centre and radius, and the rectangle is located by one of its diagonal.
Input
Output
Sample Input
1 1 1 1 2 4 3
1 1 1 1 3 4 4.5
Sample Output
NO
#include <stdio.h>
#include <string.h>
#include <math.h> using namespace std; double a, b, xa, ya, xb, yb, r; double far(double n1, double m1, double n2, double m2)
{
double ans;
ans = (n1 - n2) * (n1 - n2) +(m1 - m2) * (m1 - m2);
ans = sqrt(ans);
return ans;
} double max(double x, double y)
{
if (x > y)
return x;
else
return y;
} double min(double x, double y)
{
if (x < y)
return x;
else
return y;
} int main()
{
int T;
scanf("%d", &T);
while(T--)
{
scanf("%lf%lf%lf%lf%lf%lf%lf", &a, &b, &r, &xa, &ya, &xb, &yb);
if (
far(xa, ya, a, b) < r &&
far(xa, yb, a, b) < r &&
far(xb, ya, a, b) < r &&
far(xb, yb, a, b) < r //矩形在圆里面
)
{
printf("NO\n");
continue;
}
else if (
far(xa, ya, a, b) > r &&
far(xa, yb, a, b) > r &&
far(xb, ya, a, b) > r &&
far(xb, yb, a, b) > r &&
far(xa, ya, xb, ya) > *r &&
far(xa, ya, xa, yb) > *r //圆在矩形里面
)
{
printf("NO\n");
continue;
}
else if (
far(xa, ya, a, b) <= r ||
far(xa, yb, a, b) <= r ||
far(xb, ya, a, b) <= r ||
far(xb, yb, a, b) <= r //顶点在圆内
)
{
printf("YES\n");
continue;
}
else if(
(far(xa, b, a, b) <= r && b < max(ya, yb) && b > min(ya, yb))||
(far(xb, b, a, b) <= r && b < max(ya, yb) && b > min(ya, yb))||
(far(a, ya, a, b) <= r && a < max(xa, xb) && a > min(xa, xb))||
(far(a, yb, a, b) <= r && a < max(xa, xb) && a > min(xa, xb)) //顶点不在圆内但是边和圆相交
)
{
printf("YES\n");
continue;
}
else
{
printf("NO\n");
continue;
} }
return ;
}
判断圆和矩形是否相交C - Rectangle and Circle的更多相关文章
- HDU 1221 Rectangle and Circle(判断圆和矩形是不是相交)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1221 Rectangle and Circle Time Limit: 2000/1000 MS (J ...
- poj1410(判断线段和矩形是否相交)
题目链接:https://vjudge.net/problem/POJ-1410 题意:判断线段和矩形是否相交. 思路:注意这里的相交包括线段在矩形内,因此先判断线段与矩形的边是否相交,再判断线段的两 ...
- PHP判断两个矩形是否相交
<?php $s = is_rect_intersect(1,2,1,2,4,5,0,3); var_dump($s); /* 如果两个矩形相交,那么矩形A B的中心点和矩形的边长是有一定关系的 ...
- C# 判断两个矩形是否相交
源代码 public bool JudgeRectangleIntersect(double RecAleftX, double RecAleftY, double RecArightX, doubl ...
- HDU 1221 Rectangle and Circle 考虑很多情况,good题
http://acm.hdu.edu.cn/showproblem.php?pid=1221 114 92 31 95 13 96 3 这题只需要判断圆和矩形是否相交,然后在里面是不算相交的. 那么就 ...
- cocos2d-x JS 各类点、圆、矩形之间的简单碰撞检测
这里总结了一下点.圆.矩形之间的简单碰撞检测算法 (ps:矩形不包括旋转状态) 点和圆的碰撞检测: 1.计算点和圆心的距离 2.判断点与圆心的距离是否小于圆的半 isCollision: functi ...
- poj 1410 Intersection (判断线段与矩形相交 判线段相交)
题目链接 Intersection Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12040 Accepted: 312 ...
- 【LeetCode】1401. 圆和矩形是否有重叠 Circle and Rectangle Overlapping
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 利用公式 日期 题目地址:https://leetco ...
- Rectangle and Square(判断正方形、矩形)
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=42#problem/D 改了N多次之后终于A了,一直在改判断正方形和矩形那,判断 ...
随机推荐
- BZOJ 1001: [BeiJing2006]狼抓兔子(最短路)
平面图的最小割转化为对偶图的最短路(资料:两极相通——浅析最大最小定理在信息学竞赛中的应用) ,然后DIJKSTRA就OK了. ------------------------------------ ...
- 弹出窗口内嵌iframe 框口自适应
说一下,弹出窗口还有内嵌一个iframe 这种模式应该是不科学的,但是公司项目里面就偏偏用到了,它这高低还不能只适应,所以我痛苦的日子来了 分析一下: 首先window.showDialog 方法的时 ...
- C# DES加解密
加密 public static string Encrypt(string sourceString, string key, string iv) { try { byte[] btKey = E ...
- JS性能
获取以下属性 会等待对应元素渲染完成 才继续执行 * offsetTop, offsetLeft, offsetWidth, offsetHeight* scrollTop, scrollLeft ...
- qt数据库多线程问题的解决(QSqlDatabase只能在创建它的线程中使用)
Qt数据库由QSqlDatabase::addDatabase()生成的QSqlDatabase只能在创建它的线程中使用, 在多线程中共用连接或者在另外一个线程中创建query都是不支持的几乎国内没有 ...
- JAVA GUI学习 - JTable表格组件学习_C ***
/** * JTable高级应用 * @author Wfei * */ public class JTableKnow_C extends JFrame { JTable jTable; MyJMe ...
- 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题
[HDU 3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...
- Swift调用Objective C的FrameWork
很多Github的库经过很多年的发展,源码都是OC写的,,所以,用Swift调用OC的库就是开发中难免遇到的的一个问题,本文以AFNetworking为例,讲解如何跨语言调用. 第一步 创建一个空的工 ...
- Android 建造者(Builder)模式
关于 Builder 模式 详述:http://blog.csdn.net/jjwwmlp456/article/details/39890699 先来张图 看到 Android 中 使用了 Bui ...
- js 常用的一些函数
//设置默认焦点 var setFocus = function SetFocus(elementId) { document.onkeydown = function (even ...