top of page
Search
cedarcantab

Studying Box2D-Lite in Javascript, Part 5.4: Submerged Area of Circle

Updated: Mar 1



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;

}

7 views0 comments

Recent Posts

See All

p2 naive broadphase

var Broadphase = require('../collision/Broadphase'); module.exports = NaiveBroadphase; /** * Naive broadphase implementation. Does N^2...

sopiro motor constranit

import { Matrix2, Vector2 } from "./math.js"; import { RigidBody } from "./rigidbody.js"; import { Settings } from "./settings.js";...

Comments


記事: Blog2_Post
bottom of page