box2d.b2CircleShape.prototype.ComputeSubmergedArea = function(normal, offset, xf, c) {
/** @type {box2d.b2Vec2} */
var p = box2d.b2Mul_X_V2(xf, this.m_p, new box2d.b2Vec2());
/** @type {number} */
var l = (-(box2d.b2Dot_V2_V2(normal, p) - offset));
if (l < (-this.m_radius) + box2d.b2_epsilon) {
//Completely dry
return 0;
}
if (l > this.m_radius) {
//Completely wet
c.Copy(p);
return box2d.b2_pi this.m_radius this.m_radius;
}
//Magic
/** @type {number} */
var r2 = this.m_radius * this.m_radius;
/** @type {number} */
var l2 = l * l;
/** @type {number} */
var area = r2 (box2d.b2Asin(l / this.m_radius) + box2d.b2_pi / 2) + l box2d.b2Sqrt(r2 - l2);
/** @type {number} */
var com = (-2 / 3 * box2d.b2Pow(r2 - l2, 1.5) / area);
c.x = p.x + normal.x * com;
c.y = p.y + normal.y * com;
return area;
}
Comments