What is the native component script for Bengesht's "Flip curve toward a point"

Hi, I have the problem that I do not know what “flip curve toward a point” of Begehst Components is doing. Can someone show what would be the equivalent with native grasshopper components. Inputs and outputs should be the same.

Thank you for your time and help!

Do a quick GitHub search: This thing does that:

2 Likes

How to do that with GH native components?

This is actually a perfect example of the limitations of grasshopper and when it starts to become better to code. So to simulate a conditional, (I think, but please correct me if I’m wrong), we need to use a stream filter. The problem is that we actually use calculation time to calculate the flipped curve, even if we don’t intend to use it, as well as the graph being needlessly complicated.

Of course every component could include an on-off switch but that would be ridiculous!

2 Likes

Or like this in Python:

if crv.PointAtEnd.DistanceToSquared(pt) > crv.PointAtStart.DistanceToSquared(pt):
    crv.Reverse()

Why use DistanceToSquared() instead of DistanceTo() you might ask. Well, square root calculations are expensive and the distance calculation between two points includes one. Using DistanceToSquared() thus gives you a performance boost!

:wink:

1 Like

Lovely, thank you so much.

1 Like

I tried to put it in a python component but was not able to bring it two work. Can you show me what would be the entire code for your example? Is there some more variable defining before that?

python.gh (3.7 KB)

3 Likes

Sorry, had an issue with copying the correct text :sleepy: