'use strict';
/**
* Defines a Unitcircle
* with center at canvas coordinates ox,oy
* and radius r
*/
var UnitCircle = function (ox, oy, r, el) {
this.x = ox; // x coord of center
this.y = oy; // y coord of center
this.r = r; // radius
this.a = 0; // starting angle
this.cc = true; // angle increasing counterclockwise
this.el = 0; // extra length of arrow
if (el != null)
this.el = el;
}
UnitCircle.prototype.draw = function (baz) {
var ctx = baz.getContext();
ctx.beginPath();
ctx.strokeStyle = 'black';
ctx.arc(this.x, this.y, this.r, 0, Math.PI * 2, true);
ctx.stroke();
ctx.closePath();
}
UnitCircle.prototype.angleDraw = function (baz) {
var ctx = baz.getContext();
ctx.beginPath();
ctx.strokeStyle = 'red';
ctx.moveTo(this.x, this.y);
ctx.lineTo(this.x + this.getRadius() + 10, this.y);
ctx.moveTo(this.x, this.y);
ctx.lineTo(this.getCosEP(), this.getSinEP());
ctx.stroke();
ctx.closePath();
}
UnitCircle.prototype.getRadius = function() {
return this.r;
}
UnitCircle.prototype.getAngle = function() {
return this.a;
}
UnitCircle.prototype.setAngle = function(deg) {
this.a = Math.PI * deg / 180;
}
UnitCircle.prototype.getCc = function() {
return this.cc;
}
UnitCircle.prototype.setCc = function(cc) {
this.cc = cc;
}
UnitCircle.prototype.getSinEP = function() {
return -Math.sin(this.a) * (this.r + this.el) + this.y;
}
UnitCircle.prototype.getCosEP = function() {
return Math.cos(this.a) * (this.r + this.el) + this.x;
}
UnitCircle.prototype.angleInc = function(fracs) {
if (fracs == null)
fracs = 720; // fractions of PI*2
this.a += Math.PI * 2 / fracs;
}