Apply MakeUniform command using RhinoCommon

Hi guys!
As you can read here seems that Rhino can’t calc surfaces intersections properly, in some cases.
As suggested, i would like to apply something like “MakeUniform” command to a surface, but using C# code.
I tried to search something useful in the RhinoCommon SDK but i found nothing…
Can you help me?
Thanks! :slight_smile:

Hi @software_comas,

See if this works for you:

/// <summary>
/// Changes a surface so each control point affects the surface exactly the same way.
/// Makes the surface's knot vectors uniform without changing the control point locations.
/// This will change the surface's shape slightly.
/// </summary>
/// <param name="srf">The surface.</param>
/// <param name="direction">The direction, where 0 = U, 1 = V, 2 = Both.</param>
public static bool MakeSurfaceUniform(NurbsSurface srf, int direction = 2)
{
  if (srf == null || direction < 0 || direction > 2)
    return false;

  for (int dir = 0; dir < 2; dir++)
  {
    if (dir == 0 && direction == 1)
      continue;
    else if (dir == 1 && direction == 0)
      continue;

    var index = 0.0;
    var srf_knots = (dir == 0) ? srf.KnotsU : srf.KnotsV;
    var old_knot = srf_knots[0];
    srf_knots[0] = index;

    for (var ki = 1; ki < srf_knots.Count; ki++)
    {
      var knot = srf_knots[ki];
      if (Math.Abs(knot - old_knot) < RhinoMath.ZeroTolerance)
      {
        if (ki < srf.Degree(dir) || ki >= srf_knots.Count - srf.Degree(dir))
        {
          srf_knots[ki] = index;
          continue;
        }
      }

      index += 1.0;
      srf_knots[ki] = index;
      old_knot = knot;
    }
  }

  return true;
}

– Dale

It works like a charm, @dale! Thanks!

如果是brepface呢?或者是trimmed surface

Hi @yi1357068078,

The above only works on a Surface.

– Dale

你好 Dale:

我现在有一些Trimmed Surface,(实际是BrepFace),请看下面的图
怎么样才能在Trimmed Surface上实现这个功能呢?
(图中的Rebuild Surface在LunchBox中,但是会被转换成Untrimmed Surface)

补充:请忽略图中的两张曲面,实际有5个点,这只是效果展示

Hi @yi1357068078,

Does this help?

test_rebuild_retrim.gh (8.8 KB)

– Dale

您好:
我测试了您的gh文件,似乎修剪曲面之后,读取已修剪曲面(Trimmed Surface)的边缘顺序、顶点顺序就不正确了,只有重建曲面(Untrimmed Surface)才能正确获取边缘及顶点的顺序,有没有解决方案呢?请看图片演示:

因为我想要实现下图的功能,请看演示: