algorithmic modeling for Rhino
Tags:
I haven't tried this in Grasshopper, but the following code appears to work just fine. I also noticed that your for loop is short by one. You shouldn't subtract 1 from crvs.Length.
Random r = new Random();
Curve[] crvs = new Curve[30];
for (int i = 0; i < 30; i++)
{
double x0 = r.NextDouble()*10;
double y0 = r.NextDouble() * 10;
double x1 = r.NextDouble() * 10;
double y1 = r.NextDouble() * 10;
crvs[i] = new LineCurve(new Point3d(x0, y0, 0), new Point3d(x1, y1, 0));
}
double[] xCrvs = new double[30];
for (int i = 0; i < 30; i++)
{
xCrvs[i] = crvs[i].PointAt(0.5).X;
}
Array.Sort(xCrvs, crvs);
for (int i = 0; i < 30; i++)
{
double x = crvs[i].PointAt(0.5).X;
RhinoApp.WriteLine(x.ToString());
}
thanks steve,
yes, you are right about the -1. But I've done essentially the exact same thing you did, and the sort is not working properly.
Hi Brendon,
trust me, Sort works fine. If it didn't, .NET would not be usable. I suspect you are probably not sorting the values you think you are sorting. This line:
crvs[i].PointAt(0.5).X;
is meaningless. The PointAt() method uses curve parameters. There is no guarantee that 0.5 is even a valid parameter on your curve. If you want the MidPoint, then consider using:
crvs[i].PointAtNormalizedLength(0.5)
--
David Rutten
david@mcneel.com
Poprad, Slovakia
hmm, thanks david,
I did reparameterize the curves and check that the point was at 0.5.. but it wasn't working.
If the curves have arc-length parameter spacing then 0.5 on reparameterized curves probably is the midpoint, but not on your regular freeform nurbs curve.
Array.Sort() is not the problem here, the bug or oversight must be elsewhere. Can you post the files I need to replicate this?
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by