How can this kind of "twisting" be done automatically? Now I just can do it manually

Hello everyone,

I collect a series of curves (from clinical images, they are parallel in z direction) and want to loft them. However, because of the image processing, some curves are twisted according to a rotation point in x-y plan (fig1). Thus the lofted surface has the “gaps” (fig2). What I can do now is to manually twist the curves back to minimize the gaps by my eyes (fig3). It’s a time consuming work.
My question is, is it possible to realize the “twisting back” automatically? In my mind it is a quite difficult work, and any suggestion or idea are welcome and appreciated.
The rhino file including the curves and the rotation point is attached.
rotate.3dm (297.3 KB)




How do you know how far to rotate each block of curves? Or is it just based on intuition? It does sound difficult, I would start by figuring out the longest diagonal of each slice curve and maybe align those.

No that’s no good, some of your sections are too close to circular to yield reliable spanning diagonals:

Wow, it’s really you, David? I can’t believe my eyes! Thank you so much and I am so happy to have your help!
You are right I just rotate each block based on my intuition.
Your suggestion means I should get out longest diagonal of each slice (I would do it for neighboring slices at the “gap”), then align according to the angle?
Thanks again!

Anyway, I’m going home soon. Here’s my file (which isn’t a good solution), just in case: scan (109.0 KB)

Thank you, David, I will try your method to see if there is anything can be improved.

Are you sure they are only rotated around that point in your file?

In that case, attached a possible direction to look in using galapagos to compare the overlap between two subsequent curve areas and minimize that. Then rotate the curve and the curves above it and replace the list items with the ones that have been rotated

Maybe @DavidRutten has an idea how to make this into a loop…
You should of course only rotate if the area difference is above a certain treshold… that you define (111.5 KB)

Hi Gijs, I think that’s a great idea to compare the overlapped area and minimize it.
You are right the loop is another key (hard) point…
Thank you again for your kind help (especially in weekend)!

not in python:
use at your own risk, haven’t done excessive testing: (3.3 KB)

grasshopper version: (111.5 KB)

That’s really fantastic (again)! Thank you so much Gijs, and I need much time to understand your work in details :).

I think the method I chose for rotating the profile is not yet good (reliable)

btw: what does the scan represent?

Hi Gijs, your contribution has provided me a hopeful direction.
You have sharp eyes: this is a medical scan, from images on patient’s coronary vessel. We want to 3d reconstruct the vessel.

ok, because I wonder if there are any risks involved if the reconstruction is not 100% ok. And it isn’t, because although this script removes most of the rotation, there is no guarantee that the least overlap is the right solution. How many of these scans do you need to process?

Hi Gijs, thank you for your carefulness!
We have lots of (more than 100 cases) these scans to do, thus we need eagerly an automatic way to regulate.

Ok, yes in that case it’s going to be a tedious exercise!
I can probably make the script faster and more reliable. Right now the twist in the layers seemed to be always in the same direction is this right? Is this always the case?

Hi Gijs, it’s a good question and I never though of it.
Actually we just began our work, and until now we tried about 3-4 cases. For them twist is always in the same direction. But I can’t guarantee there is no “black swan” inside :). Anyway, let’s assume that they are in the same direction.
Thank you again for your kindness!

Hi Gijs,

According to the information in the python code, I visit your website. You are so good at design…I like the Birdsnest eggcup!
We may have more and deeper cooperation in the near future!

1 Like

Hi Gijs,

It’s been a week since your help and I am still struggling in the first step: every time I run your python code, it shows the error:
"Runtime error (NotImplementedException): The method or operation is not implemented.

line 231, in GetObject, “C:\Users\w.wu\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\”
line 19, in alignInput, “”
line 91, in script"

I tried to search online, and asked other guys in the forum, but no answers. Would you please have a check what the problem is? (5.7 KB)

seems to me like you are trying to put the non-gh version into grasshopper? The .py I posted should be run from the pythonscript editor.

line 19: rs.GetObjects is a method that asks you to select curves. In gh you don’t need this, since you wire things up. In that case rs.GetObjects isn’t needed, because you feed the script with curves right away

Thank you for your reply, Gijs!
However, after I deleted the lines for curves and points, there are new errors.