Flip curves in a consistent direction

I was wondering, toying around with domains, I noticed that any flipped curve always has a negative domain. So I’m thinking, I could use this property (if it is a correct assumption), to always flip a curve in a certain direction. Or does anyone else know of a better method?



Flip curve direction.gh (15.4 KB)

What I am trying to do is make sure my input curve direction is such that a positive offset in in Positive X AND Y direction and negative offset in Negative X OR Y direction, regardless in which direction the curve was drawn in Rhino.

Do not rely on the specific sign of the domain of your curves parametrization.
You should be able to “reparametrize” your curves (setting it to 0-1 range) at any give time and your code should work the same… that’s the idea.

…this doesn’t cover all possible cases, what about a line going from -1,-1 to +1,+1 , which side should be the correct offset for you?


Usually curve direction can be properly defined when the curve is closed (and decently planar).
The norm is having counterclockwise curves as “positive” , with the offset going outwards, and the opposite, clockwise curves are “negative” with offset going inwards.
(note, you have to specify the plane , XY, to have this thing working reliably)

I suggest you to first close your curve, then check the direction, then proceed with the rest.

What is the generalized case you are working on?

1 Like

I’m working on a script which creates a building floorplan. I already had a version working, but if I can figure out the offset direction in advance, that would allow me to speed up the script by 1/4th or so. Basically, I draw the outlines for the building, assign attributes to the curve and offset the curves with the attributes.

Much like Revit, a curve can be offset from its centre, towards an inside and outside. If I know the direction for each offset, I can multiple curves intersect for the inside and the outside to obtain clean wall outlines. Sure it’s easier to join all curves, but then you can’t use attributes to make certain segments wider than others.

Wall Offset problem.3dm (43.3 KB)
Wall offset direction problem.gh (25.2 KB)

E: Fixed the files @maje90 :slight_smile:

If you are working in simple 2D, you can reliably offset your open curves by giving the XY plane input to the Offset component.
From an “internal point of view” of the curve (like a car traveling the curve from start to end) positive is on the right of the curve, negative is on the left.


positive offset = offset to the right (which, on a closed counterclockwise curve, is outward)

Do you have more specific description of how “Wall location [-1, 0, 1]” key works?
I expect your problem can be solved with 1/3 of the components you are using…

I thought I knew how to do this but struggled more than I expected. Finally gave up and reverted to a method that I’m not confident will always work… :thinking: But as I type this, I thought of something that might be more robust.

First, the dubious method:


curve direction_2025Jan25a.gh (19.0 KB)

Then a more robust method?


curve direction_2025Jan25b.gh (20.9 KB)

Both offset the curves in both direction and then use distance to choose one of them, version ‘a’ from a “center” point (dubious) and version ‘b’ from a surrounding rectangle (more robust?).

No curve flipping.

P.S. If you want the other offset instead, you can reverse the List Item input: (green group)

Maybe not better, but one can check the curve orientation:

It is like Centre, Exterior, Interior line locations in Revit. So with it set to 0, the wall offsets from the centre of the line (half width), with it set to 1 or -1 it offsets one side with + or - the wall’s width and the other side will be coincident with the input (0 offset).

How it works in Revit is irrelevant here, eh?

It’s just an explanation in case people are familiar :wink:

1 Like

Yeah those were my ideas too. But then I thought about it further and figured the bounding box method wouldn’t work, because I am also using this script on a U-Shaped building, so then the centre point is outside the building in the courtyard.

I use this set of commands in my projects. Where, by the end points, I determine the closest start point and the end point, and if necessary, the “flip” command will work

Blockquote


2 curves flip or not.gh (12.8 KB)

Distance from a “center” point was the dubious method in my post, distance to a surrounding rectangle was what I called “more robust”. But yeah, a U-shaped building breaks both of those methods. Wish you had mentioned this earlier, when I was still interested.

I think I have another solution, I’ll post that once I get to it. :wink:

Here is a method that requires the perimeter curves to form a Boundary surface:


curve direction_2025Jan25c.gh (23.5 KB)

To get the other offset instead, just invert (right-click and select “Invert”) the Cull Pattern ‘P’ input (green group).

P.S. Then again, when you have a Boundary surface, you also have a perimeter curve that works fine with Offset. To get the other offset instead, use Negative. (or not)


curve direction_2025Jan25d.gh (9.3 KB)

1 Like

I had a version which cuts the bounding rectangle, which can be cast into a surface (so you don’t need to draw it), that’s part of the reason why the offsets have to be extended. But I’m trying without a Surface Split, because it is a somewhat ‘heavier’ solution.

I don’t know what that means? Hope you understand the code I posted…

@inno, your mind reading skills are needed here. :wink:

1 Like

Here’s the solution, if you create a closed polycurve, the direction can be set by joining the curve, flipping the curve in clockwise direction and decomposing the curve to its parts. If you need the attributes, decomposing can be performed using the endpoints of the curve segments. Both curve data trees can be matched and voila.
The offset side can be determined with Curve Side and offsets can be sorted with Curve Closest Point with midpoints, for example.

Notice how flipping the curve doesn’t affect the direction.


Consistent curve direction.gh (15.1 KB)

I said that two days ago

Then something is wrong. Is there supposed to be a Rhino file?
Your video and GH files tell me nothing. Oh well.

if you have a closed non self-intersecting planar curve I think the best way might be to offset both positive and negative: the longer resulting curve is the outside, the shorter is the inside

Indeed, problem here was that the inside can get flipped, the offset may be X/2 and -X/2, but can also be X and 0 or -X and 0. :wink:
But I already solved it so it’s all good.