Grasshopper

algorithmic modeling for Rhino

Views: 600

Replies to This Discussion

Hi, 

if you want do do that with brep in VB you could do a component 

As Input : 

Brep As list

Direction As list (same size as Brep)

Algorithm

Step = the first step you want say 1 unit of distance

Precision = 0.0001

While Math.Abs(step)> precision

{

intersection = false;

for all brep (i)

{

For all brep (j != i)

{

if Intersection.BrepBrep ( Brep(i), Brep(j),    tolerance, byref Curve(), byref Point3d())  
{
intersect = true;
break (no need to continue for)
}
if intersect = true => break (no need to continue for)

}

if (intersect)

{

'we move front

move all brep with a vector*step

}

else

{

'we move back

step = step /2

move all brep with a vector*(-step)

}

}'end while

}

in C# and it works for 2 and surely more. Here with 2 spheres (the same indeed). 

private void RunScript(List<Brep> brep, List<Vector3d> vector, ref object A, ref object B, ref object C)
{

double precision = 0.01;
int nstep = 1;
int nstepmax = 100;
double step = 0.1;
bool intersection = false;
Curve[] intersectionCurves;
Point3d[] intersectionPoints;
List<double> steps = new List<double>();


while ((step > precision) && (nstep < nstepmax))
{
nstep += 1;
intersection = false;
for (int i = 0; i < (brep.Count - 1); i++)
{
for (int j = (i + 1); j < brep.Count; j++)
{
Rhino.Geometry.Intersect.Intersection.BrepBrep(brep[i], brep[j], 0.0001, out intersectionCurves, out intersectionPoints);
if ((intersectionCurves.Length) > 0 || (intersectionPoints.Length > 0))
{
intersection = true;
break;
}
}
if (intersection)
{
break;
}
}
if (intersection)
{
for (int i = 0; i < (brep.Count ); i++)
{
brep[i].Translate(vector[i] * step);
}
}
else
{
step = step / 2;
for (int i = 0; i < (brep.Count ); i++)
{
brep[i].Translate(vector[i] * (-step));
}
}
steps.Add(step);
}

Attachments:

Un grand merci pour la réponse, messieurs Laurent

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service