检查点在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 怎么训练狗狗卧下
4 上海狗狗训练基地
5 训练狗狗排便
6 狗狗基础训练
8 如何训练狗狗装死
9 狗狗站姿训练
10 狗狗训练用品
11 训练狗狗吧
12 狗狗要怎么训练
13 怎么训练狗狗玩球
14 训练狗狗唤回
15 狗狗训练躺下
16 狗狗训练指令
17 狗狗的训练技巧
18 狗狗不好训练