getParameterAtPoint returning incorrect value

getParameterAtPoint returning incorrect value

mschafer39KEH
Explorer Explorer
1,025 Views
7 Replies
Message 1 of 8

getParameterAtPoint returning incorrect value

mschafer39KEH
Explorer
Explorer

I am working on a script to process some geometry so I started with a script to iterate through the edges of the outer loop of a selected surface.  I use approximate each edge as a polyline using the Evaluator3D getStrokes method.  I need the parameter values for each stroke so I call getParametersAtPoints with the points returned by getStrokes.  The points look correct for all the edges, but some of the edges give the same parameter value for every point.  The code and output are below.

 

Thanks,

Marc

 

 

 

truncated conetruncated cone

 

            sel0 = input0.selection(0);
            face = sel0.entity
            faceEval = face.evaluator
            loops = face.loops
            outerLoop = loops[0]
            fitTolerance = .01 # database units, cm
            # coEdges are 2D in parameter space of the face
            # use edge instead but direction might be reversed
            for iedge in range(outerLoop.coEdges.count):
                print ("--------------- edge " + str(iedge) + "---------------")
                ce = outerLoop.coEdges.item(iedge)
                reversed = ce.isOpposedToEdge
                e = ce.edge
                eval = e.evaluator
                (ret, t0, t1) = eval.getParameterExtents()
                tstep = (t1 - t0) / 2.
                if reversed:
                    t0, t1 = t1, t0
                    tstep = -tstep

                (ret, lineFit) = eval.getStrokes(t0, t1, fitTolerance)
                for ifit in range(len(lineFit)):
                    p = lineFit[ifit].asArray()
                    (ret, tFit) = eval.getParameterAtPoint(lineFit[ifit])
                    if not ret:
                        ui.messageBox('getParameterAtPoint_NG')
                        return
                        
                    print(str(p) + " @ " + str(tFit))
                    

Output from code for truncated cone pictured above:

--------------- edge 0---------------
(-5.0, 0.0, 0.0) @ 0.0
(-2.0, 0.0, 3.0) @ 4.242640687119285
--------------- edge 1---------------
(-2.0, 4.898587196589413e-16, 3.0) @ -3.141592653589793
(-1.9615705608064606, 0.39018064403225744, 3.0) @ -3.141592653589793
(-1.847759065022573, 0.7653668647301808, 3.0) @ -3.141592653589793
(-1.6629392246050894, 1.111140466039206, 3.0) @ -3.141592653589793
(-1.4142135623730934, 1.4142135623730967, 3.0) @ -3.141592653589793
(-1.1111404660392021, 1.662939224605092, 3.0) @ -3.141592653589793
(-0.7653668647301768, 1.8477590650225746, 3.0) @ -3.141592653589793
(-0.3901806440322531, 1.9615705608064615, 3.0) @ -3.141592653589793
(3.908665341092488e-15, 2.0, 3.0) @ -3.141592653589793
(0.3901806440322608, 1.96157056080646, 3.0) @ -3.141592653589793
(0.7653668647301839, 1.8477590650225717, 3.0) @ -3.141592653589793
(1.1111404660392088, 1.6629392246050876, 3.0) @ -3.141592653589793
(1.414213562373099, 1.4142135623730911, 3.0) @ -3.141592653589793
(1.6629392246050938, 1.1111404660391995, 3.0) @ -3.141592653589793
(1.847759065022576, 0.7653668647301736, 3.0) @ -3.141592653589793
(1.9615705608064622, 0.3901806440322498, 3.0) @ -3.141592653589793
(2.0, -7.350356717430472e-15, 3.0) @ -3.141592653589793
--------------- edge 2---------------
(5.0, 6.123233995736766e-16, 0.0) @ 0.0
(2.0, 2.4492935982947064e-16, 3.0) @ 4.242640687119285
--------------- edge 3---------------
(-5.0, 1.2246467991473533e-15, 0.0) @ -3.1415926535897927
(-4.960573506572389, 0.6266661678215234, 0.0) @ -3.1415926535897927
(-4.8429158056431545, 1.2434494358242767, 0.0) @ -3.1415926535897927
(-4.648882429441255, 1.8406227634233931, 0.0) @ -3.1415926535897927
(-4.381533400219316, 2.4087683705085805, 0.0) @ -3.1415926535897927
(-4.045084971874735, 2.9389262614623703, 0.0) @ -3.1415926535897927
(-3.644843137107054, 3.4227355296434485, 0.0) @ -3.1415926535897927
(-3.1871199487434434, 3.852566213878951, 0.0) @ -3.1415926535897927
(-2.679133974894977, 4.22163962751008, 0.0) @ -3.1415926535897927
(-2.128896457825356, 4.524135262330102, 0.0) @ -3.1415926535897927
(-1.5450849718747288, 4.755282581475772, 0.0) @ -3.1415926535897927
(-0.9369065729286133, 4.911436253643446, 0.0) @ -3.1415926535897927
(-0.3139525976465562, 4.990133642141359, 0.0) @ -3.1415926535897927
(0.31395259764657846, 4.990133642141358, 0.0) @ -3.1415926535897927
(0.9369065729286356, 4.9114362536434415, 0.0) @ -3.1415926535897927
(1.5450849718747497, 4.755282581475765, 0.0) @ -3.1415926535897927
(2.128896457825376, 4.524135262330092, 0.0) @ -3.1415926535897927
(2.6791339748949956, 4.2216396275100685, 0.0) @ -3.1415926535897927
(3.1871199487434607, 3.8525662138789367, 0.0) @ -3.1415926535897927
(3.6448431371070695, 3.422735529643432, 0.0) @ -3.1415926535897927
(4.045084971874747, 2.9389262614623526, 0.0) @ -3.1415926535897927
(4.381533400219327, 2.408768370508561, 0.0) @ -3.1415926535897927
(4.648882429441264, 1.8406227634233727, 0.0) @ -3.1415926535897927
(4.842915805643161, 1.2434494358242554, 0.0) @ -3.1415926535897927
(4.960573506572392, 0.6266661678215013, 0.0) @ -3.1415926535897927
(5.0, -2.1040427052676556e-14, 0.0) @ -3.1415926535897927

0 Likes
1,026 Views
7 Replies
Replies (7)
Message 2 of 8

p.seem
Advocate
Advocate

I'm able to get the same (incorrect) behaviour, and it smells to me like it's a bug.  I thought it had to do with the approximation involved in getStroke, but even without all of that the two semi-circular edges are always returning the same parameter for any point along the edge.

 

The snippet below is enough to show the issue -- qs should equal [t0, t1], but it's coming back as [t1, t1].

(r, t0, t1) = eval.getParameterExtents()
(r, ps) = eval.getPointsAtParameters([t0, t1])
(r, qs) = eval.getParametersAtPoints(ps)

Other shapes (e.g. the face of a simple half cylinder) return the expected result.  There must be something about that conic section that the algorithm doesn't like.

 

I know there's no answer here, but hopefully if we keep piling on this will get the attention of someone at AutoDesk.

Message 3 of 8

MichaelT_123
Advisor
Advisor

Hi Mr.Marc

... do not panic ... yet...

 

Try:

(ret, pointsFit) = eval.getStrokes(t0, t1, fitTolerance)

(ret, paramsFit) = eval.getParametersAtPoints( pointsFit )

for ifit in range(len(pointsFit)):

     point = pointsFit[ifit]

     param = paramsFit[ifit]

     print(str(point) + " @ " + str(param)

 

Regards

MichaelT

 

 

MichaelT
0 Likes
Message 4 of 8

mschafer39KEH
Explorer
Explorer

Hi MichaelT,

I started out with getParametersAtPoints and unrolled the loop to see if it made a difference.  It doesn't--either form returns the same parameter value for every point.  As p.seem pointed out, you don't even need to use getStrokes to see the bug.

 

Thanks,

Marc

 

0 Likes
Message 5 of 8

MichaelT_123
Advisor
Advisor

Hi Mr. Marc,

... as I was curious, so I did some ad hoc testing.

Results (Excel compatible) are below:

##########################

--------------- edge 0 ---------------
Point,1.5359,-6,0,@ Param=,-6.9282
Point,5,0,0,@ Param=,0
--------------- edge 1 ---------------
Point,-5,0,6.12323e-16,@ Param=,-3.14159
Point,-4.96057,0,0.626666,@ Param=,-3.01593
Point,-4.84292,0,1.24345,@ Param=,-2.89027
Point,-4.64888,0,1.84062,@ Param=,-2.7646
Point,-4.38153,0,2.40877,@ Param=,-2.63894
Point,-4.04508,0,2.93893,@ Param=,-2.51327
Point,-3.64484,0,3.42274,@ Param=,-2.38761
Point,-3.18712,0,3.85257,@ Param=,-2.26195
Point,-2.67913,0,4.22164,@ Param=,-2.13628
Point,-2.1289,0,4.52414,@ Param=,-2.01062
Point,-1.54508,0,4.75528,@ Param=,-1.88496
Point,-0.936907,0,4.91144,@ Param=,-1.75929
Point,-0.313953,0,4.99013,@ Param=,-1.63363
Point,0.313953,0,4.99013,@ Param=,-1.50796
Point,0.936907,0,4.91144,@ Param=,-1.3823
Point,1.54508,0,4.75528,@ Param=,-1.25664
Point,2.1289,0,4.52414,@ Param=,-1.13097
Point,2.67913,0,4.22164,@ Param=,-1.00531
Point,3.18712,0,3.85257,@ Param=,-0.879646
Point,3.64484,0,3.42274,@ Param=,-0.753982
Point,4.04508,0,2.93893,@ Param=,-0.628319
Point,4.38153,0,2.40877,@ Param=,-0.502655
Point,4.64888,0,1.84062,@ Param=,-0.376991
Point,4.84292,0,1.24345,@ Param=,-0.251327
Point,4.96057,0,0.626666,@ Param=,-0.125664
Point,5,0,-5.55112e-15,@ Param=,0
--------------- edge 2 ---------------
Point,-5,0,0,@ Param=,0
Point,-1.5359,-6,0,@ Param=,6.9282
--------------- edge 3 ---------------
Point,-1.5359,-6,1.88093e-16,@ Param=,-3.14159
Point,-1.49739,-6,0.34177,@ Param=,-2.91719
Point,-1.3838,-6,0.666401,@ Param=,-2.69279
Point,-1.20081,-6,0.957617,@ Param=,-2.46839
Point,-0.957617,-6,1.20081,@ Param=,-2.24399
Point,-0.666401,-6,1.3838,@ Param=,-2.0196
Point,-0.34177,-6,1.49739,@ Param=,-1.7952
Point,9.40467e-17,-6,1.5359,@ Param=,-1.5708
Point,0.34177,-6,1.49739,@ Param=,-1.3464
Point,0.666401,-6,1.3838,@ Param=,-1.122
Point,0.957617,-6,1.20081,@ Param=,-0.897598
Point,1.20081,-6,0.957617,@ Param=,-0.673198
Point,1.3838,-6,0.666401,@ Param=,-0.448799
Point,1.49739,-6,0.34177,@ Param=,-0.224399
Point,1.5359,-6,0,@ Param=,0

#############################

The object was created by a circle extrusion with tapper (30 deg) and followed by a body split.

Please note some minor changes and more serious ones...

reserved and eval are Phyton keywords. It is generally not a good idea using them as object names

so I changed them to reserved_ and faceEval respectively. (Haa, haa ... I made the same mistake in my previous post blindly copying...)

 

Regards

MichaelT

 

PS:

The code was as follows:

def testMarc ( face 😞

    #sel0 = input0.selection(0);

    #face = sel0.entity

    faceEval = face.evaluator

    loops = face.loops

    outerLoop = loops[0]

    fitTolerance = .01 # database units, cm

    # coEdges are 2D in parameter space of the face

    # use edge instead but direction might be reversed

    outputText = ''

    for iedge in range(outerLoop.coEdges.count):

        #print ("--------------- edge " + str(iedge) + "---------------")

        outputText += '--------------- edge ' + str(iedge) + ' ---------------\n'

        ce = outerLoop.coEdges.item(iedge)

        reversed_ = ce.isOpposedToEdge

        e = ce.edge

        faceEval = e.evaluator

        (ret, t0, t1) = faceEval.getParameterExtents()

        tstep = (t1 - t0) / 2.

        if reversed_:

            t0, t1 = t1, t0

            tstep = -tstep

        '''

        (ret, lineFit) = faceEval.getStrokes(t0, t1, fitTolerance)

        for ifit in range(len(lineFit)):

            p = lineFit[ifit].asArray()

            (ret, tFit) = faceEval.getParameterAtPoint(lineFit[ifit])

            if not ret:

                ui.messageBox('getParameterAtPoint_NG')

                return

             print(str(p) + " @ " + str(tFit))

        '''

        (ret, pointsFit) = faceEval.getStrokes(t0, t1, fitTolerance)

        (ret, paramsFit) = faceEval.getParametersAtPoints( pointsFit )

        #'''

        for ifit in range(len(pointsFit)):

            point = pointsFit[ifit]

            param = paramsFit[ifit]

            outputRecord  = 'Point,{:g},{:g},{:g},@ Param=,{:g}\n'.format(point.x, point.y, point.z, param)

            outputText   += outputRecord

            #print(str(point) + " @ " + str(param))

    _ui.messageBox(outputText)

    print( outputText )

    return None

 

 

 

MichaelT
0 Likes
Message 6 of 8

mschafer39KEH
Explorer
Explorer

Hi MichaelT,

I think your example shows that the bug does not affect all geometry which matches my experience.  I created my test case above by revolving a triangle and I can reliably reproduce the incorrect results for almost anything made by revolve.  The add-on I am creating is meant to be applicable to any surface and I think the intent is for getParameterAtPoint to return the correct value regardless of how the geometry was created so I still consider this an open bug.

 

Thanks for the tip about the python reserved keywords.  I will update my code accordingly.

 

-Marc

 

0 Likes
Message 7 of 8

MichaelT_123
Advisor
Advisor

Yes, Mr.Marc

 

There might be something fishy around : 

ConeSurfaceType 2 A cone surface

 

I found some other possible inconsistencies, but for time being let's give TF360  time for the investigation of the issue. 

 

Regards

MichaelT

 

MichaelT
0 Likes
Message 8 of 8

mschafer39KEH
Explorer
Explorer

Bumping this one more time to see if anybody else has ideas or if it will be acknowledged as a bug.

 

Thanks,

Marc

 

0 Likes