以特定方向分析数组

analyze array in a specific direction

我有一个动态分配的数组,其中包含一块土地的数据:

     0| 1| 2| 3| 4| 5|    ->coordinates
 0|  1  0  8  4  1  1
 1|  7  4  2  6  7  8
 2|  7  4  2  4  3  4
 3|  7  1  6  2  0  8
 4|  0  0  3  3  6  6

里面的数字代表身高。我必须分析里面的具体数据,找出哪里可以有合适的跳跃(合适的跳跃有3个方格的加固,增加的坡度高达45度,然后是2个方格陡峭的下降坡度-80度)。

但问题是我只需要分析从东到西方向的高度:[1]: https://i.stack.imgur.com/axiNh.png

我该如何具体实施该方向?到目前为止,这是我的代码的简化版本:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int length=4, width=5;

struct LandData
{
   int height;
};

struct LandData* WritingData()
{

    struct LandData *arr = (struct LandData*)malloc(length* width* sizeof(struct LandData));

    for (int i = 0; i < length ; i++){ //len
        for (int j = 0; j < width; j++){//wid
            ((arr + i*width + j)->height) = rand() % 10;
        }
    }

    int l = 1, h;
    float jumps;

    for (int i = 0; i < length ; i++) {
        for (int j = 0; j < width; j++){
            h = ((arr + i*width + j)->height);
            jumps = tan(h/l); //  cause the angle for the jumps should be 45 deg
            if(jumps <= 1)
            printf("suitable jumps: %d %d\n", i ,j);            
        }
    }

    return(arr);
}

int main()
{
    struct LandData *arr = WritingData();
}

据我了解,方向对你很重要。如果是,则以下 改变就足够了。

    for (int i = 0; i < length ; i++) {
    for (int j = width; j > 0; j--){
        h = ((arr + i*width + j)->height);
        jumps = tan(h/l); //  cause the angle for the jumps should be 45 deg
        if(jumps <= 1)
        printf("suitable jumps: %d %d\n", i ,j);            
    }
}