I am trying to find a method that I can control the side of the offset, I used this one in c# but the problem is that the curve explodes in several pieces and when I try to change the offset corner style to something different than 0 the component doesn’t work. I also have seen the trick off offsetting for both sides and then culling the bigger one, the problem is that I have to offset some lines too and the lines don’t change the length.
Offsetting is not very predictable but you can improve issues by following some strategies to find out what’s outside or inside.
Strategy n.1:
If you care about curve direction and curve properties you can always determine what’s left and what’s right by taking the cross of your tangent and your offset plane normal. Furthermore it’s likely to offset and always get the same direction, if you care about curve properties in general.
Strategy n.2:
If your curves are closed and not very complex you can determine what’s left and what’s right by the overall length off the offset or by counting the intersections of an ray going from a testpoint left or right. If the intersection count is even it’s outside if it’s odd it’s inside (for curves not suddenly going reverse)
Strategy n.3:
Create a helper curve/point and check the distance to that. This is not necessarily an average point or a circle around a closed curve. But the idea is to use another geometry and to do a distance check to see which offset should be kept.
Strategy n.4.
Work in XY space and transform or (morph) back to make use of cartesian coordinates.
I already have the center point of another curve to know exactly for which side I have to offset, the problem is that I dont really understand which rule drives the direction of the offset, that's why I used this method above, because it has a "direction point" as an input, what I am trying to search for is a similar one that doesnt explode my curve after offsetting. Thanks for your time.
Apart from the fact that I would never offset compound curves (The outcome is likely a bad curve), the code above does only explode under specific conditions.
Usually you offset only less curved curves and then you (re-) blend/fillet in between them. This is how you also should model manually. It’s a bit of pain in Rhino and a great pain in Grasshopper, but it increases shape quality a lot.
Furthermore as said at n.1, if you care about all curve properties, you can indeed predict offset direction.
But it really depends on the curve itself. Maybe you share a minimal example here…
For a start add your stuff to this (but as Tom said the offset is a GIANT topic … plus is in fact a rabbit hole with many entries and not a single exit [ in most of real-life cases, that is ]). Add corner style options and some checks related with the output (is it bananas? etc etc).
Update: found a couple of minutes for adding some plus stuff … and a 2nd C# not 100% finished - for the challenge of the day (only for the brave: how we can get the right in/outwards result(s) from any planar Polyline ???):
I rely on the methods Curve.TryGetPlane and Curve.Offset with the Plane overload. Per definition the outer boundary of a NURBS surface runs counterclockwise around a surface (viewed from its normal direction). With closed planar curves the TryGetPlane method returns a plane which is oriented accordingly - which means that you can use the Curve.Offset method with that plane and then a negative distance goes inwards (to the left) and a positive distances goes outwards and to the right side of the curve.
You may avoid that the curve “explodes” by using proper a CurveOffsetCornerStyle. Please check attached sample CurveOffsetByPlane_jm.gh (9.1 KB)
Jess
This actually works for my proposal, many thanks, but I still want to understand better the offset subject so if you can explain in more detail or send some sstudy reference would be nice.
I made some tests and unfortunately it does not work reliable in all cases.
Attached are some samples which tend to fail. OffsetCurveSamples.3dm (39.3 KB)
Are you familiar with recursion? (100% familiar, that is). Study these 3 Images: can you think a recursive search for the correct ccx events (offset segments) by checking the DotProduct between a given segment dir VS the correct candidate dir one? (if there’s a correct one - see 3rd image). BTW In case that you may suspect that using the Brep.CreatePlanarBreps(…) Method can cut the mustard … well … don’t do it.
That said I have stuff that can handle any polycurve (i.e. not just polylines) case … but this is 100% pro territory (for CNC routing and the likes) meaning that I can’t post it.