Hi, David, thanks for your interest.
The code design of my project is that Grasshopper components serve to gather parameters. These parameters, once collected, are sent to a separate DLL for processing. To add context, I offer the following details:
A DLL method determines the minimum and maximum radius of an organic shaped Brep, named _reVesselShape. The radius is calculated from a central axial line to the surface of the shape.
A LineCurve is created perpendicular to the Axial Line. This line, named circularSweepLn, rotates around the axial line and intersects with the surface of the Brep, yielding points from which to derive the min/max radius value.
I first created a list of circularSweepLns and then processed the intersect points. This is where I ran into problems and requested help from the forum.
During a long session debugging, I discovered that when looping through the list of circularSweepLn’s, the endpoint coordinates would all change in unison and all the end point coordinates were identical. This despite the fact that, the calculated position of the endpoints was different. This gave me a clue the problem.
In the screen shots from the original post, the end coordinates of circularSweepLn were from one element of a list of 30 LineCurves. My attempt to discover an answer led me to remember that points, lines and probably LineCurves are value based variables, not referenced as with classes. Because the first start and end points were the seed of all the descendent LineCurves, altering the position of the end points affected all the LineCurves created. (Perhaps I am drawing a conclusion that is not based on the C# language.)
Since my original posting, I have revised the offending method. Two principle changes corrected the problem. 1) Though it may not be necessary, I created Curves, not LineCurves. 2) Once the original Curve was created, ie, ‘circularSweepCrv’, I duplicated the original to ‘dupCrv2’ before any transforms were applied. This made every line unique. After transforms, the duplicate Curves were then added to a list. The code of the method CalcMinMaxRadius follows
public static (double, double, Point3d, Point3d, List<Curve>, List<Point3d>) CalcMinMaxRadius(Brep _reVesselShape)
{
(double, double, Point3d, Point3d) domainsBox = CalcShapeSpecs(_reVesselShape);
Point3d _startPt = domainsBox.Item3;
Point3d _endPt = domainsBox.Item4;
int centerLineTicks = 10; //? adjust to 500
double centerLen = _startPt.DistanceTo(_endPt);
double centerLineOffset = centerLen / (centerLineTicks);
Vector3d centerLnVector = new Vector3d(_endPt - _startPt);
int radialTicks = 10; //? adjust to 360
double radialRadOffset = 2 * Math.PI / radialTicks;
double minLen;
double maxLen;
Curve[] oLapCrvs;
Point3d[] intZPts;
List<Point3d> intFerPts = new List<Point3d>();
List<double> lenSort = new List<double>();
List<Curve> _xCurves = new List<Curve>();
// *** generate Circular Sweep Line ***
Line line = new Line(_startPt, new Point3d(_startPt.X, 6, _startPt.Z));
Point3d pt = line.PointAtLength(line.Length / 2);
List <Point3d> endpts = new List<Point3d>() { line.From, pt, line.To };
Curve circularSweepCrv = Curve.CreateControlPointCurve(endpts, 1);
// Calculate the Offset Points Along the Center Line
Point3d tickCL = new Point3d();
List<Point3d> offsetPts = new List<Point3d>();
int cLnTicks = centerLineTicks + 1;
for ( int i = 0; i < cLnTicks; i++)
{
double tick = 1.0 / cLnTicks * i;
tickCL = CalcOffsetPt(_startPt, _endPt, centerLineOffset * i);
offsetPts.Add(tickCL);
}
// Calculate the Radial Sweep Angles About the CenterLine
double sweepOffset;
List<double> sweepOffsets = new List<double>();
int rTicks = radialTicks + 1;
for (int i = 0; i < rTicks; i++)
{
sweepOffset = radialRadOffset * i;
sweepOffsets.Add(sweepOffset);
}
// TODO: Offset the end of reVesselShapeto the block
// Start testing at the bottom of the VShape
for (int i = 0; i < centerLineTicks + 1; i++)
{
Curve dupCrv = circularSweepCrv.DuplicateCurve();
double offx = offsetPts[i].X;
double offy = offsetPts[i].Y;
double offz = offsetPts[i].Z;
dupCrv.Translate(offx , offy , offz );
for(int j = 0; j < radialTicks + 1; j++)
{
Curve dupCrv2 = dupCrv.DuplicateCurve();
dupCrv2.Transform(Transform.Rotation(sweepOffsets[j], centerLnVector, offsetPts[i]));
var start = dupCrv2.PointAtStart;
var end = dupCrv2.PointAtEnd;
double len = dupCrv2.GetLength();
_xCurves.Add(dupCrv2);
Intersection.CurveBrep(dupCrv2, _reVesselShape, .001, out oLapCrvs, out intZPts);
for(int k = 0; k < intZPts.Length; k++)
{
intFerPts.AddRange(intZPts);
double intZLength = intZPts[k].DistanceTo(offsetPts[i]);
if (intZLength > .75)
{ lenSort.Add(intZLength); }
}
}
}
lenSort.Sort();
minLen = lenSort[0];
maxLen = lenSort[lenSort.Count - 1];
return (minLen, maxLen, _startPt, _endPt, _xCurves, intFerPts);
}
Below is an illustration of what I hoped to achieve.
Long story for what appears a simple answer.
Thank you, David, for the inquiry.
Dave