C# : Coming to grips with Surface.Grips (CVs)

Strange. I count the CVs of a surface and display the totals. No problem.
I count the CVs in the U and V direction, and display the totals. No problem.
I check the degree in U and V direction, and display the numbers. No problem.

Then I try to collect the CVs as points, either as rows and columns (U & V), or as a one dimensional array, but my code doesn’t seem to pick them up (I get hold of only a few of the cvs).

Fig 1. Only a few cv’s (the green ones) was collected by the code shown far below:

    // collect grips by rows and columns, or as list
    var nsrf = srf.ToNurbsSurface();
    var cv_points = new Point3d[nsrf.Points.Count()];
    for (int i = 0; i < nsrf.Points.CountU; i++)
    {
      for (int j = 0; j < nsrf.Points.CountV; j++)
      {
        var k = i + j;
        cv_points[k] = nsrf.Points.GetControlPoint(i, j).Location;
        //cv_points[k] = grips[k].CurrentLocation;
      }
    }
    CV = cv_points;

image

I expected all grips/cvs to be collected, but they’re not. What am I doing wrong?

// Rolf

The files (the surface is referenced via guid from the 3dm so that file needs to be attached as well)
CVs.3dm (1.2 MB) Grips_debug.gh (9.1 KB)

The problem is in this line: var k = i + j; if you print the value of k you’ll get something like this:
0, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 2, 3, 4, 5, 6, 7, 3, 4, 5, 6, 7, 8

// collect grips as rows and columns
var nsrf = srf.ToNurbsSurface();
var cv_points = new Point3d[nsrf.Points.Count()];
var k = 0;
for (int i = 0; i < nsrf.Points.CountU; i++)
  for (int j = 0; j < nsrf.Points.CountV; j++)
    cv_points[k++] = nsrf.Points.GetControlPoint(i, j).Location;
CV = cv_points;

Grips_debug.gh (12.5 KB)

If you would like to calculate k based on i and j you can do something like this:

k = i * nsrf.Points.CountV + j;
1 Like

Hm. I tried all those variants (except for using a List as you do). My code fails when trying to assign the result into indexed arrays. Must be the “k” index that goes bananas. i*j+j doesn’t work either.

Even a two dimensional array fails:

   cv_points[i][j] = nsrf.Points.GetControlPoint(i, j).Location;
   // or, as indices
   cv_indices[i][j] = i*j +j ;

< scratching head >

I will have to try a little harder… :thinking: :grinning:


Edit: You were right, the following works (shame on me :blush: )

var k = (i * nsrf.Points.CountV) + j;

// Rolf