RhinoCommon ClosedCurveOrientation() question

If you draw a simple rectangle left to right on the top CPlane, then call the normal Rhino command Dir on it, the arrows should point in a counterclockwise direction (the sort of “standard” curve orientation as far as I can tell…)

Now if you run the following script on it, it will report “Clockwise”

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

def cp_crv_filt(rhino_object, geometry, component_index):
    return rs.IsCurvePlanar(geometry) and rs.IsCurveClosed(geometry)

msg="Select closed planar curve in Top view"
crvID=rs.GetObject(msg,4,preselect=True,custom_filter=cp_crv_filt)
crv=sc.doc.Objects.Find(crvID).Geometry
plane=rs.WorldXYPlane()
print crv.ClosedCurveOrientation(plane.Normal)

Now, this is comparing it with an “up” direction vector which is the normal of the world XY plane, which I consider to be "up "in this case. So why is it reporting clockwise and not CounterClockwise? Should I be standing on my head here? :stuck_out_tongue_closed_eyes:

Curve.ClosedCurveOrientation Method (Vector3d)   

Parameters    
upDirection
    Type: Rhino.Geometry.Vector3d
    A vector that is considered "up".    
Return Value
The orientation of this curve with respect to a defined up direction.

Thanks, --Mitch

I don’t have an answer for above. I’d just like to ask a question about testing curve direction. I’ve used this code for testing curve direction, are there situations where it will give the wrong answer.

import rhinoscriptsyntax as rs

obj = rs.GetObject("Select a curve", 4)

if rs.IsCurve(obj) and rs.IsCurvePlanar(obj):
    curveplane = rs.CurvePlane(obj)
    if (curveplane[3][2] < 0.0):
        print 'clockwise'
    else:
        print 'anticlockwise'

Thanks Mark.

Hi Mitch,

i guess because the up direction is understood to be the direction you look along. If you look from the top view, the up direction vector is pointing to you. Therefore it reports not counter-clockwise. If you set the up direction vector to the negative world z-axis by reversing it (the direction you look along from top), it will return counter-clockwise.

c.

So I do need to stand on my head then… :wink:

Just seems to me that stating “up direction” is very ambiguous, for if I get the CurvePlane of the aforementioned rectangle, the “up” for me is +Z, not -Z. But whatever, as long as it is consistent. Maybe the help should be more explicit in saying exactly what you said:

Curve.ClosedCurveOrientation Method (Vector3d)

Parameters    
upDirection
    Type: Rhino.Geometry.Vector3d
    The vector representing the viewing direction of the curve
Return Value
The orientation of this curve with respect to the direction vector

That would be too exhausting all the time. You could rotate the monitor 180° instead, or swap top with bottom view :wink:

I guess the situation with the upvector is similar when rotating points in the top view. Positive values rotate counter-clockwise which seems odd at first glance. But if you look along the rotation axis from the bottom, this direction is clockwise.

@Hughes_Tooling,

you might consider a check for single line segments. Your example always returns “anticlockwise” eg. with a line along any axis, regardless of its direction.

c.

My point exactly, actually. Looking “down” the positive world Z-axis (in the negative Z direction), things rotate counterclockwise. I fully expected that a closed curve would be also be considered turning counterclockwise when viewed from this same direction.

–Mitch

Thanks Clement, fortunately I will not have to deal with that situation. I noticed it will fail if you have several collinear lines as well, not sure if a straight line can have a clockwise anticlockwise direction!

Mark

@dale @dalelear

It’s been interesting trying to follow this thread. I’m still confused, even if you all aren’t. I think part of the problem is the documentation you’ve cited. Clockwise/counterclockwise needs a frame of reference. We all know Rhino uses a right-hand coordinate system, but beyond that some further definition is in order. Are we talking World coordinates, which is pretty absolute, or C-plane, or view, or what? More importantly, what are ClosedCurveOrientation and other SDK routines using?

I think it might be helpful if one of the Dales slipped on their cloak of authority and offered a few words of guidance to purify our thoughts.

I’m looking into this.