mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Commit experimental root fixing code.
This commit is contained in:
parent
4924d683e4
commit
8a2a9409bd
1 changed files with 13 additions and 4 deletions
|
@ -176,11 +176,20 @@ var Numerical = new function() {
|
|||
// This sqrt is safe, since Q3 >= 0, and thus Q >= 0
|
||||
v1 = -2 * sqrt(Q);
|
||||
v2 = b / 3;
|
||||
// TODO: Improve these values using findRoot()!
|
||||
function f(x) {
|
||||
// Normalized, a * x = x:
|
||||
return ((x + b) * x + c) * x + d;
|
||||
}
|
||||
function df(x) {
|
||||
return (3 * x + 2 * b) * x + c;
|
||||
}
|
||||
function fix(t) {
|
||||
return Numerical.findRoot(f, df, t, -10, 10, 32, Numerical.TOLERANCE);
|
||||
}
|
||||
return [
|
||||
v1 * cos(theta / 3) - v2,
|
||||
v1 * cos((theta + 2 * PI) / 3) - v2,
|
||||
v1 * cos((theta - 2 * PI) / 3) - v2
|
||||
fix(v1 * cos(theta / 3) - v2),
|
||||
fix(v1 * cos((theta + 2 * PI) / 3) - v2),
|
||||
fix(v1 * cos((theta - 2 * PI) / 3) - v2)
|
||||
];
|
||||
} else { // One real root
|
||||
var A = -Math.pow(abs(R) + sqrt(R2 - Q3), 1 / 3);
|
||||
|
|
Loading…
Reference in a new issue