Ejemplo n.º 1
0
double FuzzyVariable::DeFuzzifyCentroid(int NumSamples)const
{
 
  double StepSize = (m_dMaxRange - m_dMinRange)/(double)NumSamples;

  double TotalArea    = 0.0;
  double SumOfMoments = 0.0;

  
  for (int samp=1; samp<=NumSamples; ++samp)
  {
   
    MemberSets::const_iterator curSet = m_MemberSets.begin();
    for (curSet; curSet != m_MemberSets.end(); ++curSet)
    {
      double contribution = 
          MinOf(curSet->second->CalculateDOM(m_dMinRange + samp * StepSize),
                curSet->second->GetDOM());

      TotalArea += contribution;

      SumOfMoments += (m_dMinRange + samp * StepSize)  * contribution;
    }
  }

  
  if (isEqual(0, TotalArea)) return 0.0;
  
  return (SumOfMoments / TotalArea);
}
Ejemplo n.º 2
0
		Vector2 TikiSteering::Arrive(const Vector2& targetPos, const Deceleration decel)
		{
			Vector2 ToTarget = targetPos - tikiBot->Pos();

			//calculate the distance to the target
			float dist = ToTarget.Length();

			if (dist > 0)
			{
				//because Deceleration is enumerated as an int, this value is required
				//to provide fine tweaking of the deceleration..
				const float DecelerationTweaker = 0.3f;

				//calculate the speed required to reach the target given the desired deceleration
				float speed =  dist / ((float)decel * DecelerationTweaker);     

				//make sure the velocity does not exceed the max
				speed = MinOf(speed, (float)tikiBot->MaxSpeed());

				//from here proceed just like Seek except we don't need to normalize 
				//the ToTarget vector because we have already gone to the trouble of calculating its length: dist. 
				Vector2 DesiredVelocity =  ToTarget * speed / dist;

				return (DesiredVelocity - tikiBot->Velocity());
			}

			return Vector2::Zero;
		}