【问题标题】:How to get the arclen between two curve points in Maya?如何在 Maya 中获得两个曲线点之间的 arclen?
【发布时间】:2016-11-08 09:21:44
【问题描述】:

在 Maya 2015 中,我可以使用以下命令获取曲线的 arclen:

cmds.arclen('bezier1')

但现在我想得到曲线中两点的弧线。有没有办法得到这个?

【问题讨论】:

    标签: maya maya-api


    【解决方案1】:

    使用 Maya API,您可以使用 MFnNurbsCurve::findLengthFromParam(仅限 Maya 2016+)。如果你需要在两点之间,然后用每个参数调用这个函数并减去。

    如果您不想使用 api,那么另一个选项是创建原始曲线的副本并在需要的点处使用“分离”它,然后在新曲线上使用 arclen 命令来获取您的长度.所以这是另一种方式。

    请注意,在分离曲线时,它似乎试图使曲率尽可能接近原始曲线,但这并不准确,因此与原始曲线相比,长度可能不同。如果这对您来说是一个重要因素,也许重建曲线以获得更多点可能会提高准确性。

    【讨论】:

    • 感谢回答,所以Maya2015中没有这个api吗?
    • 查看文档,看起来并非如此。你可以自己写一个,但如果你研究近似 b 样条的长度,它会有点复杂
    • 但是如果曲线变换上有比例变换,我将如何计算长度?
    【解决方案2】:

    正如@scottiedoo 所说,使用 Maya 的 API 无疑是最好的方法,但这是我在不了解 API 时创建的一个函数,它可以为您提供相同的结果。

    from maya import cmds
    
    def computeCrvLength(crv, startParam = None, endParam = None):
        '''
        Compute the length of a curve between the two given UParameters. If the both
        UParameters arguments are set to None (default), will compute the length of
        the whole curve.
    
        Arguments:
        - crv = string; an existing nurbCurve
        - startParam = 0 <= float <= 1 or None; default = None; point parameter
          value, if not None, will compute the points only between the startPt and
          EndPt values.
        - endParam = 0 <= float <= 1 or None; default = None; point parameter
          value, if not None, will compute the points only between the startPt and
          EndPt values.
    
        Returns:
        - The length of the curve between the given UParameters
        - The length of the curve from its start to the startParam
        - The length of the curve from its start to the endParam
        '''
    
        ###### Exceptions
        if cmds.objExists(crv) == False:
            cmds.error ('The curve "%s" does\'nt exists.' % crv)
    
        if cmds.filterExpand (crv, sm = 9) == None:
            cmds.error ('The object "%s" is not a nurbCurve.' % crv)
    
        if startParam != None:
            if (0 <= startParam <= 1) == False:
                cmds.error ('The start point parameter value must be between 0 and 1.')
    
        if endParam != None:
            if (0 <= endParam <= 1) == False:
                cmds.error ('The end point parameter value must be between 0 and 1.')
    
        if (startParam == None and endParam != None) or (startParam != None and endParam == None):
            cmds.error ('The start and end points parameters must be both None or ' + 
                        'both have values.')
    
        if startParam != None and endParam != None:
            if endParam < startParam:
                cmds.error ('The end point parameter value cannot be less or ' + 
                            'equal to start point parameter value.')
    
        ###### Function
        if startParam == None and endParam == None:
    
            crvLength = cmds.arclen (crv, ch = False)
            distCrvToStartParam = 0
            distCrvToEndParam = crvLength
    
        else:
    
            tmpArclenDim = cmds.arcLengthDimension (cmds.listRelatives(crv, s = True)[0]
                                                    + '.u[0]')
            cmds.setAttr (cmds.listRelatives(tmpArclenDim, p = True)[0] +
                          '.uParamValue', startParam)
            distCrvToStartParam = cmds.getAttr (tmpArclenDim + '.al')
            cmds.setAttr (cmds.listRelatives(tmpArclenDim, p = True)[0] +
                          '.uParamValue', endParam)
            distCrvToEndParam = cmds.getAttr (tmpArclenDim + '.al')
            cmds.delete (tmpArclenDim)
            crvLength = (distCrvToEndParam - distCrvToStartParam)
    
        return crvLength, distCrvToStartParam, distCrvToEndParam
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-18
      • 1970-01-01
      • 2022-11-07
      • 1970-01-01
      相关资源
      最近更新 更多