Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 检查是否有一个点位于圆之外_C++_Algorithm_Geometry - Fatal编程技术网

C++ 检查是否有一个点位于圆之外

C++ 检查是否有一个点位于圆之外,c++,algorithm,geometry,C++,Algorithm,Geometry,因此,我试图制作一个控制台应用程序,检查它是否有N(x,y)点位于N圆圈之外 因此,当有一个圆时,程序工作得非常完美。但当我进入一个以上的圆圈时,它不能正常工作 这是我的密码: #include <stdio.h> #include <iostream> #include <cmath> using namespace std; struct tokr { float x, y, r; int br; }; struct ttoc { flo

因此,我试图制作一个控制台应用程序,检查它是否有
N(x,y)
点位于
N
圆圈之外

因此,当有一个圆时,程序工作得非常完美。但当我进入一个以上的圆圈时,它不能正常工作

这是我的密码:

#include <stdio.h>
#include <iostream>
#include <cmath>

using namespace std;
struct tokr {
    float x, y, r; int br;
};
struct ttoc {
    float x, y;
};
tokr circ[30];
ttoc points[20];
int brokr, brtoc;
void readOkr(tokr* ok) {
    cout << "x: "; cin >> ok->x;
    cout << "y: "; cin >> ok->y;
    cout << "r="; cin >> ok->r;
}
void readToc(ttoc* t) {
    cout << "x :"; cin >> t->x;
    cout << "y :"; cin >> t->y;
}
int main()
{
  int n, brToc;
  float dx,dy,r;
  bool outside;

  cout << "Number of circles: ";
  cin >> n;

  for(int i = 0; i <n; i++) {
    readOkr(&circ[i]);
  }

  cout << "Number of points: ";
  cin >> brToc;

  for(int i = 0; i <brToc; i++) {
    readToc(&points[i]);
  }

  for(int i = 0; i<brToc; i++) {
    outside = false;
    for(int j = 0; j<n; j++) {
        dx = abs(points[i].x - circ[j].x);
        dy = abs(points[i].y - circ[j].y);
        r = abs(pow(circ[j].r,2));
        if(pow(dx,2) + pow(dy,2) > r) {
           outside = true;
           break;
        }
    }
    if(outside) cout << "Point: " << i+1 << " is outside \n";
  }


  return 0;
}
}
#包括
#包括
#包括
使用名称空间std;
结构tokr{
浮动x,y,r;整数br;
};
结构ttoc{
浮动x,y;
};
tokr-circ[30];
ttoc积分[20];
布尔托克国际酒店;
无效读卡器(读卡器*ok){
cout>ok->x;
cout>ok->y;
cout>ok->r;
}
无效读目录(ttoc*t){
cout>t->x;
cout>t->y;
}
int main()
{
int n,brToc;
浮动dx,dy,r;
在外面;
cout>n;
对于(int i=0;i brToc;

对于(int i=0;i而言,从循环中移除的不相关部分基本上如下所示:

for(int i = 0; i<brToc; i++) {
outside = false;
for(int j = 0; j<n; j++) {
    dx = ...;
    dy = ...;
    r = ...;
    if(pow(dx,2) + pow(dy,2) > r) {
       outside = true;
       break;
    }
}
if(outside) cout << "Point: " << i+1 << " is outside \n";

for(int i=0;i从循环中删除的不相关部分基本上如下所示:

for(int i = 0; i<brToc; i++) {
outside = false;
for(int j = 0; j<n; j++) {
    dx = ...;
    dy = ...;
    r = ...;
    if(pow(dx,2) + pow(dy,2) > r) {
       outside = true;
       break;
    }
}
if(outside) cout << "Point: " << i+1 << " is outside \n";

for(inti=0;i您可以切换此选项

 outside=false;
    //...other instructions...
    if(pow(dx,2) + pow(dy,2) > r) {
           outside = true;
           break;
        }


你可以换一下这个

 outside=false;
    //...other instructions...
    if(pow(dx,2) + pow(dy,2) > r) {
           outside = true;
           break;
        }