CubicBezierCurve.js 974 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**************************************************************
  2. * Cubic Bezier curve
  3. **************************************************************/
  4. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  5. this.v0 = v0;
  6. this.v1 = v1;
  7. this.v2 = v2;
  8. this.v3 = v3;
  9. };
  10. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  11. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  12. var tx, ty;
  13. tx = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  14. ty = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  15. return new THREE.Vector2( tx, ty );
  16. };
  17. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  18. var tx, ty;
  19. tx = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  20. ty = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  21. var tangent = new THREE.Vector2( tx, ty );
  22. tangent.normalize();
  23. return tangent;
  24. };