Jump to content

Get y from x on the cardinal spline curve

- - - - -

  • Please log in to reply
5 replies to this topic

#1
mayasmitha

mayasmitha

    Newbie

  • Members
  • PipPip
  • 13 posts
Hi,

I have implemented the cardinal spline curve. ref link:- Interpolating Cardinal and Catmull-Rom splines

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?

Posted Image

Thanks & Regards,
Mayasmitha

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
If you have the curve, you should be able to evaluate it for given values of x.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java

WingedPanther said:

If you have the curve, you should be able to evaluate it for given values of x.
I assume his main problem will be finding the curve with the given 4 points ;)

#4
mayasmitha

mayasmitha

    Newbie

  • Members
  • PipPip
  • 13 posts
Thank you for your reply :) Actually I am trying to get a point on the curve.

http://algorithmist.....plines-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. I want to find the point on the curve whose X co ordinate is 1.5(xtarget)

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 :)

#5
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java

Quote

sometimes it is not on the curve
Is it close to the curve then? Cause if it is, try using the BigDecimal class instead of using doubles, as doubles loose some precision.

#6
mayasmitha

mayasmitha

    Newbie

  • Members
  • PipPip
  • 13 posts
Yes I got it. Thank you :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users