CubicBezierCurve.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { CubicBezier, TangentCubicBezier } from '../core/Bezier';
  2. import { Curve } from '../core/Curve';
  3. import { Vector2 } from '../../math/Vector2';
  4. /**************************************************************
  5. * Cubic Bezier curve
  6. **************************************************************/
  7. function CubicBezierCurve( v0, v1, v2, v3 ) {
  8. this.v0 = v0;
  9. this.v1 = v1;
  10. this.v2 = v2;
  11. this.v3 = v3;
  12. }
  13. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  14. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  15. CubicBezierCurve.prototype.getPoint = function ( t ) {
  16. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  17. return new Vector2(
  18. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  19. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  20. );
  21. };
  22. CubicBezierCurve.prototype.getTangent = function ( t ) {
  23. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  24. return new Vector2(
  25. TangentCubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  26. TangentCubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  27. ).normalize();
  28. };
  29. export { CubicBezierCurve };