Using chatgpt to generate surface curvatures in grasshopper c# component

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;



  Plane localFrame = inputSurface.FrameAt(u, v);


  Plane localFrame = Plane.Unset;
  if(!inputSurface.FrameAt(u, v, out localFrame)){
    Print("Failed to get frame");

I don’t think it’s your fault, ChatGPT invents methods, types or properties and doesn’t know how to say “I don’t know”, so many times it is a waste of time for programming.

1 Like

Thank you so much for the fast reply!! I do get the following:

But I was expecting the lines to follow the surface, rather than giving me inward normals, could you solve that as well? Thank you :slight_smile:

Hi @Rick8

That code from ChatGPT does not contain any method for calculating surface curvatures.

Here’s an example for getting surface curvatures using the existing methods in RhinoCommon

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

AT LAST: a man who hates VS (I never use that thing)

Get something to start (far more complex things available as well): (338.4 KB) (120.7 KB)

Yes, you can use the RhinoCommon library from within the C# scripting component in Grasshopper, without using Visual Studio.

You do not need to download it - it is already there from your Rhino installation, and is already automatically referenced in any script component, so you don’t need to move the files around.

Rajaa Issa has written an excellent guide to help get you started with C# scripting for Grasshopper

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 :slight_smile:

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!

Indeed … but no pain == no gain.

What means “new programs” ?


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.

Moral: no pain no gain.