Hi, I am quite new to c# scripting in grasshopper, but I have been using grasshopper for multiple years now. My goal is to try to make 2 simple c# components that generate the asymptotic lines and the principal curvature lines respectively on a given surface.
As mentioned in the title I have been using chatgpt to write the script, but I haven’t gotten any of its codes to work, which is probably my own fault. I would really appreciate it if anyone could take a look at this code for principal curvature on a simple surface that chatgpt created:
private void RunScript(Surface inputSurface, double step, ref object outputLines)
// Create an empty list to store the asymptotic lines
List asymptoticLines = new List();
// Get the domain of the surface
Interval uDomain = inputSurface.Domain(0);
Interval vDomain = inputSurface.Domain(1);
// Loop through the surface domain
for (double u = uDomain.Min; u < uDomain.Max; u += step)
for (double v = vDomain.Min; v < vDomain.Max; v += step)
// Get the local frame at the current point
Plane localFrame = inputSurface.FrameAt(u, v);
// Get the asymptotic vector
Vector3d asymptoticVector = localFrame.ZAxis;
// Transform the asymptotic vector to the world coordinate system
// Normalize the asymptotic vector
// Get the point on the surface at the current u, v
Point3d surfacePoint = inputSurface.PointAt(u, v);
// Create a line from the surface point in the direction of the asymptotic vector
Line asymptoticLine = new Line(surfacePoint, asymptoticVector);
// Add the line to the list
// Set the output data
outputLines = asymptoticLines;
Thank you Daniel, this RhinoCommon thing is quite confusing, but I downloaded it through microsoft visual studio yesterday according to the Rhino guide, but all the tutorials I have watched end up coding in visual studio which I do not want, I want to write directly in the c# component for grasshopper, I am still not sure if grasshopper has acess to the RhinoCommon library so I have also added the RhinoCommon dll file to the special folder>components folder. The script you referred to is it supposed to be pasted directly into the c# component after private void etc or is it for c# in visual studio? Thanks for the reply
Hi, thanks for the reply, I have only done some minor scripting a couple of years ago in c# for grasshopper in a course, so I want to stay to that lane and not add new programs to the mix
Those scripts are not beginner friendly but I will take it! Does the first return the principal curvature when interpolating the points? The other script I am not sure what it does, thanks!
The 1st C# returns curvature data according some U/V division using a Surf List. Includes a suitable Class as well (an intro to data mining so to speak) for doing LINQ queries related with curvature stuff: say, find the Surface/Pt that have the max Mean Curvature, or find all Pts that have Gauss Curvature in some search Interval etc etc. That said most people think that the essence of coding is doing things … but the core of the matter is in fact how to manage things.
The 2nd C# … well … tells you what curvature is. Better start from that one…
Rhino Common is critical for ANY C# worth the name (when deals with Geometry matters, that is). Better deal with that prior attempting anything.
I would strongly advise to read C# books many times (forget Internet) preferably with computer off. After that … well … may The Force be with you.
Thanks for the reply Daniel, I will try to go through the guide and learn this stuff for real as soon as I do not have pressing deadlines, the example you provided it is not simply enough to copy paste it into a c# component? Sorry for being stupid!
With new programs I mean visual studio, I would prefer to just keep going with the c# component for simplicity.
Thanks for the feedback, I will try to learn this for real as soon as I have the time, I was just hoping someone or would have or that there would already be a simple component for describing surfaces with principal curvature lines/asymptotic curves, all this is needed for is to make for meshing that is more in-line with the forms that I aim to do.
Well … if you have plans to learn C# (the build in editor is 10000% crap - but that adds to the pleasure) … then think the whole situation as waterstarting (a windsurf thing that one) a heavy (i.e. sleeve full of water) race sail . If you try to learn been 5 meters from the shore … you’ll waste your time > go into the deep > sharks/orcas/monsters/aliens > point of no return > either do it or die.