查找点是否在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 好听的元旦简短祝福语