algorithmic modeling for Rhino
Hi to everybody,
this is my firts discussion here as I am just learning scripting.
I have written a very easy code to model a diagrid on a surface, but the surface is not parametrized and the diagrid doens't populate the full surface area.
Here the code of the SolveInstance part:
protected override void SolveInstance(IGH_DataAccess DA)
{
Surface baseSurface = null;
int nrBaysUDirection = new int();
int nrBaysVDirection = new int();
DA.GetData(0, ref baseSurface);
DA.GetData(1, ref nrBaysUDirection);
DA.GetData(2, ref nrBaysVDirection);
List<Line> lines = new List<Line>();
List<Point3d> points = new List<Point3d>();
double uPos=(double)1/(double)nrBaysUDirection;
double vPos=(double)1/(double)nrBaysVDirection;
for (int i = 0; i <= nrBaysUDirection-1; i++)
{
for (int j = 0; j <=nrBaysVDirection-1; j++)
{
Point3d pt0 = baseSurface.PointAt(i * uPos, j * vPos);
Point3d pt1 = baseSurface.PointAt((i + 1) * uPos, j * vPos);
Point3d pt2 = baseSurface.PointAt((i + 1) * uPos, (j + 1) * vPos);
Point3d pt3 = baseSurface.PointAt(i * uPos, (j + 1) * vPos);
Point3d ptM = baseSurface.PointAt((i * uPos) + (0.5 * uPos), (j * vPos) + (0.5 * vPos));
Line lnA = new Line(pt0, ptM);
Line lnB = new Line(pt1, ptM);
Line lnC = new Line(pt2, ptM);
Line lnD = new Line(pt3, ptM);
lines.Add(lnA);
lines.Add(lnB);
lines.Add(lnC);
lines.Add(lnD);
points.Add(pt0);
points.Add(pt1);
points.Add(pt2);
points.Add(pt3);
}
}
DA.SetDataList(0, lines);
DA.SetDataList(1, points);
}
and further a screenshot.
Where is my mistake?
Last question:
to script the component I am using the default assmbly from Giulio Piacentino, but when I debug I got this error:
Warning 1 Member 'SimpleGrid.SimpleGridInfo.AssemblyName' overrides obsolete member 'Grasshopper.Kernel.GH_AssemblyInfo.AssemblyName'. Add the Obsolete attribute to 'SimpleGrid.SimpleGridInfo.AssemblyName'. C:\Users\matteo\Documents\Visual Studio 2010\Projects\SimpleGrid\SimpleGrid\SimpleGridInfo.cs 7 32 SimpleGrid
when I do not use this assemblt I do not get this error.
How can I fix it?
Thanks for your help and tips
Matteo
Tags:
Hi Matteo,
about the warnings; AssemblyName was changed to Name. The old member is still there but it has been marked as Obsolete. Just change your override to Name and the warning will go away.
As for your surface, the problem is that you're assuming the Surface UV space goes from zero to one in both directions. This is not necessarily the case. You'll need to remap your normalized coordinates into actual surface coordinates:
Point3d pt0 = baseSurface.PointAt(i * uPos, j * vPos);
Point3d pt1 = baseSurface.PointAt((i + 1) * uPos, j * vPos);
Point3d pt2 = baseSurface.PointAt((i + 1) * uPos, (j + 1) * vPos);
Point3d pt3 = baseSurface.PointAt(i * uPos, (j + 1) * vPos);
Point3d ptM = baseSurface.PointAt((i * uPos) + (0.5 * uPos), (j * vPos) + (0.5 * vPos));
Would become:
Interval U = baseSurface.Domain(0);
Interval V = baseSurface.Domain(1);
...
double u0 = i * uPos;
double u1 = i * uPos + 0.5 * uPos;
double u2 = (i+1) * uPos;
double v0 = j * vPos;
double v1 = j * vPos + 0.5 * vPos;
double v2 = (j+1) * vPos;
u0 = U.ParameterAt(u0);
u1 = U.ParameterAt(u1);
u2 = U.ParameterAt(u2);
v0 = V.ParameterAt(v0);
v1 = V.ParameterAt(v1);
v2 = V.ParameterAt(v2);
Point3d pt0 = baseSurface.PointAt(u0, v0);
Point3d pt1 = baseSurface.PointAt(u2, v0);
Point3d pt2 = baseSurface.PointAt(u2, v2);
Point3d pt3 = baseSurface.PointAt(u0, v2);
Point3d ptM = baseSurface.PointAt(u1, v1);
--
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