Skip to content
Advertisement

How could I generate a 2D array from a known slope and aspect value?

Given a dummy heightmap (or digital elevation model) stored as a Numpy array like this:

JavaScript

I can calculate its slope and aspect like this:

JavaScript

And visualise it:

JavaScript

enter image description here

But how would I go the other way?

I’d like to generate a blank 2D Numpy array of a fixed size, then fill it with values that follow a known slope and aspect (starting from an arbitrary elevation e.g. 0).

Advertisement

Answer

Since gradient assumes a step size of 1, the general formula for making a line with N points and a given slope and offset is

JavaScript

What you call Slope is the magnitude of the gradient, given as an angle. What you call Aspect is the ratio of partial slopes in the x- and y-directions, also given as an angle. You have the following system of non-linear equations:

JavaScript

Luckily, you can solve this pretty easily using substitution:

JavaScript

Now all you need to do is take the outer sum of two lines with slopes sx and sy:

JavaScript

Here is an example:

Inputs:

JavaScript

Gradient:

JavaScript

Result:

JavaScript

enter image description here

Your conventions may be off by a sign, which you should be able to fix easily by looking at the plot.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement