File: src/shapes/Capsule.js
var Shape = require('./Shape')
, vec2 = require('../math/vec2')
module.exports = Capsule;
/**
* Capsule shape class.
* @class Capsule
* @constructor
* @extends {Shape}
* @param {Number} length The distance between the end points
* @param {Number} radius Radius of the capsule
*/
function Capsule(length,radius){
this.length = length || 1;
this.radius = radius || 1;
Shape.call(this,Shape.CAPSULE);
};
Capsule.prototype = new Shape();
/**
* Compute the mass moment of inertia of the Capsule.
* @method conputeMomentOfInertia
* @param {Number} mass
* @return {Number}
* @todo
*/
Capsule.prototype.computeMomentOfInertia = function(mass){
// Approximate with rectangle
var r = this.radius,
w = this.length + r, // 2*r is too much, 0 is too little
h = r*2;
return mass * (h*h + w*w) / 12;
};
Capsule.prototype.updateBoundingRadius = function(){
this.boundingRadius = this.radius + this.length/2;
};