Cleanup solveCubic() further.

This commit is contained in:
Jürg Lehni 2013-04-21 08:44:41 -07:00
parent 2fc4ff10ee
commit dc9a9c42d2
2 changed files with 12 additions and 11 deletions

View file

@ -301,7 +301,7 @@ var Curve = this.Curve = Base.extend(/** @lends Curve# */{
if (t >= -tolerance && t < 1 - tolerance) {
var pt = Curve.evaluate(vals, t, true, 0);
/*#*/ if (options.debug) {
console.log(t, point.y, pt.y);
console.log(t, point + '', pt + '');
new Path.Circle({
center: Curve.evaluate(vals, t, true, 0),
radius: 2,

View file

@ -180,18 +180,19 @@ var Numerical = this.Numerical = new function() {
if (abs(q) < epsilon) { // One triple solution.
roots[0] = - b;
return 1;
} else { // One single and one double solution.
var sqp = sqrt(p),
snq = q > 0 ? 1 : -1;
roots[0] = -snq * 2 * sqp - b;
roots[1] = snq * sqp - b;
return 2;
}
} else if (D < 0) { // Casus irreducibilis: three real solutions
}
// One single and one double solution.
var sqp = sqrt(p),
snq = q > 0 ? 1 : -1;
roots[0] = -snq * 2 * sqp - b;
roots[1] = snq * sqp - b;
return 2;
}
if (D < 0) { // Casus irreducibilis: three real solutions
var sqp = sqrt(p),
phi = Math.acos(q / (sqp * sqp * sqp)) / 3,
o = 2 * PI / 3,
t = -2 * sqp;
t = -2 * sqp,
o = 2 * PI / 3;
roots[0] = t * cos(phi) - b;
roots[1] = t * cos(phi + o) - b;
roots[2] = t * cos(phi - o) - b;