2
0
Fork 0
mirror of https://github.com/photonstorm/phaser synced 2024-12-22 02:53:27 +00:00
phaser/v3/merge/hermite/GetAngleWithDistance.js

25 lines
717 B
JavaScript
Raw Normal View History

2017-01-05 15:46:47 +00:00
var GetAngle = require('./GetAngle');
var FindT = require('./FindT');
/**
* Calculate and return the angle, in radians, of the curves tangent at the given pixel distance along the curves length.
*
* @param {number} [distance=0] - The distance along the curve to get the angle from, in pixels.
* @return {number} The angle of the line at the specified distance along the curve. The value is in radians.
*/
var GetAngleWithDistance = function (curve, distance)
{
if (distance === undefined) { distance = 0; }
if (distance <= 0)
{
return Math.atan2(this._v1y, this._v1x);
}
else
{
return GetAngle(curve, FindT(curve, distance));
}
};
module.exports = GetAngleWithDistance;