检查点在C ++中是在椭圆的内部,外部还是在椭圆上
假设给出了一个椭圆(中心坐标(h,k)和半长轴a,以及半短轴b),还给出了另一点。我们必须找到该点是否在椭圆内。为了解决这个问题,我们必须针对给定的点(x,y)解决以下方程式。
$$\frac{\left(xh\right)^2}{a^2}+\frac{\left(yk\right)^2}{b^2}\leq1$$
如果结果小于一,则该点在椭圆内,否则不在椭圆内。
示例
#include <iostream>
#include <cmath>
using namespace std;
bool isInsideEllipse(int h, int k, int x, int y, int a, int b) {
int res = (pow((x - h), 2) / pow(a, 2)) + (pow((y - k), 2) / pow(b, 2));
return res;
}
int main() {
int x = 2, y = 1, h = 0, k = 0, a = 4, b = 5;
if(isInsideEllipse(h, k, x, y, a, b) > 1){
cout <<"Outside Ellipse";
}
else if(isInsideEllipse(h, k, x, y, a, b) == 1){
cout <<"On the Ellipse";
} else{
cout <<"Inside Ellipse";
}
}输出结果
Inside Ellipse
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下