LineCurve.js 944 B

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