Trying to use Collide 2D

I’m trying to make use of Collide 2D to solve geometric constraints.
A line segment must either have it’s end on a polyline, or be tangent to that polyline, depending on it’s initial location.
The idea is to used Collide 2D by considering a polyline which goes around my line at a very short distance as the second polyline.
After much trial and failure, I checked the “Collide2D_Shapes” sample file and realized that the whole “Collide 2D” concept was some kind of hack in the way the 2D polylines were made to keep their shape.
I tried to replicate the ideas such as using the “Angle” component to maintain the shapes, but it fails miserably.

Maybe there’s a more straightforward approach, but I have yet to find it.
Line tangent to (18.5 KB)

Hi Olivier,

I don’t think collide 2D is actually the ideal component to use here. For this shape of a rectangle with arcs at the ends, there is a much simpler way to calculate the collisions, because the boundary is at a fixed distance from a straight line. This is what is used in the ‘Collider’ component. Here’s an example: (19.3 KB)

About the Collide2D example though - that specific example uses angle to preserve the shapes, which is more suited to simple polygons than to finely discretized curves. It was also done that way to show that it can work with flexible shapes.
Since adding the 6 degree of freedom points to the solver though, I’ve also worked on a different approach to collision more like the rigid body components, but for curves, so it keeps them completely rigid in shape, and does the collision directly between the pairs of NURBS curves. I suspect that might be more what you were after. I’ll try and clean up and post that component soon.

Hi Daniel,

Thanks for coming back to me.
It looks like there’s something very basic that I didn’t understand about Kangaroo.
I had tried the “Collider” component, but I thought that I needed to put all the lines as an input for the collision condition to be enforced.
In fact, as it appears in the definition you sent me, collisions will be enforced with all other goal-geometry.
This is not obvious.
Also, As I want to find a tangency, I need a goal which pulls the end of the line towards the boundary.
I tried using a lign with a zero-length goal, but I can’t seem to find the strengths that will allow to converge between those conflicting goals…

No, you were understanding it right the first time - the Collider goal only applies collisions between the lines going into that goal. Note how there is a list of 3 lines going into the Objects input.

For the tangency you might need another goal - I’ll post it here in a minute. (14.9 KB)

Here’s a line-line goal that keeps them tangent. It’s the same code as the line-line collisions, except it doesn’t switch off when they don’t overlap.
You’ll need to set the assembly reference location of the KangarooSolver.dll for the script file when you first open it.
If you’re using Rhino 6 this will be something like:
C:\Program Files\Rhino 6\Plug-ins\Grasshopper\Components\KangarooSolver.dll

No, you were understanding it right the first time - the Collider goal only applies collisions between the lines going into that goal. Note how there is a list of 3 lines going into the Objects input.

Indeed, so since there is only one radius value in the list, it applies only to the first line in the list, and the two others are considered “Zero” radius ?
I didn’t think that “Zero” was a valid input.

Tangency ! Excellent…
We are getting closer to “Sketch” constraints à la SolidWorks.
This could even be packaged as a separate plugin as a more “mainstream” application of your physics engine.
Sketch constraints (geometric and dimensional) are a much missed feature in Rhino.

Ah, I see what you’re getting at now.
It does look for a radius for each line in the list. When only one is provided, it uses that same value for all of them, the same as the data matching works in standard Grasshopper components.

Also, for these collisions it is really only the sum of the radii of the pair of colliding objects that matters.
If you set the radius of one line as 2, and the other as 1, they will be touching when the centrelines are 3 units apart, which is the same if the radii are the other way around, or even if one radius is 3 and the other is 0.

OK, I get it, but it still can’t seem to reach my end goal :

There are two distinct cases, and I would like to find the set of goals that will find the position of the end of the blue line seamlessly if I change the angle between the red and blue lines.
To be honest, that would be impossible to do in SolidWorks, but maybe GH+Kangaroo gives more flexibility…

Like this? (14.6 KB)


E-X-A-C-T-L-Y !
I owe you a beer.

1 Like