Ask Your Question

Revision history [back]

Solving a quartic equation

I'm attempting to rearrange an equation from an answer on the Mathematics StackExchange.

The answer given is this equation:

$$L^2 = (-ab(t)+p)^2-\left(\frac{(-ab(t)+p).(cd(t)-ab(t))}{(cd(t)-ab(t))^2}(cd(t)-ab(t))\right)^2$$

Where $a$, $b$, $c$, $d$, and $p$ are known 2D points, $L$ is a known length, and $t$ is an unknown scalar. $ab(t)$ indicates interpolation between $a$ and $b$.

I am interested in rearranging this to solve for $t$. Here's what I've tried in Sage:

def sqr(var): return var.dot_product(var)
var('ax bx cx dx px ay by cy dy py t L')
a = vector([ax, ay])
b = vector([bx, by])
c = vector([cx, cy])
d = vector([dx, dy])
p = vector([px, py])
g = a - at + bt
h = c - ct + dt
u = p - g
v = h - g
eq = L^2 == sqr(u) - sqr((u.dot_product(v)/sqr(v)) * v)
eq.solve(t)

At the solve step I have observed it to sit for quite a while without producing a result. Two questions:

  1. Am I inputting the problem correctly?

  2. Is there any way to know if this is likely to terminate in a reasonable time? I have no idea what the solver looks like under the hood, and wouldn't want to wait for some O(n!) calculation to terminate :)