# Grasshopper Terrain Slope in Degrees

Thank you David. Now how to know which colour represent what degree ?

You don’t because you initialise your gradient using the angle range. If you unplug the L0 and L1 inputs and just set the values to 0 and 90, you’ll know that green is horizontal and red is vertical.

1 Like

Cool. It works. Last questions:

1. How to smooth the result? currently it based on actual triangles.
2. Why area where slope is less then 45 is red as well? Am I doing something wrong?

Thank you

ok found how to blur )

Since you uploaded no files I can’t tell you whether there’s a mistake or not. It does look pretty noisy. Are you sure you’re not conflating face normals and vertex normals?

Oh wait, I can tell from your image that you are in fact conflating face and vertex normals.

Instead of the face normals component, use Deconstruct Mesh . It’ll give you the vertex normals which is what you need since colours are assigned on a per-vertex basis.

Hi David please see attached files.

I think I calculating the angle incorrectly. I am getting an angle between world Z and face normal. But I need to display the actual slope angle relative to world plane.

[David R: attachment removed, missing Rhino file and it locks up your computer for 10 minutes trying to open this].

Yep. It works.

Why does this file take forever to open? It’s still going…

10 minutes for every save/open iteration, dayum.

Works fine on my machine. I have attached an updated version.
SlopeAnalysis.gh (465.5 KB)

Thank you David. I solved everything I wanted with your help.
Is there a way to export vertex colour as a texture?

Cheers

Thank you Guys!

I am trying to get the same diagram but using slope percentage. So I can just find a tng of every vector angle , but what is the best way to colour the mesh?
If I want for example have rages 0-5, 5-25 and so on ?

Cheers

When you assign mesh vertex colours, they will always interpolate across each triangle. This can lead to messy visualisation when the differences between neighbouring vertices is large. For example imagine that flat areas are coloured green, medium slopes yellow, steep slopes red and vertical cliffs in black. If you have one triangle which goes straight from flat to vertical, it’ll just blend green to black without the intervening yellow and red.

A solution is to use texture coordinates and a gradient bitmap instead, but Grasshopper 1.0 doesn’t understand either of those, so that’ll require custom code.

If you are happy using vertex colours, then you can use ranges by mapping your angles into a domain sequence. (I’ll upload a file after I poured myself some more tea).

palette.gh (22.0 KB)

palette_2018Mar1a.gh (18.2 KB)

And instead of a specific palette, random colors, number and hue:

palette_2018Mar1b.gh (25.6 KB)

Sorted colors:

palette_2018Mar1c2.gh (28.1 KB)

2 Likes

In addition to the suggestions already given, In order to get “percent” VS “degree” you just need to do a little math in between.

This example uses one custom component to explode the mesh. There are a few others around.

Also, depending on the types of surfaces/meshes you are working with, I have found this to help speed things up a bit. Explode the mesh, decompose and measure against another vector(as described in other examples), then average them together. This effectively gives you the face normal as oppose to every vertex. Then process those values. In the workflow I use, when you reconstruct the mesh with the colors, it assigns the same color(1 color) to each vertex of each individual face. Resulting in a “colored by face” mesh. But if you want, just blur it after to get a smoother looking gradient.
For example, in the attached file, there are 10000 vertices. If I explode it, and only operate on the average of those face vertex normals, I get the vertex at the center,( 1 face normal) of the face. This reduces the values that are being operated on down to 2500. Lastly…this is just how I do it, there are other ways as well.
I have found this approach to be the most useful, IF you want to be able to describe a series of slope “ranges”, (which are really domains), and have control over the color of the ranges. Also, by using the find domain component, you can reuse the index to cull the resulting mesh, (isolating your slope zones).
SlopeAnalysis_Basic_CH.gh (18.9 KB)

1 Like

Hey Guys,

Thank you for your replies. Here is what I came up with. Basically based of what David suggested.
I like Chanley’s variant as well.

Cheers

SlopeAnalysisPercent.gh (1.4 MB)

Hi Chris, thank you so much for this script.

I got a question regarding the slope ranges. (0 to 10, 10 to 20, etc.)

I am able to follow till where you converted the Tangent to Percentage. I understood you are using Find Domain to check which group the Slope Percentage falls into. Is the slope range is to be thought of as percentage?

I am trying to design a walkable slope.
It seems my slope range will be quite small. For example, 0 to 5 for 1in20 ramp (5%).
Am I understanding correctly?

Thanks!
Mon

In the example that I showed above, the logic is as follows:
1 - the values being computed are actually “done” once they come out of the “Angle - compute angle between 2 vectors component”. They are output in Radians. The rest is just sorting/organizing data to color mesh faces.
2 - the next step is converting those radians to either “Degrees” or “Percent”. In Landscape Architecture, (the discipline I work in), we almost always use percent. The “Stream Filter” component is being used to select which one you want to use.
3 - The Slope “ranges” that you want to find, (that are defined in the “Gene Pool” component"), are not necessarily dependent on whether you use Degrees or Percent. It is simply being use to define the bounds of the domains you want to be searched. The values are set manually according to what you want.

So, in my example in the screen shot above, the values coming out of the “Angle” component are being converted to Percent. So the values are in percentages. The find domain doesn’t care what “units” the values are in, it just takes the values that are between, for example, 0 -10, and puts them all in that domain. So the values, that are already computed as percent, are put in “0-10”. If you changed the input of the stream gate to “Degrees”, and didn’t change anything else, the “0-10” range would hold values of 0-10 degrees. Note: as you already know, percent is not the same as degrees, and the coloring of the mesh will be different based on your choice.

Hrmm, not sure I explained that clearly. …

Lastly, that mesh explode component in my example is old and totally overkill. You can simply put this into a python component: Set the input to Item Access, Type Hint = Mesh, Change the Name to M. Change the name of output to F

``````import Rhino

if M:
M.Unweld(0, True)
F = M.ExplodeAtUnweldedEdges()
``````
1 Like