Get y from x on the cardinal spline curve

  • Thread starter mishalkk
  • Start date
  • Tags
    Curve
In summary, the cardinal spline curve can be used to get the Y value along the curve for a given x. The function is very normal looking, so you would only have 1 real solution. However, there are 2 methods to find the point on the curve. One is to solve a cubic equation, and the other is to use a numerical method.
  • #1
mishalkk
4
0
Hi,

I have implemented the cardinal spline curve. ref link:- http://www.ibiblio.org/e-notes/Splines/Cardinal.htm

My requirement is to get the Y Value along the spline curve for a given x.Please look at the image attached below.

Here P1,P2,P3,P4 are my Points and cardinal spline passes through these points. But how can I find the point along the curve whose x-value is given.How can I find out the point of intersection?

2v01mbn.jpg
 
Physics news on Phys.org
  • #2
What you need to do is find the value of t (or whatever your parameter is called) that produces the desired value of x (1.5 in your case). Should be close to 0.5 if you are using parameter range of 0 to 1 and the plot is to scale. Once you know t you can calculate the corresponding value of y. In this case, you have to solve a cubic, which in general can have 3 values of t that produce the same x. In your case, the function is very normal looking, so you would only have 1 real solution. As far as I know, there are basically two choices, (1) solve the cubic algebraically (internet search will help find the formula) or (2) use a numerical method such as Newton-Raphson or subdivision. Thus is the challenge when using parametric equations.
 
Last edited:
  • #3
Thank you .I have followed the above method.

Formula : P(t) = s(-t3 + 2t2 – t)P1 + s(-t3 + t2)P2 + (2t3 – 3t2 + 1)P2 + s(t3 – 2t2 + t)P3 + (-2t3 + 3t2)P3 + s(t3 – t2)P4

where P is the point on the curve,P1,P2,P3,P4 are the actual points, s is the tanget and it is inversely proportional to t. and t is the tension. I calculate P(t)x and P(t)y co ordinates for the t varying from 0 to 1.

But these points are approximate. Not exact. I need to get the exact position on the curve.

Can anyone suggest me any methods with which I can find the point on the curve?

Or how the points are drawn using the actual points and control points?

Thank you
 
  • #4
Hi mishalkk! :smile:

I'm not sure where your "s" comes from.
I don't see it in your reference.
Is it simply s=1/t?

Either way, you should have a parametric curve P(t) consisting of P(t)x and P(t)y.
Solve P(t)x=1.5 to find t, and substitute in P(t)y, as hotvette said.

The difficulty of course is to solve P(t)x=1.5 for which you need to solve a cubic equation.
Do you need help with that?
 
  • #5
Hi,

Thank you for your reply :)
http://algorithmist.wordpress.com/2009/09/28/cardinal-splines-part-2/

Cardinal splines specify the tangents at interior points based on the vector from previous point to subsequent point. Each tangent is parallel to this vector and some multiple of its length. For example, the tangent direction at point P1 is parallel to the vector P2 – P0, or we could simply write something like T1 = s(P2 – P0) where s is a real number.

Here is the pat of the code.
xtarget is the input value X, here in my case 1.5

Code:
 for (Double t = 0; t<=1; t += 0.01)
  {
      s = (1 - t) / 2;
P(t)x = s(-t3 + 2t2 – t)P1X + s(-t3 + t2)P2X + (2t3 – 3t2 + 1)P2X + s(t3 – 2t2 + t)P3X + (-2t3 + 3t2)P3X + s(t3 – t2)P4X

P(t)y = s(-t3 + 2t2 – t)P1Y + s(-t3 + t2)P2Y + (2t3 – 3t2 + 1)P2Y + s(t3 – 2t2 + t)P3Y+ (-2t3 + 3t2)P3Y + s(t3 – t2)P4Y

if(P(t)x=>xtarget)
{
return P(t)y;
}
-----------------
I get P(t)y which is approximate. But it is not the exact point on the curve(sometimes it is not on the curve). I need to get the exact points on the curve..ie P(t)y which is exactly on the curve.Any help is appreciated.

Thank you :)
 
  • #6
I got it :)
 

1. How do I determine the value of y for a given x on the cardinal spline curve?

In order to determine the value of y for a given x on the cardinal spline curve, you will need to use the equation of the curve. The equation takes into account the x and y coordinates of the control points that define the curve, as well as the tension parameter. By plugging in the x value into the equation, you can solve for the corresponding y value.

2. What is the tension parameter in the cardinal spline curve equation?

The tension parameter in the cardinal spline curve equation is a value that controls the tightness of the curve. A higher tension parameter will result in a smoother and tighter curve, while a lower tension parameter will result in a more relaxed and looser curve.

3. How do I choose the control points for a cardinal spline curve?

The control points for a cardinal spline curve should be chosen carefully to ensure that the curve accurately represents the desired shape. Generally, the control points should be evenly spaced along the curve and should be positioned in a way that defines the desired curvature. There are also mathematical algorithms that can help determine the optimal placement of control points for a given curve.

4. Can I use the cardinal spline curve for any type of data?

The cardinal spline curve can be used for a wide range of data, including numerical, categorical, and even time-series data. It is a versatile curve that can accurately represent many types of data, making it a popular choice for data visualization and analysis.

5. Is the cardinal spline curve a type of interpolation or extrapolation?

The cardinal spline curve is a type of interpolation, meaning that it is used to estimate values between known data points. It is not suitable for extrapolation, which is the process of estimating values outside of the known data range. Attempting to use the cardinal spline curve for extrapolation can lead to inaccurate and unreliable results.

Similar threads

Replies
5
Views
1K
Replies
4
Views
996
Replies
3
Views
318
Replies
4
Views
2K
Replies
10
Views
1K
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Differential Equations
Replies
5
Views
474
Replies
3
Views
2K
Replies
4
Views
1K
Back
Top