# How to create a curve which follows the position of severals points ?

 03 March 2007 arketip Frequenter   arketip Bruxelles, Belgium How to create a curve which follows the position of severals points ? Hello, I search for the way to smooth an edge selection. So i have an array of points... The problem is : how to create a curve passing approximately by these points? Lets say the curve will be simple... share quote
 03 March 2007 mbousquet CGFreelancer   Michele Bousquet Senior Editor CG Freelancer Magazine New Orleans, USA I'm not sure if this is what you're looking for, but this is what you can use to build a line from some points. ``````( -- Initialize line new_spline = splineShape() addnewspline new_spline cRad = 50 -- A number for the curve radius cAng = 23 -- Some random angle -- Throw some point3 values (coordinates) in an array just to have something. -- Using sin and cos to set some lines in a curve. pointArray = for i = 1 to 10 collect [cRad*(sin(i*cAng)),cRad*(cos(i*cAng)),0] -- Add points in array to construct the line for i in pointArray do addknot new_spline 1 #smooth #curve i ) `````` share quote
03 March 2007
Just by curiosity:
I don't know if I am alone having a crash when I edit the vertices of the spline ?
But if I add the line "updateShape new_spline" at the end then it don't crash anymore.
Well that isn't very important.

I realize I was not very precise in my request.
I am trying to give you a complete explanation:

I want to create a tool for modelers.
The modeler have an edge selection but the curve of these edges is a bit chaotic.
Because of that, the surface generated by the subdivision surface of this curve isn't very clean.
I avoid that by editing it manually (I use some tools to displace the vertices or I recreate some new edges with cut function).
The goal is to obtain a very smooth curve.

So the problem is not to follow exactly the postion of the points but to be able of creating a perfect curve using a cloud of points. It is more a mathematical problem.

It is easier to show it than to say it. Then here is a plan:
Attached Images
 curve.gif (1.7 KB, 184 views)

 03 March 2007 mbousquet CGFreelancer   Michele Bousquet Senior Editor CG Freelancer Magazine New Orleans, USA This looks like a NURBS CV curve. share quote
 03 March 2007 rdg random data generator   portfolio Georg Duemlein New Zealand Quote: But if I add the line "updateShape new_spline" at the end then it don't crash anymore. Well that isn't very important. It is very important to add updateShape() after modifying a spline Your image indeed looks like a nurbs or bezier curve. There is a mathematically *easy* version of bezier curves that are described by 4 points only. But I guess you need the full version. http://local.wasp.uwa.edu.au/~pbour..._curves/bezier/ Georg __________________ Georg Duemlein share quote
 03 March 2007 arketip Frequenter   arketip Bruxelles, Belgium Thanks for the reply rdg. To be honest I had hoped to find a less complex solution for smoothing the edges. Bezier curves are really core mathematics... share quote
 03 March 2007 Rivendale Right here   portfolio Carl-Mikael Lagnecrantz CG artist Stockholm, Sweden Hey Arketip, how about taking the vert that is "highest up" and "lowest down" and calculating that distance. Then get the middle position of all edges, go straigth "up" from that position by the amount of the first distance and you have a position. Create a spline with three knots and set the end knots to the verts of the edges farthest away from each other and set the middle knot to the position you got above the middle. If you set the knot type to Smooth for the middle knot you will have a curve that you can align the verts of the edges to. I hope that made sense, I'm a bit tired. CML __________________ PolyBoost Tools for 3ds max share quote
 03 March 2007 eek Fixer   portfolio Charles Looker Snr Technical Artist Electronic Arts Vancouver, Canada That sounds like a quadratic way of generating a curve - that a degree of n2. Way to slow for something a little more complex that 4-5 points. I'd use a bernstien polynormial of maybe a nth degree of 3, nurbs curves which are a bezier curve projection into 4d space, using conic sections is very complicated to write and I still find pretty hard to do. So ontop of building a respective curve, be it cardinal (a curve that goes through your set aproximated points) or a bezier curve which infact what you want is a b-spline, which is several bezier curves joined together. (the math for the sections isnt too hard, and infact the algorithm for the polynormial isnt either) - your have to do some aproximation math on the points firstly: 1.to get the 'best fit' selection of points, maybe based on distance to each other. 2. then get an 'average' point made of these selections or maybe a vector to 3. build your aproximated spline. Im just thinking out loud (love trying ideas out), so grab every say 10 points that are close to each other, build an average vector from that. Think you'll need a modular function on a per 10 vector basis. `````` r = 0 aprxVecs=#() for v = 1 to vecs.count do ( if mod((v 10)-1) == 0 then ( r = 0 ) else ( if distance (vecs[v] vecs[(v+1)) < 10 do ( r = r + vecs[v] ) append aprxVecs (r/10) ) ) `````` umm.. something like that. may need to put a distance fn in there some where. Then you'll need a polynomial to quantify the curve, hmm.. you'll need to do some percentage based section stuff, a bezier curve segment relies on 4 control points (tangents) its how these tangents are derived that the difference between a cardinal and a bezier curve. Nurbs are a lot different. First off id build a spline using a simple for loop and knot creation methods. If you want something a little more custom then yell! Your aproximation is the most important part, as you may not want distance but edge detection etc. __________________ Disclaimer: My opinions are not those of my employer. Last edited by eek : 03 March 2007 at 05:27 AM. share quote
 03 March 2007 PEN R&D/Technical Director   portfolio Paul Neale PEN Productions Canada This is a quadratic curve but really is the basis for others. If you pass it 20 points I'm sure that it would get slow. I use this in rigs and it is faster then using Max splines. How ever I usualy set it up so that it is only using sets of four points each. __________________ Paul Neale http://paulneale.com share quote
03 March 2007
Thanks very much !

Tonight i only had the time to do a little test based on the middle of the edges.

1. find the middle of the edges
2. & 3. a new curve appears but the points aren't positioned correctly...
4. Then 2 options are possible:
Either i find the middle of this new edges but it is a little bit to far for several points.
Or i project the old point on this new curve (at the right)
5. The smoothed final curve.

mmmhhh that is not very good. The edges are smoothed but the shape is lost.

I will try another idea tomorrow
Attached Images
 smoothing03.gif (8.8 KB, 214 views)

 03 March 2007 Rivendale Right here   portfolio Carl-Mikael Lagnecrantz CG artist Stockholm, Sweden Hey Arketip, I couldn't help playing around with this idea since I think it is a very good one. Would you mind if I included a similar tool in the PolyBoost tools? I think it would be appreciated by the users. My idea is to generate smooth curves of edges/edgeloops where the curvature is based on the position of the selected verticses along the loops. I'm using splines to form the curves. I already have something that is working fairly well and can be used on multiple edgeloops at once to curve a whole surface, feels like working with patches or nurbs a bit. Some examples...the top images is the initial vertex selection along selected loops, in the bottom the tool is applied: What do you think? I don't want to rip you off if this idea is something you are going to use commercially or something. cheers, CML __________________ PolyBoost Tools for 3ds max share quote
 03 March 2007 eek Fixer   portfolio Charles Looker Snr Technical Artist Electronic Arts Vancouver, Canada anyone know how to store an array of vertex indices, the order they were selected? I can get an array but it sorts them the second they become an array? eg 13,17,12 becomes 12,13,17!! __________________ Disclaimer: My opinions are not those of my employer. share quote
 03 March 2007 Light Let there be Light   Houdini FX TD Animatrix Montreal, Canada Hi Charles, You can't. I know because I asked Larry about it before. Only way would be to use a callback or timer, but if the user select multiple SOs, then it becomes uncertain. Also depending on what you want to do with it, you could also make a tool to pick them (using the tool clause). Light share quote

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off CGSociety Society of Digital Artists www.cgsociety.org Powered by vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.