UNPKG

ngraph.forcelayout3d

Version:
29 lines (24 loc) 728 B
/** * Represents 3d drag force, which reduces force value on each step by given * coefficient. * * @param {Object} options for the drag force * @param {Number=} options.dragCoeff drag force coefficient. 0.1 by default */ module.exports = function (options) { var merge = require('ngraph.merge'), expose = require('ngraph.expose'); options = merge(options, { dragCoeff: 0.02 }); var api = { update : function (body) { body.force.x -= options.dragCoeff * body.velocity.x; body.force.y -= options.dragCoeff * body.velocity.y; body.force.z -= options.dragCoeff * body.velocity.z; } }; // let easy access to dragCoeff: expose(options, api, ['dragCoeff']); return api; };