Permalink
Browse files

Add a function to caluation the control point for a quadratic bezier,…

… so that it fits through 3 points.
  • Loading branch information...
1 parent 9046c50 commit 9ad512ebf8af198b60168179c7e22f76c4e9b6d0 @deanm committed Apr 12, 2009
Showing with 13 additions and 1 deletion.
  1. +13 −1 pre3d_path_utils.js
View
@@ -75,8 +75,20 @@ Pre3d.PathUtils = (function() {
return path;
}
+ // Fits a quadratic bezier curve evenly through 3 points. Returns a control
+ // point that forms a quadratic bezier (with end points p0 and p2) that
+ // crosses through p1 at t=0.5. The time value 0.5 is hardcoded / implicit to
+ // simplify the calculation.
+ function fitQuadraticFromPoints(p0, p1, p2) {
+ return {
+ x: p1.x + p1.x - 0.5 * (p0.x + p2.x),
+ y: p1.y + p1.y - 0.5 * (p0.y + p2.y),
+ z: p1.z + p1.z - 0.5 * (p0.z + p2.z)};
+ }
+
return {
makeCircle: makeCircle,
- makeSpiral: makeSpiral
+ makeSpiral: makeSpiral,
+ fitQuadraticFromPoints: fitQuadraticFromPoints
};
})();

0 comments on commit 9ad512e

Please sign in to comment.