Curve domain of reversed curve

Hi guys, I ran into a problem with a curve’s domain when the curve is reversed.

if I try this example script that adds a point at the middle of the domain then the point is added to the start of the curve:


import rhinoscriptsyntax as rs
obj = rs.GetObject("Select a curve")
if rs.IsCurve(obj):
    domain = rs.CurveDomain(obj)
    t = domain[1]/2.0
    point = rs.EvaluateCurve(obj, t)
    rs.AddPoint( point )

image

Is that expected behaviour?

I understand that this happens because the curve start that used to be “0” is now the curve end at “-0” and that the curve end at “140” is not the curve start at “-140”, but it seems a bit odd that the example fails on reversed curves.

(BTW: I made a workaround so I don’t need that :slight_smile: Thanks!)

I wouldn’t assume the start or end of a curve’s domain is 0 unless it has been reparameterized. To get the middle of the domain I would always use:

dom=rs.CurveDomain(crv)
mid_dom=(dom[0]+dom[1])/2

–Mitch

Thanks, yes, that’s the workaround I used too.
So I guess the example here: http://developer.rhino3d.com/wip/api/RhinoScriptSyntax/#curve-CurveDomain should be adjusted.

HI @Holo,

A curve’s domain should be increasing.

Also, the middle of a curve’s domain does not always evaluate to the midpoint of a curve.

import Rhino
import rhinoscriptsyntax as rs

def TestCurveDomain():
    curve_id = rs.GetObject('Select curve', rs.filter.curve, True)
    if curve_id:
        curve = rs.coercecurve(curve_id)
        if curve:
            # Domain mid parameter
            t = curve.Domain.Mid
            print 'Domain mid parameter ', t
            rs.AddPoint(curve.PointAt(t))
            # Curve mid parameter
            rc, t = curve.NormalizedLengthParameter(0.5)
            print 'Curve mid parameter ', t
            rs.AddPoint(curve.PointAt(t))
    
TestCurveDomain()

– Dale

Yeah, I think I understand the increasing part, and that the “bug” is just in the example that i referred to, where it tires to calculates the middle of the domain as half of the “bigger” end:

Which works on a normal curve that goes from say 0 to 140, where 140/2 =70,
but what I now understand is that a reversed curve is “just” a domain that is multiplied with -1 so it goes from -140 to 0 instead. And there the bigger value is 0 and thus 0/2 = 0, so the “mid” is still at the end.

But it doesn’t matter which way the domain is pointed with the method I posted, that’s why it’s 100% reliable. It will always give you mid-domain, it’s just the average of two numbers…

1 Like

Yes, I know, that’s why I use it too. (as stated above :wink: )