Does anyone know how I can achieve a clockwise or counterclockwise direction on these curves by grasshopper:
There is no such thing for curves in general.
Clockwise or counterclockwise needs a closed curve and a reference direction or plane
You will find in Rhinocommon some tools
https://developer.rhino3d.com/api/rhinocommon/rhino.geometry.curve/closedcurveorientation
Sasquatch plugin has a tool for that.
This feels similar to this thread (from yesterday !).
Indeed a plane is required to get a notion of clockwise or anticlockwise.
Thank you so much @magicteddy
I think there is a misunderstanding,
I wrote
A straight line is not a closed curve !!!
Made a small script that checks a curve for its direction given a plane.
It utilises curve.ClosedCurveOrientation(plane)
to check direction ( as mentioned by @laurent_delrieu above.
This function is only supposed to work with closed curves but also appears to work with simple open curves that are not self-intersecting
import Rhino
def is_clockwise(curve, plane):
"""
Determine if a closed curve is oriented clockwise or counterclockwise
relative to a given plane.
Parameters:
curve: The input closed curve.
plane: The plane used to evaluate the orientation.
Returns:
Boolean: 1 = (Clockwise) or 0 (Counterclockwise).
"""
# Result also seems valid for many open curves
#if not curve.IsClosed:
#return "The curve is not closed."
orientation = curve.ClosedCurveOrientation(plane)
if orientation == Rhino.Geometry.CurveOrientation.Clockwise:
return 1
elif orientation == Rhino.Geometry.CurveOrientation.CounterClockwise:
return 0
else:
return -1
# Check orientation
if curve and plane:
result = is_clockwise(curve, plane)
if result == 1 :
text = "Clockwise"
elif result == 0:
text = "Couterclockwise"
else:
text = "Unknown Orientation "
else:
raise Exception("Missing Inputs")
# Output
CW_bool = result # Output orientation (string)
Direction_Text = text
Definition:
IsClockwise_01.gh (8.4 KB)
User Object:
Is Clockwise.ghuser (3.1 KB)