C# divide/find domains assign color

Hi all,

the problem I am facing is the following:
I try to make a mesh slope analysis I got stuck at the point where I want to assign certain colors to a certain slope range. In pseudocode i imagine something like this:

for (int i = 0; i < angleList.Count-1; i++)
{
  if (angleList[i] > V[i] & angleList[i] < V[i+1])
  {
    var color = C[i];
    colorList.Add(color);
  }
}

Here the actual code:

File:
SlopeAnalisis.gh (10.9 KB)

So I would like to assign color 1 when the angle is between rangeDouble[i] and rangeDouble[i+1]
I hope I could express my intentions clearly.

Thanks for everybody looking at this!

SlopeAnalysis.gh (20.5 KB)

Do note that what you are trying to do won’t work the way you’re trying it. You can only assign colours to a mesh on a per-vertex basis. Whereas you’re computing the colours on a per-face basis. The number of faces and vertices are not the same, and the ordering is also not the same.

Instead, you should probably measure the VertexNormals.

Thanks @DavidRutten,

exactly what i needed!

I know this answer is a little off topic, but I thought I would share. We spent some time looking at a few approaches for this and the examples below seemed to be a good fit for us. Maybe it helps?

Another approach is to explode the mesh faces into individual meshes. This allows you to assign the same color to all the vertices of each resulting “face”, (resulting in “coloring by face”). Here is an example in python.



You can also do it with mostly native components. (need something to explode the mesh, this example uses UTO Mesh Edit tools, but you can write your own). The python implementation is literally a copy of what is going on in the file below. The python implementation also uses ghpythonlib.components ConsecutiveDomains and FindDomain, (they really do the heavy lifting pretty well, so…we used that). not sure if there is a comparable thing in C#?

SlopeAnalysis_py.gh (16.4 KB)

1 Like

Hi @chanley,
its always interesting to see how other deal with problems.Thanks for sharing!

To be honest i tried to put the colour per face, but i didnt knew how to solve it, so i did it as @DavidRutten mentioned, what was fine for the moment


I imagine it is quite simple just repeating the color something like this or probably simpler:
maybe he could show us how do do this.I am still interested.

No problem! Happy to share. I wish I was better at C#. The key to the method I was using is exploding the mesh, (each face of the mesh becomes an individual mesh). I have an example of exploding a mesh in C#, (but I’m not great with it). The attached file maybe starts to get you in the right direction? process would probably be something like, explode the mesh->deconstruct the resulting meshes->reconstruct with calculated slope values.


SlopeAnalysisCSharp.gh (18.3 KB)

thanks Cris,

i already saw this post of James Ramsden http://james-ramsden.com/how-to-explode-a-mesh-in-grasshopper/ about how to explode a mesh in C#.

i wondered about the comment, if it s possible to it with the ExplodeAtUnweldedEdges() method. in my case it didnt.

i think i can avoid exploding the mesh by just repeating the color and add to the list. I will keep trying,maybe i can get it work.

I’ll be watching this thread to see if you can get it! The only way I know, to color meshes “by face”, (if that is the goal), is to explode the mesh somehow. Which creates unique vertices for each face/new mesh. (granted, it does result in overlapping/duplicate vertices for neighboring meshes). Then you color the vertices for each mesh the same color. Good luck! I would be interested to learn if there is another/better way!

PS- the ExplodeAtUnweldedEdges method does seem to work, but you need to unweld first.

thanks again Chris,

you are right,forget about the overlaying vertices.
And thanks for the uwnweld tip.

HI,

i tried to change the definiton to measure the slope of an Curve, for that reason i shattered the Curve and extracted the Tangent Vector at the midpoint, to measure the angle between the XY Plane.

I am not sure if this is the right way?
When i have a planar Curve the output angles are 90 which seems reasonable, but i some kind of got stuck at this point.

Maybe somebody could explain.


CurveSlopeAnalisis.gh (9.6 KB)