Home Technical Talk

(Solved) Maya MEL: periodic curve and knots

polycounter lvl 6
Offline / Send Message
bitinn polycounter lvl 6
Hi,

So as far as I can understand, if I got a periodic curve, I need to add knots manually.

What I don't understand, is the value for knots, I have read at least 2 explanation on this but still, I have no idea if using a uniformly increasing value + obeying the (CV Count  + Degree - 1) rules are enough.

So for example, If I have 4 CV, Degree of 3, and is creating a Periodic Curve, I still need 4 + 3 - 1 = 6 Knots. But what are the right values for knots? Is 0 1 2 3 4 5 sufficient? Is -2 -1 0 1 2 3 the same? What are knots "doing"?

So to cite my reading:

- Maya Doc says this:
curve -per on -p 0 0 0 -p 3 5 6 -p 5 6 7 -p 9 9 9 -p 0 0 0 -p 3 5 6 -p 5 6 7 -k -2 -k -1 -k 0 -k 1 -k 2 -k 3 -k 4 -k 5 -k 6;
// This command creates a closed (or "periodic") curve with
// four distinct CVs. You must specify a knot vector when the
// "-per" flag is used. Notice that the first "degree" points
// are the same as the last "degree" points (ie. the first three
// points are the same as the last three points). Notice also
// that the knot spacing between the first "degree" knots must
// be the same as the spacing between the last "degree" knots
// (ie. the space between the 1st and 2nd knots is the same as
// the space between the 7th and 8th knots, and the space between
// the 2nd and 3rd knots is the same as the space between the
// 8th and 9th knots). There must be space between the first
// "degree" knots, unlike the previous example, where the first
// "degree" knots are the same.

- A CG Society thread, but doesn't explain periodic curve

For a cubic curve, degree = 3. (The highest power in the parametric equation). So a degree 1 curve is straightforward linear interpolation. I'll assume that you'll only be wanting cubic curves (which are the lowest degree curves that can maintain continuity. Higher order curves are less efficient to calculate). 

So, given the following 4 points:

A, B, C, D. The knot vector has 4 + 3 - 1 number of knots (i.e. 6). For a curve that gets to the start and end control points, you need to use 0, 0, 0, 1, 1, 1. 
If you used the knot vector 0, 0, 0, 0.5, 0.5, 0.5; the curve would start at the first control point, and end at the mid point of the curve. 

The numbers in the knot vector (eg, 0, 1, 0.5 etc) determine which curve span in the spline. The number of spans is determined with:

num spans = num control points - degree. 

So for a curve with 5 points, there are 2 spans. 6 Control points gives you 3 spans etc. The number of spans will equal the highest value in the knot vector (unless you are dealing with periodic curves - eg circles, but lets forget about that right now....)

All this basically means is that for the following number of control points, you probably want to use the following knot vectors... 

4 points: 0 0 0 1 1 1 
5 points: 0 0 0 1 2 2 2
6 points: 0 0 0 1 2 3 3 3 
7 points: 0 0 0 1 2 3 4 4 4 
8 points: 0 0 0 1 2 3 4 5 5 5
9 points: 0 0 0 1 2 3 4 5 6 6 6
10 points: 0 0 0 1 2 3 4 5 6 7 7 7

Replies

  • bitinn
    Options
    Offline / Send Message
    bitinn polycounter lvl 6
    A more concrete example:

    I know this works:

    curve
      -name "TEST1"
      -periodic 1
      -degree 1
      -point 0 0 0
      -point 1 0 0
      -point 2 0 0
      -point 2 0 1
      -point 2 0 2
      -point 1 0 2
      -point 0 0 2
      -point 0 0 1
      -point 0 0 0
      -knot 0
      -knot 1
      -knot 2
      -knot 3
      -knot 4
      -knot 5
      -knot 6
      -knot 7
      -knot 8;

    But I can't get the degree 3 version of it working, curve doesn't print error or warning, it just does nothing.

    curve
      -name "TEST1"
      -periodic 1
      -degree 3
      -point 0 0 0
      -point 1 0 0
      -point 2 0 0
      -point 2 0 1
      -point 2 0 2
      -point 1 0 2
      -point 0 0 2
      -point 0 0 1
      -point 0 0 0
      -knot 0
      -knot 1
      -knot 2
      -knot 3
      -knot 4
      -knot 5
      -knot 6
      -knot 7
      -knot 8
      -knot 9
      -knot 10;
  • sprunghunt
    Options
    Offline / Send Message
    sprunghunt polycounter
    if you set the periodic value to "0" it works.

    <div>curve</div><div>&nbsp; -name "TEST1"</div><div>&nbsp; -periodic 0</div><div>&nbsp; -degree 3</div><div>&nbsp; -point 0 0 0</div><div>&nbsp; -point 1 0 0</div><div>&nbsp; -point 2 0 0</div><div>&nbsp; -point 2 0 1</div><div>&nbsp; -point 2 0 2</div><div>&nbsp; -point 1 0 2</div><div>&nbsp; -point 0 0 2</div><div>&nbsp; -point 0 0 1</div><div>&nbsp; -point 0 0 0</div><div>&nbsp; -knot 0</div><div>&nbsp; -knot 1</div><div>&nbsp; -knot 2</div><div>&nbsp; -knot 3</div><div>&nbsp; -knot 4</div><div>&nbsp; -knot 5</div><div>&nbsp; -knot 6</div><div>&nbsp; -knot 7</div><div>&nbsp; -knot 8</div><div>&nbsp; -knot 9</div><div>&nbsp; -knot 10</div><div>;</div><div>&nbsp;&nbsp;</div>

  • throttlekitty
    Options
    Offline / Send Message
    I kinda get this, and I kinda don't. As shown in the maya example, the first and last three degrees are to be identical and that we do need incremental knot vectors. I learned that these define how each span is connected, but I don't quite understand why the numbering must be uniform.

    https://www.cl.cam.ac.uk/teaching/1999/AGraphHCI/SMAG/node4.html
    http://cagd.cs.byu.edu/~557/text/ch6.pdf (knot vectors are in section 6.2)

    So with a little different formatting just to make this easier to read, we have a working curve. I chose to split the first/last knot lines in groups of two, because their degree is 3, so I didn't need to worry about renumbering the whole list while I was mucking around. -2, -1, 0 would be the same as 1, 2, 3, but that made it convenient for me to edit from the starting point since I was testing around with different lengths.
    curve -n "deg3_cv8" -per 1 -d 3
    
    -p 0 0 0 -p 1 0 0 -p 2 0 0
    -p 2 0 1 -p 2 0 2 -p 1 0 2 -p 0 0 2 -p 0 0 1
    -p 0 0 0 -p 1 0 0 -p 2 0 0
    
    
    -k -2 -k -1
    -k 0 -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8
    -k 9 -k 10
    ;

    The last degree spans back across the first is important to Maya because reasons. This is why your example was doing nothing, or changing a value in the first or last set in the documentation example would do the same thing. I'm sure if I read up more I'd get it, but this is sufficient enough for me today.

    edit: The thing I really don't get is what happens when I open that curve. I had expected there to be a gap between the last "real" point that i made (-p 0 0 1) and the first (-p 0 0 0), but it drops the first two and last points instead.
  • bitinn
    Options
    Offline / Send Message
    bitinn polycounter lvl 6
    Thx @throttlekitty, that Cambridge lecture note might have taught me to understand how knot vectors work.

    Using the right keyword I can now find an even better (simpler) explanation for close curve:

    https://pages.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/B-spline/bspline-curve-closed.html

    So I finally realise where I don't fully understand: it explains why the first 3 and last 3 control points need to match for a degree 3 close curve.
Sign In or Register to comment.