Skip to content
Browse files

Optimise and simplify ellipse code.

  • Loading branch information...
1 parent 9d1a023 commit a87affe9f07bc3e2b1390fc76b68bf42a795a9ad @lehni lehni committed
Showing with 9 additions and 9 deletions.
  1. +9 −9 src/path/Path.js
View
18 src/path/Path.js
@@ -1887,21 +1887,21 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
// dx/dt = a sin(t) cos(phi) + b cos(t) sin(phi) = 0
// derivative of y = cy + b*sin(t)*cos(phi) + a*cos(t)*sin(phi)
// dy/dt = b cos(t) cos(phi) - a sin(t) sin(phi) = 0
- // this can be simplified to:
+ // This can be simplified to:
// tan(t) = -b * tan(phi) / a // x
// tan(t) = b * cot(phi) / a // y
// Solving for t gives:
// t = pi * n - arctan(b * tan(phi) / a) // x
// t = pi * n + arctan(b * cot(phi) / a)
// = pi * n + arctan(b / tan(phi) / a) // y
- var tx = -Math.atan(b * Math.tan(phi) / a),
- ty = Math.atan(b / (Math.tan(phi) * a)),
- // Due to symetry, we don't need to cycle through pi * n solutions:
- x = a * Math.cos(tx) * Math.cos(phi)
- - b * Math.sin(tx) * Math.sin(phi),
- y = b * Math.sin(ty) * Math.cos(phi)
- + a * Math.cos(ty) * Math.sin(phi);
- return [Math.abs(x), Math.abs(y)];
+ var sin = Math.sin(phi),
+ cos = Math.cos(phi),
+ tan = Math.tan(phi),
+ tx = -Math.atan(b * tan / a),
+ ty = Math.atan(b / (tan * a));
+ // Due to symetry, we don't need to cycle through pi * n solutions:
+ return [Math.abs(a * Math.cos(tx) * cos - b * Math.sin(tx) * sin),
+ Math.abs(b * Math.sin(ty) * cos + a * Math.cos(ty) * sin)];
}
/**

0 comments on commit a87affe

Please sign in to comment.
Something went wrong with that request. Please try again.