About creating a NURBS Surface with C#

I’m new here and just joined the field. Does anybody know, how to create a random coarse surface with C# NURBS? Thanks.

I interpreted coarse to mean jagged and sharp. Here’s the result

And the code

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
    const int PointsDim = 6;
    const int Order = 2;
    const int Dimension = 3;

    var Srf = NurbsSurface.Create(Dimension, true, Order, Order, PointsDim, PointsDim);

    Srf.KnotsU.CreateUniformKnots(1);
    Srf.KnotsV.CreateUniformKnots(1);

    Random Rand = new Random();

    const double MaxHeight = 2.0;

    for (int i = 0; i < PointsDim; i++)
    {
        for (int j = 0; j < PointsDim; j++)
        {
            Srf.Points.SetPoint(i, j, new Point3d(i, j, Rand.NextDouble() * MaxHeight));
        }
    }

    doc.Objects.Add(Srf);

    doc.Views.Redraw();

    return Result.Success;
}

Both of the orders are 2 which gives the the surface its coarseness. It might be helpful if you describe what you’re trying to solve in general since I’m not sure this is what you’re looking for. It might also be helpful if you become more familiar with NURBS and how they work under the hood. Here’s a nice high level description of NURBS geometry, and here’s the NURBS wiki article.

2 Likes

Hey, sir: I’m simulating some virtual surface and their defect for deep learning data, and I saw some people use displacement mapping. I’m not sure if displacement mapping and your code indicate the same thing. Also, how can I make the surface more smooth(not that sharp)? Appreciate your reply!

He explained why the surfaces was so sharp (you asking for coarse). If you read the papers linked to you will find that you can play with the “order” (2+).

Both of the orders are 2 which gives the the surface its coarseness.

Small patches of higher order surfaces would need matching to become smooth, a larger surface can be manipulated with the ControlPoints, or, with a displacement map.

You may also want to use a Mesh surface where you can manipulate the vertices.

Not showing an example of what kind of surface you want means we are all still in the dark trying to help you. An example picture would be helpful on your part.

// Rolf

1 Like

Thanks for your reminding and explaining, I saw the variable of coarseness.

They are not the same thing. Displacement maps are a material property that modify vertex positions on a mesh. Rhino 6 has displacement support to modify the render mesh. Rhino WIP also supports displacement maps on the PBR material.

Unfortunately, without more information or an example I can’t help you replicate this in Rhino. I’m still unsure what you’re trying to accomplish.

1 Like

Hello sir,
hope the questions can reveal my detail technical requirement for you:
How can I increase the density of the control points based on the code ( I want the frequency of up and down can be higher)?

I want to add some random style scratch on the surface. (single, two, cross pattern,… few scratches can be see by human eyes is OK)
How can I set light source in the image automatically?
Can Rhino produce the bite the flower like the scratch image shown? This question is more advance, I need to conquer the problems above first.
Thanks!

I think you should be more specific about what information you have, and what you’re trying to create with it. I can’t infer your goal from the questions.

One way to increase the density of control points on a NURBS surface is to increase the degree along the U or V. Here’s an example. You can only do this a finite number of times though. You also need at least one more control point than the new degree for it to succeed.

Those small scratches and roughness would better be simulated with the material than the surface itself.

You can create lights and position them in a similar way to creating the surfaces in my previous example. It’d probably be useful to start by reading about lights in the documentation.

1 Like