Hello,
Am trying to compute total Gaussian curvature for all vertices in a mesh… but coming across this error as u see…
the output in the yellow should be 4*pi …
Can someone tell me where I am going wrong please?
Hello,
Am trying to compute total Gaussian curvature for all vertices in a mesh… but coming across this error as u see…
the output in the yellow should be 4*pi …
Can someone tell me where I am going wrong please?
Hello,
regarding the error message:
„neighbours“ is of type PlanktonVertexList which seems to be a custom collection which does not support indexing. So you cannot use square brackets to get an item, but there probaly is a method called „getItem(index)“ or „elementAt(index)“ or something else.
Edit: Or it actually does… but just replace (…) with […] at line 39 and 40.
But what the heck is the total gaußian curvature of a mesh?
Hello Tom,
Thank you for your reply and explanation… I think maybe it helped but I have this other error now? I can’t figure out what my syntax error is here or whether the trouble is still in line 39 & 40
Are you able to help please?
A gaussian curvature of a mesh is like the average of the vertices at that point in the mesh.
Hi, you haven’t closed the second set of square brackets in line 40
Python allows you to continue across multiple lines inside brackets so it tells you it found a problem on line 41 but it doesnt realise the mistake was on line 40
Hello Graham,
Many thanks, you were right about that
I still have this issue appearing though:
Do you know how I may fix this?
That is very strange. it doesnt quite fit but is neighbours an integer or a vertex?
As stated by the error message, you are trying to calculate the remainder from the division of i + 1, an integer incremented by 1, with n, which is a single PlanktonVertex object.
What are you trying to calculate? You can get the number of vertices by calling m.Vertices.Count
, but I’m not sure if that’s what you looking for.
Ahh yes I see you have redefined n in line 39 so it represents the vertex, not the number of vertices
by the way did you know you can use
import math
math.pi
hmm
Ah okay, so what i am trying to do is work w this pseudo-code,
with the aim of computing the total Gaussian curvature for all vertices… so i guess i am trying more to get the position of the neighbour vertices as opposed to number of vertices?
yes! i have import math up, just not showing in screen capture, but changed it from math.pi to pi.value so that in the yellow panel it can show it as ‘4 pi’ as opposed to a number
thank you though.
Yeah, was trying to capture the position of the neighbour vertices
Hey @farah,
I hope this is, what you are looking for!
I’m not sure if the Gaussian curvature is correctly calculated!
However, this should demonstrate how to get the friendly neighbourhood vertices of a certain vertex, construct the necessary vectors, compute the vector angles and so fourth.
import Rhino.Geometry as rg
import Grasshopper as gh
import math
import clr
import os
# Paths to the Plankton libraries (might need to be changed for your setup!!!)
plankton_dll_path = os.path.join(gh.Folders.DefaultAssemblyFolder, "Plankton.dll")
plankton_gha_path = os.path.join(gh.Folders.DefaultAssemblyFolder, "Plankton.gha")
clr.AddReferenceToFileAndPath(plankton_dll_path) # halfedge mesh data structure
clr.AddReferenceToFileAndPath(plankton_gha_path) # GH components and helper methods
import Plankton
import PlanktonGh
clr.ImportExtensions(PlanktonGh.RhinoSupport) # extension methods (e.g. rg.Mesh.ToPlantonMesh())
# Convert the input mesh to a Plankton.PlanktonMesh() object
plt_mesh = x.ToPlanktonMesh()
# Gaussian curvatures per vertex
gaussian_curvatures = []
for k in range(plt_mesh.Vertices.Count):
# Get the current vertex as a point
curr_vtx = plt_mesh.Vertices[k].ToPoint3d()
# Get the indices of the vertex neighbours
nb_indices = plt_mesh.Vertices.GetVertexNeighbours(k)
# Get the vertex neighbours as points
neighbours = [plt_mesh.Vertices[i] for i in nb_indices]
valence = plt_mesh.Vertices.GetValence(k)
t = 2 * math.pi
# Contruct the vectors from the current vector to its neighbours
vecs = [v.ToPoint3d() - curr_vtx for v in neighbours]
for i in range(len(vecs)):
# Calculate the angle in radians for each vector pair
angle = rg.Vector3d.VectorAngle(vecs[i], vecs[(i + 1) % valence])
# Subtract the rangle in radians of each vector pair from t
t -= angle
# Save t as the Gaussian curvature of the current vertex
gaussian_curvatures.append(t)
# Output
a = gaussian_curvatures
Since, you got this previously wrong, let me explain how (i + 1) % valence
works.
Let’s assume that our current vertex has 3 neighbours, which means that its valence is also 3. Furthermore, we need to calculate 3 vectors from our current vertex to its 3 neighbouring vertices and store them into a list. However, for our 3 vectors we now need to calculate 4 vector angles. How so? Well, in our vector list, the last vector has an angle with the first vector!
While looping over the vectors list, our last vector has the index 2. To get its corresponding vector, which is the first one, at index 0, from the list, we can simply calculate its index with the above formula. (2 + 1) % 3 equals 0, which gets us the desired first vector.
For all the other iterations, the formula also produces the right index. (0 + 1) % 3 = 1, (1 + 1) % 3 = 2, etc. It’s basically the same as simply calculating i + 1, however this wouldn’t work for the last vector, since 2 + 1 equals 3, but there is no vector at index 3 in the list.
gaussian_curvature_v1.gh (7.5 KB)
ahhhh yes it is correctly calculated ! The vector angle was interesting, instead of how i converting it to radians !
Many thanks, as usual, I am v appreciate in your help towards me bettering my python skills haha
Super helpful Thank you very much!!
Minor update of diff-arch’s file for Windows 10 / Rhino 7.
added a note for how to get plankton working if it’s a new insstall, and I found the labels and points were coming out in different orders, so I amended the script to output a list of points in same order.
Verification can be done with a meshed torus - it’s a shape with negative gaussian curvature on inside and positive on outside. See differential geometry - Is there any easy way to understand the definition of Gaussian Curvature? - Mathematics Stack Exchange
gaussian_curvature_v2.gh (108.2 KB)
Here’s an alternative approach, which implements the Plankton distribution that ships natively with Kangaroo2 (i.e. it will work without issuing dependencies):