joint(s)


    
    function Joint(pointMassA, pointMassB, shortConst, longConst)
    {
      this.pointMassA = pointMassA; 
      this.pointMassB = pointMassB; 
      this.delta = new Vector(0.0, 0.0);     
      this.pointMassAPos = pointMassA.getPos(); 
      this.pointMassBPos = pointMassB.getPos(); 
      
      this.delta.set(this.pointMassBPos); 
      this.delta.sub(this.pointMassAPos); 
      
      this.shortConst = this.delta.length() * shortConst; 
      this.longConst = this.delta.length() * longConst; 
      this.scSquared = this.shortConst * this.shortConst; 
      this.lcSquared = this.longConst * this.longConst; 
  
      this.setDist = function(shortConst, longConst)
      {
        this.shortConst = shortConst; 
        this.longConst = longConst; 
        this.scSquared = this.shortConst * this.shortConst; 
        this.lcSquared = this.longConst * this.longConst;     
      }
      this.scale = function(scaleFactor)
      {
        this.shortConst = this.shortConst * scaleFactor; 
        this.longConst = this.longConst * scaleFactor; 
        this.scSquared = this.shortConst * this.shortConst; 
        this.lcSquared = this.longConst * this.longConst;     
      }
      this.sc = function()
      {      
        this.delta.set(this.pointMassBPos); 
        this.delta.sub(this.pointMassAPos); 
  
        var dp = this.delta.dotProd(this.delta);
        
        if(this.shortConst != 0.0 && dp < this.scSquared)
        {
          var scaleFactor; 
          
          scaleFactor = this.scSquared / (dp + this.scSquared) - 0.5; 
          
          this.delta.scale(scaleFactor);
         
          this.pointMassAPos.sub(this.delta); 
          this.pointMassBPos.add(this.delta); 
        } 
        else if(this.longConst != 0.0 && dp > this.lcSquared)
        {
          var scaleFactor;
          
          scaleFactor = this.lcSquared / (dp + this.lcSquared) - 0.5; 
          
          this.delta.scale(scaleFactor);
         
          this.pointMassAPos.sub(this.delta); 
          this.pointMassBPos.add(this.delta);       
        }
      } 
    }