phaser/v3/merge/hermite/GetAngleWithDistance.js
2017-09-29 16:38:04 +01:00

24 lines
717 B
JavaScript

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;