Error with rs.OffsetCurve (rhino5)

I am trying to script offset of simple closed shapes (rectangles and concave shapes with no crossing lines nor any interior voids).
rs.OffsetCurve will fail for some parameters when my understanding of geometry and the manipulation says it should work.

rectangles work correctly: e.g. rectangle (100,100 - 500,500)
vector 0,0,0 offset= 75 = outside
vector 0,0,0 offset= -75 = inside

for a convex shape (like an outlined U or rectangle as above with hole rectangle (200,200 -400, 500) so these points:

vector [0,0,0] offset = 20 = outside
vector [0,0,0] offset = -20 ERROR (Thinnest portion is 50 wide, so 20 inset should leave 10mm space and be valid).

using curvecentroid[rhino with offset.3dm|attachment]
[0,0,0] offset = -20
ac = rs.CurveAreaCentroid(newcurve)
offCurve = rs.OffsetCurve( newcurve, ac[0], -offsetnum )
works but is still outside. it should be inside. It will work properly, if i manually select a point say(450,200) that is inside shape, but farther from edge than the offset amount. This is hard to generalize to make a program.

my understanding of vector from the vague description (after experiments) is that for offset >0, that the nearest curve point moves closer and then the rest of the curve is on that side of original curve. Is that reasonably correct?

How can I programmatically offset inside and outside for concave and convex shapes?

Sample code and rhino file attached.

  1. for toolpath, select the object on ‘toolpath’ layer
  2. for shape use any line on ‘shape-u’ layer

rhino with offset.3dm (115.5 KB)
offset (2.4 KB)

Hi @don,

Can you simply your 3dm to just provide the curve to offset, and simply your code to just offset it?


– Dale