content/hifi-content/dave/walk-tools/walkTools/libraries/three.js/extras/curves/EllipseCurve.js
2022-02-13 22:49:05 +01:00

49 lines
1.1 KiB
JavaScript

/**************************************************************
* Ellipse curve
**************************************************************/
THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise ) {
this.aX = aX;
this.aY = aY;
this.xRadius = xRadius;
this.yRadius = yRadius;
this.aStartAngle = aStartAngle;
this.aEndAngle = aEndAngle;
this.aClockwise = aClockwise;
};
THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
THREE.EllipseCurve.prototype.getPoint = function ( t ) {
var deltaAngle = this.aEndAngle - this.aStartAngle;
if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
var angle;
if ( this.aClockwise === true ) {
angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
} else {
angle = this.aStartAngle + t * deltaAngle;
}
var vector = new THREE.Vector2();
vector.x = this.aX + this.xRadius * Math.cos( angle );
vector.y = this.aY + this.yRadius * Math.sin( angle );
return vector;
};