Grasshopper

algorithmic modeling for Rhino

Does anyone understands Catmull-Rom interpolation?

I've managed to do an implementation of Catmull-Rom splines using Bezier Spans, even though I don't completly understand the math involved.

My objective was to be able to constrain the curve to avoid the overshooting that the native interpolate occasionally does. I was able to constrain the max distance from the curve to the control polygon controlling the length of the vectors.

The problem is I don't really know how to resolve the start and end segments. I put together a hack but I'm a bit unsure about it.

Also I would like some critique on the definition itself.

Views: 2722

Attachments:

Replies to This Discussion

Hmm ...

1. Give this a quick reading: http://www.mvps.org/directx/articles/catmull/

2. So ... let's assume that we have a "closable" List of points (Bool close "shifts" indices kinda like the native List item wrap option).

Close = false:

Close = true:

3. let's assume that we have a "non closable" List of points.

Close = false:

Close = true:

BTW: If you are interested on the insides of "shifting" this is how it's done:

First of all thank you for your attention.

I think however you misundurtood a couple of things, I didn't code anything, it's all made with native components in a cluster. I just used a formula to get the control vectors to feed to the bezier span component.

My objective was to get those tangents so I could manipulate the curve by limiting their length (wich I was able to do)

My problem was only with the first and last segments when the curve is open. (in your case the 0 to 1 and 7 to 8 segments) because those are not usually calculated.

Your aproach is a bit different than mine, did you use the direct formula to get the points from the parameter, sample 3 points and interpolate them?

By the way, did you open the file? the link to the paper with the formula I used is inside.

Oh and I don't know how to code yet, I´m trying to learn C# but I'm not there yet. so I can only kind of understand what you did there.

Maybe I'll go to the dark side soon :P

Well ...

I think that you completely misunderstood the scope of the images provided:

Obviously are made due to some code that does CR interpolation ... BUT ...their scope has nothing to do with coding (besides I haven't attached any def). They are used only to indicate the relation between the pairs of points VS the previous/next one in cases related with closed/open curves.

Meaning that if we have a "first" point (the 0) that we wish to act as the start point in an open curve (from the points that we are trying to calculate) and a "last" point (the 8) that we wish to act as the end point ... the CR logic doesn't apply for pairs 0-1 and 7-8 since for a given pair you need a "guide" previous and a "guide" next point.

I have no problems with closed curves, in fact in the file I posted there's a solved closed curve. The problem is only with open curves.

the CR logic doesn't apply for pairs 0-1 and 7-8 since for a given pair you need a "guide" previous and a "guide" next point.

My problem is exactly this. You can use the CR logic to calculate the backward tangent on point 1 but you can't for the forward tangent on 0.

I've found 3 ways this can be solved:

- Repeat point 0  - solve the first segment as P0, P0, P1, P2 - this leads to a zero length tangent at 0 (same aplies for last point)

"pure reflection of the first and last segments about the endpoints" - p.9 - I think I know what they mean but not sure it's a good result

- "one-sided differences used for the first and last piece" - This one seems interesting but I don't have a clue what they mean

Er ... obviously you have no problems with closed curves.

Back to open ones:  One way to "cheat" on that matter is to add a point PRIOR p0 (the first) and AFTER pN (the last) ... thus fooling the CR algo to include the missing 2 pairs (since p0 would become the 2nd point and pN the penultimate).

Cheat points could be defined by adding a smallish vector derived from, say, p0-p1 for the first/second points  (and the ultimate/penultimate).

So do a vector = p0-p1 then unitize it and make the first cheat point PRIOR p0:

p0 + (vector * someFactor) ... then insert that to your pts List (at index 0).

Do the same with the last and just add it to the List.

That's what I think they mean with reflection, it has the problem of pinching the curve in the end:

Do you happen to know what "one-sided differences" is and how I can do that?

Use this for "cheating" on first/last points. Then insert new First (at index 0) and just add new Last.

Yes that's pretty much what I did, but it this cheat produces that weird pinch of the curve near the end. I wish I knew what "one-sided difference" is, it seems to make a smoother end...

Well ... forgot to state the "obvious":

Interpolate your points into a curve, extend it "a bit" both sides and then get the curve start Pt as the new First and the curve end Pt as the new Last.

Anyway, since you've mentioned it, if and when you decide to cross the Rubicon ... notify me to send you the thingy captured that "exposes" the CR logic rather clearly.

Haha well that one sounds like to much cheating. I would love checking out your code, even if I don't fully understand it I'll probably learn something.

OK, get the thingy with the primitive cheating (using "smallish" vectors) and I'll add the extend curve cheating - as Plan B - later on.

Attachments:

No need for plan B, I think I got what I need.

And anyway, we are doing things in a different way, you are calculating points directly. I calculated the vectors and then used bezier spans.

I'll just leave the original cheating I had it's easier.

Thank you for your time. :)

P.S. I'm still reading your code

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service