指向多边形程序

时间:2015-12-01 23:35:52

标签: c polygon point

所以我在C语言编程方面非常新,我一直试图制作一个程序,根据现有算法,告诉我某个点是否在多边形内部。我希望程序向我询问输入数据并给我结果(0或1)我做了一些东西,但我有点卡在最后但不知道如何完成这项工作并完成它。
我没有任何错误,我没有得到任何输出。它要求我输入所需的值,最后它不会返回它应该的内容(In或out; 0或1

int main() {
    int n, s, d, vertx[6], verty[6], testx, testy, i, j, c = 0;
    printf("Enter the number of vertices of the polygon\n");
    scanf("%d", &n);

    printf("Enter the x coordinates of the polygon\n");
     for (s = 0; s < n; s++)
        scanf("%d", &vertx[6]);

    printf("Enter the y coordinates of the polygon\n");
        for(d = 0; d < n; d++)
            scanf("%d", &verty[6]);

    printf("Enter the x and y test coordinates\n");
    scanf("%d%d", &testx, &testy);

    for (i = 0, j = n-1; i < n; j = i++) {
       if ( ((verty[i]>testy) != (verty[j]>testy)) &&
          (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-                             verty[i]) + vertx[i]) )
   c = !c;
  }
  return c;
  printf("%d", &c);
  }

我希望有人愿意帮助我一点点。 谢谢!

1 个答案:

答案 0 :(得分:1)

请仔细查看您的scanf语句。您希望每次都扫描到阵列中的其他条目,但是您要扫描到阵列内存末尾的位置!

相关问题