0

I have a dynamically allocated array that contains data for a piece of land:

     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

The numbers inside represent height. I have to analyze specific data inside to figure out where i can have suitable jumps(Suitable jumps have 3 squares of reinforcement with an increasing slope of up to 45 degrees,followed by 2 squares steep descending slope -80 degrees).

But the catch is that I only need to analyze the heights that are from the direction from east to west:[1]: https://i.sstatic.net/axiNh.png

How can I implement that direction specifically? this is a simplified version of my code so far:

#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();
}
3
  • Define suitable jump. Commented May 27, 2021 at 10:41
  • @Cheatah I just edited the question. I didn't think that was relevant that's why I didn't add it Commented May 27, 2021 at 10:45
  • Your question is mainly about maths and has no place on stackoverflow (sorry) Commented May 27, 2021 at 10:53

1 Answer 1

0

as far as I understand, the direction is important for you. if it's, then the following changing is enough for that.

    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);            
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.