mfg

06-22-2012, 07:07 PM

Hi all,

I am trying to divide a curve in equidistant straight line segments. The code so far works but I would like to get better accuracy and speed.

This is the kind of accuracy I get so far, with spacing 1.0:

…

1.00482071963

1.00659363694

1.00426146343

1.00045259905

1.0097287904

1.00428835113

...

I can use python api if that helps but maybe there is a better basic approach to speed things up?

import math

import maya.OpenMaya as om

import maya.cmds as mc

def eqDistanceCurveDivide(curvename,segmentcurveLength):

uValeStart=0.0

curveLength=mc.arclen(curvename)

kk=(int(curveLength/segmentcurveLength))

intCL=int(curveLength)

accur=100*intCL

uVale=1.0/accur

for t in range(kk):

for i in range(accur):

pointA=mc.pointOnCurve(curvename,top=True, pr=uValeStart, p=True )

vecA=om.MVector(pointA[0],pointA[1],pointA[2])

pointB=mc.pointOnCurve(curvename,top=True, pr=uVale, p=True)

vecB=om.MVector(pointB[0],pointB[1],pointB[2])

vecC=om.MVector()

vecC=(vecB-vecA)

distance=vecC.length()

if distance<segmentcurveLength:

uVale+=1.0/accur

else:

uValeStart=uVale

break

mc.spaceLocator(p=(pointB[0],pointB[1],pointB[2]))

if uValeStart>=0.99:

break

eqDistanceCurveDivide('curve1',1.0)

I am trying to divide a curve in equidistant straight line segments. The code so far works but I would like to get better accuracy and speed.

This is the kind of accuracy I get so far, with spacing 1.0:

…

1.00482071963

1.00659363694

1.00426146343

1.00045259905

1.0097287904

1.00428835113

...

I can use python api if that helps but maybe there is a better basic approach to speed things up?

import math

import maya.OpenMaya as om

import maya.cmds as mc

def eqDistanceCurveDivide(curvename,segmentcurveLength):

uValeStart=0.0

curveLength=mc.arclen(curvename)

kk=(int(curveLength/segmentcurveLength))

intCL=int(curveLength)

accur=100*intCL

uVale=1.0/accur

for t in range(kk):

for i in range(accur):

pointA=mc.pointOnCurve(curvename,top=True, pr=uValeStart, p=True )

vecA=om.MVector(pointA[0],pointA[1],pointA[2])

pointB=mc.pointOnCurve(curvename,top=True, pr=uVale, p=True)

vecB=om.MVector(pointB[0],pointB[1],pointB[2])

vecC=om.MVector()

vecC=(vecB-vecA)

distance=vecC.length()

if distance<segmentcurveLength:

uVale+=1.0/accur

else:

uValeStart=uVale

break

mc.spaceLocator(p=(pointB[0],pointB[1],pointB[2]))

if uValeStart>=0.99:

break

eqDistanceCurveDivide('curve1',1.0)