Click to See Complete Forum and Search --> : Cubic Sline with constraints
sgrya1
Dec 13th, 2007, 12:16 PM
Hi all,
I have a problem in trying to fit a continuous 3 eqn curve to five points but with constraints. VBA Hack has helped be significantly with a similar problem but I now need to adapt it.
Basically I have the information in the attached picture.
Information I have:
X and Y coords of the start and end of the curve.
the gradient at the ends = 0
Curvature =0 at two known X coords.
Gradient = 0 at one known Y coord.
Is this enough information to find the three equations of the curve?
This is what I've put together but I only have 9 of the 12 required equations to work out the 12 variables (a-l). I don't know what to do with the lowest point of the curve where I have the y coordinate and the gradient. But at best I can maybe get two equations out of that point. Can anyone help or advise me?
Cubic Eqn 1 y = ax³ + bx² + cx + d
Gradient y' = 3ax² + 2bx + c
Curvature y'' = 6ax + 2b
Cubic Eqn 2 y = ex³ + fx² + gx + h
Gradient y' = 3ex² + 2fx + g
Curvature y'' = 6ex + 2f
Cubic Eqn 3 y = ix³ + jx² + kx + l
Gradient y' = 3ix² + 2jx + k
Curvature y'' = 6ix + 2j
Eqn 1: y1 = ax1³ + bx1² + cx1 + d .......... End Point 1
Eqn 2: y2 = ix2³ + jx2² + kx2 + l ............ End Point 2
Eqn 3: y'(x1) = 0 = 3ax1² + 2bx1 + c .......... Gradient at End Point 1=0
Eqn 4: y'(x2) = 0 = 3ix2² + 2jx2 + k ............ Gradient at End Point 2=0
Eqn 5: 0 = ax3³+ bx3² + cx3 + d - ex3³ - fx3² - gx3 - h ..... join point is common to Eqn 1 and Eqn 2
Eqn 6: 0 = ex3³+ fx3² + gx3 + h - ix3³ - jx3² - kx3 - l ..... join point is common to Eqn 1 and Eqn 2
Eqn 7: 0 = 3ax3² + 2bx3 + c - 3ex3² - 2fx3 - g ............... Gradient continuity at join point
Eqn 7: 0 = 3ex3² + 2fx3 + g - 3ix3² - 2jx3 - k ................. Gradient continuity at join point
Eqn 8: 0 = 6ax3+ 2b - 6ex3 - 2f .................... curvature continuity at join point
Eqn 9: 0 = 6ex3+ 2f - 6ix3 - 2j ...................... curvature continuity at join point
VBAhack
Dec 14th, 2007, 09:59 PM
Hi, it's me. It's been a day and a half and nobody has responded, so I will.
What you've done looks correct, though I didn't check all the equations in detail. But, you have 10, not 9. There are two equation #7's.
That leaves 2 equations. To me this looks very similar to a cubic spline interpolation situation where you have to make an assumption about the end conditions, in this case the curvature. If the curve represents some physical item, like a beam, then the end conditions depend on the physical constraints. One obvious choice is zero curvature at either end. Mathematically, there are multiple solutions (if not infinitely many) because of these last 2 constraints, but logic and knowledge of the situation should result in a reasonable solution.
An engineering approach might be to try several different values for curvature at either end to see how the results vary. If they don't vary much, then you pretty much have the solution. If they vary a lot (whatever alot is) then you'll need to look further at the physical constraints like I mentioned above. Since you don't have any constraints on y values for the interior points, my guess is that the solutions will vary substantially depending on the choices of curvature at the ends. I still like zero curvature at either end as a starting point.
By the way, there are multiple ways to fit 3 curves to 5 points. I assume the middle curve has 3 points.
Edit: I keep perpetuating a mistake of equating curvature and 2nd derivative. They aren't the same. If the 1st derivative is very small, then the 2nd derivative approximates curvature. Simplified beam theory is based on this approximation.
:)
sgrya1
Dec 15th, 2007, 09:10 AM
Hi VBAHack! I was going to write on the previous thread asking you to look at it.
Right you are! 10 equations! 2 left. Or 1 if I use two cubic splines and one parabola?
The ends will have curvature as the curve hits a high point at then repeats the same 5 point curve so I can’t apply equations there, but you’ll see that I haven’t yet been able to add equations for the middle point where I know the value of y and the gradient =0.
The derived equation for curvature is currently a function of x. As I don’t have the x value at this point I don’t know what to do.
The middle curve has 3 points. At the two ends, we only know the position of x and that the gradient matches the adjoining curve and that the curvature is 0. At one the internal point of the middle curve we know the y value and that the gradient at this point is 0.
I’ve started looking through your tutorials. Great work!
VBAhack
Dec 15th, 2007, 05:46 PM
The ends will have curvature as the curve hits a high point at then repeats the same 5 point curve so I can’t apply equations there, but you’ll see that I haven’t yet been able to add equations for the middle point where I know the value of y and the gradient =0.
Wait, are you saying the composite curve shown keeps repeating? If so, then I think there is promise. Let's say you have 10 such curves that are all the same and keep repeating. By writing the compatibility equations (including matching 2nd derivatives at the ends of each composite segment), all you'd need to do is make an assumption about the 2nd derivative at each end of the entire series (assumming the string of curves doesn't go on forever). I think you'll find that the shapes of the interior curves won't depend very much on the end conditions at either extreme end. Try it with just 3 composite curves (36 equations) and see what changes in the middle one based on the 2nd derivative of the extreme ends. I hope this makes sense.
Thanks for the comment on the tutes. In the summer, I re-discovered the tri-diagonal cubic spline formulation I'd learned a gazillion years ago in graduate school, and figured I better write something up for my own use so I could easily refresh in the future. One thing let to another.......
sgrya1
Dec 17th, 2007, 03:45 AM
It's sort of a wave pattern but all the wave's are different. So the start and end points won't have matching curvature.
I think I need to make an educated guess on the x position of the low point. A ratio of the two end points. With that x position I will have the 11th and 12 equations. It's not perfect but am hoping it will do the job.
VBAhack
Dec 19th, 2007, 12:39 AM
I took a closer look. I think what you proposed (3 cubics connecting 5 points) is actually over constrained, not under constrained. There aren't enough equations. Each of the 2 join points takes up 4 constraints:
- common point (C0 continuity)
- common 1st derivative (C1 continuity)
- common 2nd derivative (C2 continuity)
- specific value for 2nd derivative
That's 8 constraints so far. Add one for the center point 1st derivative. Add 2 for each end point (specific point, specific 1st derivative). That totals 13 but you only have 12 parameters.
If you made it 4 cubics instead of 3, then it would work (16 parameters):
- 3 join points that take 4 constraints each = 12
- 2 end points that take 2 constraints each = 4
This will provide a unique solution for the geometry you show in the sketch. The only problem is that you can't have 2nd derivative continuity for the curves on either side, if that's important.
sgrya1
Dec 19th, 2007, 05:25 AM
VBAHack.
I can’t thank you enough!!
I’ve just been through a similar ordeal trying to fit these curves as I did last time though this time it I’m sure it was a lot quicker because of what you’ve showed me previously. I’ve been scratching my head for ages about why the curves weren’t fitting together. I’ve had two other people pouring over the problem and they have been as dumbstruck as me. I was on the verge of posting the excel file when I honed in on the problem and twigged that you had pointed out in the previous thread. What might be considered an oddity in excel but is probably not an oddity by any mathematician.
-X² does not give the same result as –(X²)
Genius! Thanks for that!
Result attached. One thing I didn't want was to have to specify the X location of point 3. But the assumption looks fine!
VBAhack
Dec 19th, 2007, 11:38 AM
Glad it worked out. :)
sgrya1
Dec 23rd, 2007, 06:33 AM
VBAhack, can you, or someone, help me out again?
There's a minor glitch in what I have. For some combinations of points, the derived equation for the central cubic spline has both positive and negative curvature. It needs to be one or the other. Basically the first and last segments of the curve can only have positive curvature while the middle segment has the negative curvature (or vice versa).
A quadratic solution for the three curves would enforce single curvature but then I wouldn't have enough variables to satisfy the number of constraints that I have. Can you suggest a different equation to a cubic spline or some way I could avoid this double curvature?
sgrya1
Jan 5th, 2008, 10:06 AM
I finally worked it out. I used 4 parabolic equations (ie 12 variables) and the following equations.
1 Point 1 (Eqn1)
2 Point 2 (Eqn1)=Point 2(Eqn2)
3 Point 3 (Eqn2)
4 Point 3 (Eqn3)
5 Point 4 (Eqn3)=Point 4(Eqn 4)
6 Point 5 (Eqn4)
7 Gradient 1(Eqn1)=0
8 Gradient 2(Eqn1)=Gradient2(Eqn2)
9 Gradient 3(Eqn2)=0
10 Gradient 3(Eqn3)=0
11 Gradient 4(Eqn3)=Gradient4(Eqn4)
12 Gradient 5(Eqn4)=0
Curvature in parabolas never hit's 0 but at least they have single curvature. The curvature is constant apparently which confuses me. It's not perfect but it seems to do the trick. Also, as it's structural, a parabolic fit is what I should have been after in the first place. Turns out to be a considerable difference in the shape of the two.
I realized also though that regression analysis applies if you need to fit a curve given too many constraints.
Thanks again though VBAHack. Happy New Year!
sgrya1
Jan 5th, 2008, 10:13 AM
On another note, I need to find the radius of curvature at any given point. The double derivative of curvature gives does not seem to be a radius of curvature. Anyone know how I equate this?
Edit : RoC = 1/Curvature. That didn't take too long to find. Sorry.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.