LineCurve.js 900 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { Curve } from '../core/Curve';
  2. /**************************************************************
  3. * Line
  4. **************************************************************/
  5. function LineCurve( v1, v2 ) {
  6. this.v1 = v1;
  7. this.v2 = v2;
  8. };
  9. LineCurve.prototype = Object.create( Curve.prototype );
  10. LineCurve.prototype.constructor = LineCurve;
  11. LineCurve.prototype.isLineCurve = true;
  12. LineCurve.prototype.getPoint = function ( t ) {
  13. if ( t === 1 ) {
  14. return this.v2.clone();
  15. }
  16. var point = this.v2.clone().sub( this.v1 );
  17. point.multiplyScalar( t ).add( this.v1 );
  18. return point;
  19. };
  20. // Line curve is linear, so we can overwrite default getPointAt
  21. LineCurve.prototype.getPointAt = function ( u ) {
  22. return this.getPoint( u );
  23. };
  24. LineCurve.prototype.getTangent = function( t ) {
  25. var tangent = this.v2.clone().sub( this.v1 );
  26. return tangent.normalize();
  27. };
  28. export { LineCurve };