# Determining the co-ordinates on a Hermite Spline for fixed values of x.

This topic is 4256 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've recently been learning about Hermite splines for a pet project I'm working on. However, I've come to realise that there is a problematic complication in this plan. Hermite splines are specified with a point and a tangent vector and points are calculated using functions x(t), y(t) where t is a value between 0 and 1. Unfortunately, I need to be able to determine y, given a value of x. The above method does not allow me to do that. Is it possible to do this with Hermite Splines, or is another type of spline more suitable to my application?

##### Share on other sites
You can always use a numerical method; step along t by (say) 0.1 until you have a segment that brackets the x value you want, then subdivide that part into lengths t=0.01, and so on until you get close enough to the x you're looking for.

I'm not really familiar with Hermite splines, however I imagine one of our resident mathematical geniuses will be along to provide an analytical solution B).

The problem with a parametric spline is that they can have multiple values of y for the same x (or vice versa). The above method will find the first one.

##### Share on other sites
I've faced this problem before too so I've just had a dig through my code archives to remind myself how I did it. I'm at work at the moment so I cant spare the time to remind myself of all the gory details but I can at least give you an overview of the technique I used. Sorry I cant post the code either, this is something I wrote for my employers :/.

Anyway, your cubic will be defined by an array of x,y points through which the spline passes, so the first step is to find the 2 points to the left of the x value your interested in and the two point to the right. For example if your points are (0,y0) (1,y1) (5,y2) (7,y3) (8,y4) and you want to know the value of y at x=6 then you'd use the last 4 points in that list. If your point falls at the end, for example x=0.5, then you'd repeat point (0,y0) twice. These 4 points now describe a curve whose inner section between its two inner anchors accurately represents the original curve. This simplifies the problem since you dont have to deal with the whole curve and in that you know that t=0.5 on this new curve will be close to your desired x value.

Next I used these 4 points taken to calculate the cubic coefficients and the coefficients of the differential of the cubic at the desired x. So what I ended up with was an equation with factors of t, t square, and t cube, and also the equation for its differential for which I need to find the correct value of t which satisfies the equation. Starting with a value of t=0.5 (since I know this is close as explained above) I used an iterative Newton-Raphson solver to shift t around until the shifts in t became small enough that I could consider it to have reached the correct value. Its then simply a case of plugging this t value back into the cubic equation to find y.

Hope thats enough to get you started along the correct path ^^.

##### Share on other sites
You may want to take a look at this thread.

It's possible to determine y from an x numerically (I suggest recursion like the example in the above thread) but not analytically without opening Pandora's box.

I suggest that you rethink your interpolant, if possible. If you expect a unique, well-defined solution to your problem, then the spline can be expressed explicitly, so you should use something better-suited, like cardinal or cubic B-splines.

Regards

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 17
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631758
• Total Posts
3002163
×