# Incremental Rotation and Collision Checking of Polysurface

Hey there,

First time poster, so please bear with me. I am looking to utilize Grasshopper to rotate a 5 axis machine spindle. I’m running into an issue with collision checking. I want to take a polysurface (milling bit) to a location then systematically rotate the bit and check for collisions with the model. I know how to do this in other programs like Unity using C#. It’s seemingly harder in Grasshopper without having “if/then” or “looping” nodes.

Attached is an image of what I am looking to do. I’m not looking for someone to solve this problem for me, but more or less just point me in the right direction. I’m under the impression that this is something that should be handled by a C# or VB script. My goal is to come up with a solution that does not rely on surface directions from Rhino objects as some of the objects I plan to use this on may be meshes or even point locations.

Thanks

you might wanna try the c# script element in grasshopper?

this might be brute and not exactly what you’ve been looking for, but should give you some idea:

``````private void RunScript(Brep B, ref object Breps)
{
//rotz
Brep breps = B;
//xform to 0
Point3d centroid = new Point3d();
centroid = breps.GetBoundingBox(true).Center;
Vector3d vec = new Vector3d(centroid);
vec = Vector3d.Negate(vec);
var xformTrans = Transform.Translation(vec);
breps.Transform(xformTrans);

//rotz
List<double> lengths = new List<double>();
for(int i = 0;i < 720;i++)
{
BoundingBox bbox = breps.GetBoundingBox(true);
//Brep outBBox = bbox.ToBrep();
Point3d[] edgesPt = bbox.GetCorners();
double compareSize = edgesPt[0].DistanceTo(edgesPt[1]);
var xformRot = Transform.Rotation(RhinoMath.ToRadians(0.25), new Vector3d(0, 0, 1), new Point3d(0, 0, 0));
breps.Transform(xformRot);
}
int shrtIndex = new int();
double lowest = lengths[0];
for(int i = 0;i < 720;i++)
{
if(lengths[i] < lowest)
{
shrtIndex = i;
lowest = lengths[i];
}
}
var xformFinRot = Transform.Rotation(RhinoMath.ToRadians(0.25) * shrtIndex, new Vector3d(0, 0, 1), new Point3d(0, 0, 0));
B.Transform(xformFinRot);
BoundingBox finBbox = breps.GetBoundingBox(true);
Point3d finCenter = finBbox.Center;
Brep outBBox = finBbox.ToBrep();
Vector3d finVec = new Vector3d(finCenter);
finVec = Vector3d.Negate(finVec);
var xformFinTrans = Transform.Translation(finVec);
breps.Transform(xformFinTrans);

Breps = B;
//sdf
}
``````

dont have my project with me, which would rotate by 1 degree then 0.1 then 0.01 which would be much more proper and efficient, if you’d see any help of the proper version, let me know.

This is awesome, thank you so much. Its going to take me a while to figure out everything in this script as I am new to using C# for Grasshopper, but I’ll try to respond again once I figure something out.

Thanks!

theres indeed a lot of useless noise in this code…
if you need some help with it, let me know

After messing around with this idea for the past week. I unfortunately think that I just don’t have the programming knowledge to tackle the issue. Thanks for your help though!

sorry for my super late answer. I allowed myself to have a look at the first two steps of your instructions and kinda coded them like I can. If I got it correctly, further steps are more repetition of step 2, right?

guess this should help a bit more, I also added some comments to make it more comprehensive, but if you have any questions, don’t hesitate to ask!

incrementalSSXCheck.3dm (256.1 KB) incrementalSSXCheck.gh (6.7 KB)

have a good one

Ben

Thanks for taking a crack at this! You really didn’t have to. What you produced worked and did what I was looking for. However, there’s so much more that I want to do and its just super clear to me after tinkering around, I just don’t understand the Rhino Common stuff. When trying to check true vs false it seems to operate differently from any other C# I’ve ever used.

This other post seems to talk about it: RhinoCommmon Intersect.Intersection function question

All that said, I just don’t think I have the programming background to get grasshopper + C# to do what I am looking for without huge frustration. Especially for a pet project which is what this was.

Thanks again for the help! I really appreciate it.

indeed its kinda annoying to learn new libraries, but always comes with new possibilities.

in this particular case, the boolean value returned from the command does return if the command was successful, not if a intersection was found.
due to the fact that you can have different types of intersection, a simple bool isnt enough to represent this.
in usage this means that you have to check whats inside the “out” arrays or wether they are empty to have a result.

I can understand it can be frustrating, but maybe you eventually retake this project after having cuddled a bit with your pet