var Vector2 = function(x, y) { this.x = x; this.y = y; } Vector2.prototype = { "length": function () { return Math.sqrt(this.x * this.x + this.y * this.y); }, "normalize": function () { var inv = 1 / this.length(); return new Vector2(this.x * inv, this.y * inv); }, "add": function (v) { return new Vector2(this.x + v.x, this.y + v.y); }, "multiply": function (f) { return new Vector2(this.x * f, this.y * f); }, "dot": function (v) { return this.x * v.x + this.y * v.y; }, "angle": function (v) { return Math.acos(this.dot(v) / (this.length() *v.length())) * 180 / Math.PI; } } var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); var points = [{x:10, y:500}, {x:60, y:300},{x:110, y:400}, {x:160, y:100},{x:210, y:200}, {x:260, y:500}]; var cps = getControlPoint(points); ctx.strokeStyle="#000000"; ctx.beginPath(); ctx.moveTo(points[0].x, points[0].y); for(var i=0;i