lethexa-motionpredict.js
function(myPos, myVelo, targetPos, targetVelo) {
    var relTargetPos = mf.sub(targetPos, myPos);
    var a = mf.lengthSquared(targetVelo) - myVelo * myVelo;
    var b = 2.0 * mf.dot(targetVelo, relTargetPos);
    var c = mf.lengthSquared(relTargetPos);

    if( a === 0 ) {
      if( b !== 0 ) {
        var time = -c / b;
        if( time > 0.0 )
          return time;
      }
    }
    else {
      // P und Q berechnen...
      var p = b / a;
      var q = c / a;

      // Quadratische Gleichung lösen...
      var times = this.quadEquation(p, q);
      if( times.length === 0 )
        return [];

      if( times.length === 2 ) {
        var icptTime = Math.min(times[0], times[1]);
        if( icptTime < 0.0 ) {
          icptTime = Math.max(times[0], times[1]);
        }
        return icptTime;
      }
      else if( times.length === 1 ) {
        if( times[0] >= 0.0 ) {
          return times[0];
        }
      }
    }
    return undefined;
  }
function(myPos, myVelo, targetPos, targetVelo) {
    var relTargetPos = mf.sub(targetPos, myPos);
    var a = mf.lengthSquared(targetVelo) - myVelo * myVelo;
    var b = 2.0 * mf.dot(targetVelo, relTargetPos);
    var c = mf.lengthSquared(relTargetPos);

    if( a === 0 ) {
      if( b !== 0 ) {
        var time = -c / b;
        if( time > 0.0 )
          return time;
      }
    }
    else {
      // P und Q berechnen...
      var p = b / a;
      var q = c / a;

      // Quadratische Gleichung lösen...
      var times = this.quadEquation(p, q);
      if( times.length === 0 )
        return [];

      if( times.length === 2 ) {
        var icptTime = Math.min(times[0], times[1]);
        if( icptTime < 0.0 ) {
          icptTime = Math.max(times[0], times[1]);
        }
        return icptTime;
      }
      else if( times.length === 1 ) {
        if( times[0] >= 0.0 ) {
          return times[0];
        }
      }
    }
    return undefined;
  }
function ( myPos , myVelo , targetPos , targetVelo ) { var relTargetPos = mf . sub ( targetPos , myPos ) ; var a = mf . lengthSquared ( targetVelo ) - myVelo * myVelo ; var b = 2.0 * mf . dot ( targetVelo , relTargetPos ) ; var c = mf . lengthSquared ( relTargetPos ) ; if ( a === 0 ) { if ( b !== 0 ) { var time = - c / b ; if ( time > 0.0 ) return time ; } } else { // P und Q berechnen... var p = b / a ; var q = c / a ; // Quadratische Gleichung lösen... var times = this . quadEquation ( p , q ) ; if ( times . length === 0 ) return [ ] ; if ( times . length === 2 ) { var icptTime = Math . min ( times [ 0 ] , times [ 1 ] ) ; if ( icptTime < 0.0 ) { icptTime = Math . max ( times [ 0 ] , times [ 1 ] ) ; } return icptTime ; } else if ( times . length === 1 ) { if ( times [ 0 ] >= 0.0 ) { return times [ 0 ] ; } } } return undefined ; }
Calculates the intercepttime to the target at a given speed.
@method calcInterceptTime
@param myPos {Vector3d} The position of the interceptor.
@param myVelo {Number} The velocity at which the target should be intercepted.
@param targetPos {Vector3d} The position of the target.
@param targetVelo {Vector3d} The velocity and direction in which the target is moving.
@return {Number} The time from now at which the target is reached.
@for motionpredict
Calculates the intercepttime to the target at a given speed .