Пример #1
0
void Obstaculo::calTTC(float v, float antiguo)
{   float m ;
    float b;
     if(dir->getx()==0)
      m =  0;
     else
      m = dir->gety()/dir->getx();
    if(dir->getx()==0 || m==0) b = centro->gety();
    else
     b = centro->gety()/(m*centro->getx());
    Punto* corte = new Punto(0.0,b,90);

    if (b>0 && velocidad > 0 && v>0)
    {
        float tobstaculo = (centro->distanciaPunto(corte))/(velocidad/3.6);
        Punto* coche = new Punto(0,0,90);
        float tcoche = (coche->distanciaPunto(corte))/(v/3.6);
        if (fabs(tobstaculo-tcoche) > 10)
            TTC = -1;
        else
        {
            if (antiguo!=-1)
                TTC = (tobstaculo + antiguo)/2;
            else TTC = tobstaculo;
            if(TTC-antiguo<0.1)
                TTC=-1;
        }
    }
    else TTC = -1;
}