View Full Version : divide curve equidistant straight line

 mfg06-22-2012, 06:07 PMHi 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=0.99: break eqDistanceCurveDivide('curve1',1.0)
NaughtyNathan
06-23-2012, 12:03 AM

mfg
06-25-2012, 09:22 AM
Thx, but that wont help me, I want to enter a specific value for the segment length, and I dont need to preserve the last cv. Also the resulting points should be positioned on the original 3 degree curve.

when i use "rebuildCurve" to rebuild a 3 degree curve to a 1 degree curve i get the following:
- the distance between the segments are not equal
- the resulting points are not positioned on the original 3 degree curve

verbatimline
06-25-2012, 05:48 PM
would this work with chordlength parameterization,

uParam = (spacing/arclength);

get point at uParam

zoharl
06-25-2012, 10:35 PM
Maybe you'll find here something:

mfg
06-26-2012, 09:30 AM
thx, i have read through that post and unless i missed something, this is what your suggested code does: equal distance along u-param

i need equidistant straight Line distance so i can not use findParamAtLength.

http://i46.tinypic.com/1268srd.jpg

This is the kind of accuracy i get when i use the intersection node. For a curve in 3d i would need to intersect shperes, and maya does not have a command for nurbs surface - nurbs curve intersection. so you would have to extrude the curve temporarily and intersect surface with surface.

http://i49.tinypic.com/osddo0.jpg

This is what my inefficient code from the first post does, i just want better accuracy and a bit more speed.

http://i49.tinypic.com/2dquazc.jpg

Export curve to Rhino rebuild with "DivideCurveEquidistant" export back to maya:

http://i48.tinypic.com/17raeq.jpg

i understand maya is not a cad software, but it cant be that hard to create a tool that does this : http://wiki.mcneel.com/developer/sdksamples/dividecurvestraight

or maybe it is. i am not a math major ; )

tontonsuspect
06-26-2012, 12:05 PM
First of all, when using an iterative approach you needs to be aware of precision issue and decide for an acceptable tolerance value: you cant cut corner you have precision at the cost of speed .

Have you thought of using an IK spline solver with a joint chain?

Then on your code you use a command that in the background create then destroy a node to sample position on a curve: I would rather create once a pointOnCurveInfo and then bash it over and over to return the information I need. Same thing for your MVector create two outside the loop then modify its component

zoharl
06-27-2012, 05:20 AM
1. I liked tonton's idea to create a 2-joint chain and attach them to the curve using ik spline handle.

2. As you suggested, extruding the curve with a circle profile with a vanishing radius, should approximate the curve with a tube. You'll get two points of intersection with a sphere, and you can average them.

3. You can always go hardcore. Each part of the nurbs curve consists of a certain degree polynomial (usually 3). Extract the polynomial coefficients from the nurbs knots and control points, and intersect this polynomial with a parametric sphere. If the polynomial degree isn't too high, you should have a closed form expression.

mfg
06-27-2012, 08:02 AM
thx, guys
I am reading up on IK spline solver now, never used them before. ill post back the result :)

CGTalk Moderation
06-27-2012, 08:02 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.

1