Grasshopper

algorithmic modeling for Rhino

here is my code:

 

        private Point3d[,] UVPointMatrix(Surface srf, int u, int v,bool swap)
        {
            Interval domU = srf.Domain(0);
            Interval domV = srf.Domain(1);
            /*if (swap)
            {
                int temp = u;
                u = v;
                v = temp;
            }*/
            Point3d[,] ptArr = new Point3d[u+1, v+1];
            double numU = domU.Length / u;
            double numV = domV.Length / v;
            int uC = 0;
            for (double i = domU.Min; i <= domU.Max; i+=numU)
            {
                int vC = 0;
                for (double j = domV.Min; j <= domV.Max;j+=numV)
                {
                    Point3d p = srf.PointAt(i, j);
                    /*if (swap)
                    {
                        ptArr[vC, uC] = p;
                    }
                      else
                    {*/
                        ptArr[uC, vC] = p;
                    //}
                    vC++;
                }
                uC++;
            }
            return ptArr;
        }

 

It goes wrong sometimes. "Out of Index"pops up  ,or, one row of points are missing.

I use Microsoft.VisualBasic.CompilerServices.ObjectFlowControl.ForLoopControl.ForNextCheckR8

to control the loop, the problem is solved.... but ,MSDN says "This API supports the .NET Framework infrastructure and is not intended to be used directly from your code."

Code C# in VS refering to some VB Compile Method......

 

anyone has the same problem?

Views: 307

Replies to This Discussion

Hi Ian,

I'm not sure exactly what the problem is, but you cannot trust floating point for loops to terminate at an exact value.

Either use for loops with integers and compute the factor inside the loop, or extend your termination value:

for (int i = 0; i <= u; i++)
{
   double ti = (double)i / (double)u;
   ti = domU.ParameterAt(ti);
   ...
}


for (double i = domU.Min; i <= (domU.Max + 0.5 * numU); i+=numU)
{
   ...
}


--
David Rutten
david@mcneel.com
Poprad, Slovakia

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2025   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service