Tab creation script for cut paths (python)

Hi there,

I’m a few months into learning python with no previous programming experience but it’s slowly coming together.

I am trying to work out the logic and structure behind this script which seems simple enough and I’m hoping to get a some help off you guys.

The script would take a planar polyline as an input and replace the “inwards” facing corners with a semi-circle of a chosen diameter. I’ve illustrated this in the image below:

To clarify the context this will be used to cancel the rounded corners when cutting on a CNC machine so they don’t have to be cut out by hand afterwards.

Any input on how to achieve this would be hugely appreciated, the logic behind detecting the right corners still puzzles me.

Thanks :grin:

Well, if you can be sure that all your polylines have a counterclockwise direction from their start point, you can iterate along the curve and find all the corners and get the vector cross product of the segment tangents at the joint. Those which have negative pointing cross product vectors will be “inside” corners. Zero vectors will be 180° joints.

In order to make sure all curves have counterclockwise directions, I usually use the rhinoscript function CurveDirectionsMatch(). For reliability, I get the bounding box of each curve, then draw a counterclockwise polyline using the boundingbox corners, and use that to compare with the curve in question. If CurveDirectionsMatch() returns False, you then need either to reverse the curve, or check for positive cross product vectors instead of negative.

I know this sounds complex, but for me this is the most reliable method. I can try to hack out an example in awhile.


Hi Mitch,

Thanks for the speedy response, you are right the direction won’t be consistent hopefully your technique will work. An example would be much appreciated.

Additionally I think we can also assume the tab will be tangent to the shortest curve. However I would like to offer the possibility for the user to switch this.


You can also use the ClosedCurveOrientation(self: Curve, xform: Transform) method for the curve object. Since your curve will be on XY plane, you will simply pass Rhino.Geometry.Transform.Identity to the xform.

Hey Charles,

You might be interested in a script that I whipped up a few months ago. It might not be what you need (and perhaps the most efficient), but It might give you a few ideas.

– Dale

FingerJoint.rvb (2.4 KB)

FingerJoint.3dm (33.5 KB)

I have not actually forgotten this thread. In fact, I’ve been working on and off on it for the last few days. It’s not all that hard if you limit the input cases to polylines with 90° corners, but if you wish to generalize to polycurves and non 90° corners it gets trickier. So in the end, the code got more complicated… Quite complicated in fact, it’s a bit “hacky”, and I used a lot of RhinoCommon in it as well, so it’s not an easy example to follow, sorry. Finding the inside corners is the relatively easy part.

I started off trying to do some geometrical calculations for the corners and finally gave up because it’s too hard to predict when the curves coming into the corner are curved and not straight, or if segments are very short relative to the corner “notch”. Finally I just decided to create a subtractor shape and copy/orient it around to the inside corners then curve boolean difference each from the main curve. I also decided to orient the notches along the corner bisector - which makes it easier to figure out. For 90° corners, that means they will be at 45° to the corner.

There will be failure cases with unusual shapes, I built in some adaptive code to try to take care of a few, but others will always fail. The script marks (usually) where it can’t put in a corner. anyway, it’s a WIP, but I’ll toss it out here just in case (use at your own risk :stuck_out_tongue:). Only works with closed planar curves in planes parallel to the Top CPlane (they do not have to lie on the plane though).

–Mitch (9.2 KB)