Convex Hull Animation

by Matthew Vasallo

HTML

<canvas width="300" height="300" id="canvas"></canvas>

CSS

monotone 120
graham 195
jarvis 91

JavaScript

/*IMPORTS*/
function Vector2(px, py) {
    this.x = px;
    this.y = py;
}

Vector2.prototype.add = function (vector) {
    return new Vector2(this.x + vector.x, this.y + vector.y);
};

Vector2.prototype.sub = function (vector) {
    return new Vector2(this.x - vector.x, this.y - vector.y);
};

Vector2.prototype.mult = function (scalar) {
    return new Vector2(this.x * scalar, this.y * scalar);
};

Vector2.prototype.div = function (scalar) {
    return new Vector2(this.x / scalar, this.y / scalar);
};

Vector2.prototype.eq = function (vector) {
    return (this.x == vector.x) && (this.y == vector.y);
};

Vector2.prototype.neq = function (vector) {
    return (this.x != vector.x) || (this.y != vector.y);
};

Vector2.prototype.magnitude = function () {
    return Math.sqrt(Math.pow(this.x, 2) + Math.pow(this.y, 2));
};

Vector2.prototype.distanceTo = function (vector) {
    return Math.sqrt(Math.pow(this.x - vector.x, 2) + Math.pow(this.y - vector.y, 2));
};

Vector2.prototype.angleBetween = function (vector) {
    if (this.eq(vector)) return 0;
    var mag1 = this.magnitude();
    var mag2 = vector.magnitude();
    var dot = this.dot(vector);
    return Math.acos(dot / (mag1 * mag2));
};

Vector2.prototype.magSQ = function () {
    return Math.pow(this.x, 2) + Math.pow(this.y, 2);
};

Vector2.prototype.normalize = function () {
    var mag = this.magnitude();
    return new Vector2(this.x / mag, this.y / mag);
};

Vector2.prototype.lerp = function (vector, p) {

    return new Vector2(this.x + ((vector.x - this.x) * p), this.y + ((vector.y - this.y) * p));

};

Vector2.prototype.midpoint = function (vector) {
    return this.lerp(vector, 0.5);
};

Vector2.prototype.dot = function (vector) {
    return (this.x * vector.x) + (this.y * vector.y);
};

Vector2.prototype.scale = function (vector) {
    return new Vector2(this.x * vector.x, this.y * vector.y);
};

Vector2.prototype.polarAngle = function () {
    return Math.atan2(this.y,...