【问题标题】:Point in polygon program多边形程序中的点
【发布时间】:2015-12-01 23:35:52
【问题描述】:

所以我是 C 编程的新手,我一直在尝试制作一个程序,它会根据现有算法告诉我某个点是否在多边形内。我希望程序询问我输入数据并给我结果(0 或 1)我做了一些东西,但我有点卡在最后,不知道如何完成这项工作。
我没有任何错误,我没有得到任何输出。它要求我输入所需的值,最后它没有返回它应该返回的值(输入或输出;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);
  }

我希望有人愿意在这方面帮助我一点。 谢谢!

【问题讨论】:

  • 您需要指定问题。是否有错误,是否得到不正确的输出等。
  • 我没有任何错误,我没有得到任何输出。它要求我输入所需的值,最后它没有返回它应该返回的值(输入或输出;0 或 1)

标签: c polygon point


【解决方案1】:

请仔细查看您的 scanf 语句。您希望每次都扫描到数组中的不同条目,但您正在扫描到超出数组内存末尾的位置!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-16
    • 1970-01-01
    • 2011-12-19
    • 2013-04-25
    • 2011-05-13
    • 1970-01-01
    相关资源
    最近更新 更多