How to solve a cubic equation with three roots without knowing the terms? Is there any way of solving $ax^3+bx^2+cx+d=0$, which I know has three roots, without knowing what $a, b, c$, and $d$ equal? I've tried using the formula that uses $p, q$, and $r$, though that always just returns undefined.
An example of what the cubic equation might be is $4x^3-6x^2+1=0$.
EDIT:
Saying "not knowing the terms" was a bad choice of wording. The thing is that the values of $a, b, c$, and $d$ change, so I don't want an answer that relies on factoring or something similar because they would only work on certain values of $a, b, c$, and $d$.
EDIT 2:
I'm not doing this in code.
EDIT 3:
Here's a simplified example of what I'm trying to do: https://www.desmos.com/calculator/gsjtv0qnwn
I'm trying to find where the red equation intersects the x-axis. Black lines are also at these points. The blue line that is Cardano's Formula does not exist because $4p^3+27q^2$ is not greater than $0$.
 A: Using Cardano's Formula can involve imaginary cube roots, even in some cases where the roots are real. Here is a method to get the real roots without resort to complex numbers.

Identities
Start with the cubic equation
$$
x^3+px^2+qx+r=0\tag1
$$
Let $x=y-\frac p3$, then $(1)$ becomes
$$
y^3-\frac{p^2-3q}3\,y=-\frac{2p^3-9pq+27r}{27}\tag2
$$
Using the identities
$$
\begin{align}
4\cos^3(u)-3\cos(u)&=\cos(3u)\tag{3a}\\
4\cosh^3(u)-3\cosh(u)&=\cosh(3u)\tag{3b}\\
4\sinh^3(u)+3\sinh(u)&=\sinh(3u)\tag{3c}
\end{align}
$$
and multiplying by $\frac{a^3}4$, we get
$$\newcommand{\sgn}{\operatorname{sgn}}
\begin{align}
(a\cos(u))^3-\frac{3a^2}4(a\cos(u))&=\frac{a^3}4\cos(3u)\tag{4a}\\
(a\cosh(u))^3-\frac{3a^2}4(a\cosh(u))&=\frac{a^3}4\cosh(3u)\tag{4b}\\
(a\sinh(u))^3+\frac{3a^2}4(a\sinh(u))&=\frac{a^3}4\sinh(3u)\tag{4c}
\end{align}
$$

Real Solutions
Let $b=-\frac{2p^3-9pq+27r}{27}$ and $\sgn(b)=2[b\ge0]-1$ (Iverson brackets).
If $p^2=3q$, then
$$
x=-\frac p3+b^{1/3}\tag5
$$
If $p^2\gt3q$, then let $a=\frac23\sgn(b)\sqrt{p^2-3q}$, and
if $\frac{4b}{a^3}\le1$, then
$$
x=-\frac p3+a\cos\left(\frac13\cos^{-1}\left(\frac{4b}{a^3}\right)+\left\{0,\frac{2\pi}3,-\frac{2\pi}3\right\}\right)\tag6
$$
else if $\frac{4b}{a^3}\gt1$, then
$$
x=-\frac p3+a\cosh\left(\frac13\cosh^{-1}\left(\frac{4b}{a^3}\right)\right)\tag7
$$
If $p^2\lt3q$, then let $a=\frac23\sgn(b)\sqrt{3q-p^2}$, then
$$
x=-\frac p3+a\sinh\left(\frac13\sinh^{-1}\left(\frac{4b}{a^3}\right)\right)\tag8
$$
