Grasshopper Terrain Slope in Degrees


#1

Hey Guys,

I am trying to show terrain parts which have a slope more 45 degrees. Using gradient showing slope every 15 degrees.
I found a way to map vector Z and display its values, but I need to convert them to degrees somehow.
Please see attached images.

Cheers,


#2


(David Rutten) #3

If you have a normal vector, you compute the angle between it and the World Unit Z vector. Then convert this angle from radians into degrees (there’s a Deg component for this, or you can use an expression: \frac{360 \cdot angle}{\pi}).


#4

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


(David Rutten) #5

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.


#6

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


#7

ok found how to blur )


(David Rutten) #8

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.


#9

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].


#10

Yep. It works.


(David Rutten) #11

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

10 minutes for every save/open iteration, dayum.


#12

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


#13

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

Cheers


#14

#15

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


#16

missing


(David Rutten) #17

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).


(David Rutten) #18

palette.gh (22.0 KB)


#19

Instead of Consec


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)


(Chris Hanley) #20

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)


How to change text number to number in GH