2

I have an equation that looks like this:

$$ y = \sqrt{ ((at^3+bt^2+ct+d) - (et+f))^2 + ((gt^3+ht^2+it+j) - (kt+l))^2 } $$ [original image: https://i.stack.imgur.com/oSw67.png]

But I have to make this a function of $y$ instead of a function of $t$, and I'm totally stuck on where to even begin. Could anyone give me advice on where to start, or perhaps solve my problem?

EDIT: (Context)
One circle moves along a cubic bezier curve and another moves along a linear bezier curve. Between $0 ≤ t ≤ 1$, at what t values does the two circles collide if the radius of them both is a total of $y$ (distance between the two circles)?

  • 3
    Where are you getting this problem from? What is the context? –  Mar 17 '14 at 21:44
  • What do mean, make it a function of $y$? You mean invert it to get $t(y)$? (For what it's worth, if that's what you're after you're going to be out of luck, unless a lot of those constants are zero/cancel.) – user7530 Mar 17 '14 at 21:50
  • 1
    Its not at all going to be easy I think. – Sawarnik Mar 17 '14 at 21:51
  • @user7530 I mean, there's probably some method or another if OP wants to use hypergeometric functions. But I've got my doubts that he's after an answer of that form ;) –  Mar 17 '14 at 21:57
  • Didn't expect to get a reply this quickly! Anyway, yes... I do believe I would want to invert it to get t(y). So there's no way to do this then? (I'm going to update soon trying to explain the context of my problem) – user1974555 Mar 17 '14 at 21:59
  • Let's put it this way: there's no way to do this that you'd actually want to carry out. But if you're trying to invert $y$ on the way to doing something else (calculating $dt/dy$, or calculating the curvature of some curve, etc) there may be a more indirect approach. – user7530 Mar 17 '14 at 22:03
  • I just updated the question with the problem itself – user1974555 Mar 17 '14 at 22:08
  • Are you expecting to get a nice, analytic solution? Or is a numerical algorithm OK? – user7530 Mar 17 '14 at 22:13
  • My goal is to be able to use this function for programming purposes, and that's why I can't have it in its current form. t(y) would be the best way to go, but it might now be possible as the others mentioned – user1974555 Mar 17 '14 at 22:15

1 Answers1

0

So for a fixed, known $y$, you want to solve $$f(t)=g(t) - y^2 = 0$$ for $t\in [0,1]$, where $g$ (and hence $f$) are sixth-degree polynomials in $t$. Generally speaking, it won't be possible to solve for this $t$ exactly. Standard practice in computer graphics is to find $t$ numerically using a polynomial root-finding algorithm: my personal recommendation is the Jenkins-Traub algorithm (source code here: www.crbond.com/download/misc/rpoly.cpp‎), which is both fast and robust.

EDIT: To use rpoly, simplify the above polynomial so that it has the form $$a_0 t^6 + a_1t^5 + a_2 t^4 + a_3 t^3 + a_4 t^2 + a_5 t + a_6 = 0.$$

I am going to assume that $a_0$ is well away from $0$ (otherwise there are stability complications beyond the scope of this answer).

You can find all of the zeros using code along the following lines:

double op[7];
double zeror[7];
double zeroi[7];
op[0] = a0;
op[1] = a1;
op[2] = a2;
op[3] = a3;
op[4] = a4;
op[5] = a5;
op[6] = a6;

rpoly(op, 6, zeror, zeroi, NULL);

The real and imaginary parts of the roots will now be inside zeror and zeroi. Ignore all non-real roots (those whose imaginary part is greater than some threshold) and look for those real roots that lie between 0 and 1. I'm not sure if you're looking for the first time the two balls collide, or all times they collide, etc. but whatever case it is you should be able to extract that information from the roots.

user7530
  • 49,280
  • Could you recommend a good explination of this Jenkins-Traub algorithm? And I'm not quite sure what functions in the linked source code is relevant to my problem and how to use them to provide me with an answer. – user1974555 Mar 17 '14 at 22:29
  • The algorithm is described in the paper here: http://dl.acm.org/citation.cfm?id=355643&coll=ACM&dl=ACM but I strongly recommend against trying to implement the algorithm yourself -- reuse an existing implementation (such as the one I linked to). If you don't want to do so, another root-finding algorithm (i.e. the eigenvalue method) will work in a pinch, if slightly slower/less reliably. – user7530 Mar 17 '14 at 22:32
  • In the code the only function you call yourself is rpoly(). – user7530 Mar 17 '14 at 22:33
  • Is there any demonstration of the implementation which you linked me in your answer? Because I can't wrap my head around it where to start inputting my values into this classfile (P.S. the later comment you posted came up delayed. I'll look into it now) – user1974555 Mar 17 '14 at 22:36
  • Based on my math problem, what values do I have to enter in the rpoly() function? (double op, int degree, double zeror, double *zeroi, int info[]) I'm not sure what it wants me to enter here – user1974555 Mar 17 '14 at 22:40