# Circle

#####

declaration
Circle

Creates a MathLib circle
MathLib.Circle expects two arguments.
First the center in the form of an Array or a MathLib.point.
The second argument should be the radius of the circle.

#### Simple use case:

    // Create a circle with center (1, 2) and radius 3.
    var c = new MathLib.Circle([1, 2], 3);
    c.center                   // The center of the circle (point)
    c.radius                   // returns the radius of the circle

    var Circle = (function () {
    		function Circle (center, radius) {
    			this.type = 'circle';
    			if (center.type === undefined) {
    				center = new MathLib.Point(center.concat(1));
    			}

    			this.center = center;
    			this.radius = radius;
    		}

# area

#####

method
Circle.prototype.area() → number

Calculates the area of the circle.

    Circle.prototype.area = function () {
    			return this.radius * this.radius * Math.PI;
    		};

# circumference

#####

method
Circle.prototype.circumference() → number

Calculates the circumference of the circle.

    Circle.prototype.circumference = function () {
    			return 2 * this.radius * Math.PI;
    		};

# compare

#####

method
Circle.prototype.compare() → number

Option name | Type | Description
--- | --- | ---
circle | Circle | The circle to compare

Compares two circles

    Circle.prototype.compare = function (circle) {
    			return MathLib.sign(this.center.compare(circle.center)) || MathLib.sign(this.radius - circle.radius);
    		};

# draw

#####

method
Circle.prototype.draw() → Circle

Option name | Type | Description
--- | --- | ---
screen | Screen | The screen to draw onto.
options | object | Optional drawing options

Draw the circle onto the screen.

    Circle.prototype.draw = function (screen, options) {
    			if (Array.isArray(screen)) {
    				var circle = this;
    				screen.forEach(function (x) {
    					x.circle(circle, options);
    				});
    			}
    			else {
    				screen.circle(this, options);
    			}
    			return this;
    		};

# isEqual

#####

method
Circle.prototype.isEqual() → boolean

Option name | Type | Description
--- | --- | ---
circle | Circle | The circle to compare

Checks if two circles are equal

    Circle.prototype.isEqual = function (circle) {
    			return MathLib.isEqual(this.radius, circle.radius) && this.center.isEqual(circle.center);
    		};

# positionOf

#####

method
Circle.prototype.positionOf() → string

Option name | Type | Description
--- | --- | ---
point | Point | The Point to determine the position of

Determine if a point is in, on or outside a circle.

    Circle.prototype.positionOf = function (point) {
    			var diff;
    			if (point.type === 'point' && point.dimension === 2) {
    				diff = point.distanceTo(this.center) - this.radius;
    				if (MathLib.isZero(diff)) {
    					return 'on';
    				}
    				else if (diff < 0) {
    					return 'in';
    				}
    				else {
    					return 'out';
    				}
    			}
    		};

# reflectAt

#####

method
Circle.prototype.reflectAt() → Circle

Reflect the circle at a point or line

    Circle.prototype.reflectAt = function (a) {
    			return new MathLib.Circle(this.center.reflectAt(a), this.radius);
    		};

# toLaTeX

#####

method
Circle.prototype.toLaTeX() → string

Returns a LaTeX expression of the circle

    Circle.prototype.toLaTeX = function () {
    			return 'B_{' + MathLib.toLaTeX(this.radius) + '}\\left(' + this.center.toLaTeX() + '\\right)';
    		};

# toMatrix

#####

method
Circle.prototype.toMatrix() → Matrix

Converts the circle to the corresponding matrix.

    Circle.prototype.toMatrix = function () {
    			var x = this.center[0] / this.center[2], y = this.center[1] / this.center[2], r = this.radius;
    			return new MathLib.Matrix([[1, 0, -x], [0, 1, -y], [-x, -y, x * x + y * y - r * r]]);
    		};
    		return Circle;
    	})();
    	MathLib.Circle = Circle;
    })(MathLib || (MathLib = {}));