查找点是否在C ++中的圆内
假设给出了一个圆(中心坐标和半径),还给出了另一个点。我们必须找到该点是否在圆内。为了解决这个问题,我们必须找到给定点到圆心的距离。如果该距离小于或等于半径,则该距离在圆内,否则不在圆内。
示例
#include <iostream>
#include <cmath>
using namespace std;
bool isInsideCircle(int cx, int cy, int r, int x, int y) {
int dist = (x - cx) * (x - cx) + (y - cy) * (y - cy);
if ( dist <= r * r)
return true;
else
return false;
}
int main() {
int x = 4, y = 4, cx = 1, cy = 1, rad = 6;
if(isInsideCircle(cx, cy, rad, x, y)){
cout <<"Inside Circle";
} else {
cout <<"Outside Circle";
}
}输出结果
Inside Circle
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短