//TimeVals is the List of Doubles. Sorted/
//AObjList is the List of Objects of a certain class
//FmZero = 0.0001 This is the precision value
for (i = 0; i < TimeVals.Count - 1; i++)
{
Ind = GetInd(TimeVals[i], AObjList, ref Ind);
Console.WriteLine(Ind);
}
private int? GetInd(double Time, List<Obj> LObj, ref int? Ind)
{
int Head = 0;
int Tail = LObj.Count - 1;
if (Time < LObj[(int)Ind].Time)
{
while ((Ind != Head) && Time < (LObj[(int)Ind].Time - GP.FmZero))
{
Ind = Ind - 1;
}
}
else
{
while ((Ind != Tail) && Time >= (LTrj[(int)Ind].Time - GP.FmZero))
{
Ind = Ind + 1;
}
}
return Ind;
}
for (i = 0; i < TimeVals.Count - 1; i++)
{
Ind = GetInd(TimeVals[i], AObjList, ref Ind);
if(Ind!=null){
//Calculations here
Console.WriteLine(Ind);
}
}
return null;
private int? GetTrj(double Time, List<Trajectory> LTrj, int? Ind)
{
int Head = 0;
int Tail = LTrj.Count - 1;
bool Found = false;
if (Time < LTrj[(int)Ind].Time)
{
while ((Ind != Head) && Time < (LTrj[(int)Ind].Time - GP.FmZero))
{
Ind = Ind - 1;
}
}
else
{
while ((Ind != Tail) && Time >= (LTrj[(int)Ind].Time - GP.FmZero))
{
Ind = Ind + 1;
}
}
return (Found == false ? null : Ind);
}
int i = 0;
int? Ind = 0;
int? SInd = 0; //Begin search at this index
double APos = 0;
int EInd = 0; //Exist Index. Increment only if the the given Time value was found.
for (i = 0; i < TimeCnt - 1; i++)
{
Ind = GetTrj(TimeVals[i], ATrj, SInd);
if (Ind != null)
{
APos = ATrj[(int)Ind].Pos;
TableGV[a, i].Value = APos;
SInd = Ind;
EInd++;
}
else
{
Ind = SInd;
TableGV[a, i].Value = null;
}
}
private int? GetTrj(double Time, List<Trajectory> LTrj, int? SInd)
{
int Head = 0;
int Tail = LTrj.Count - 1;
bool Found = false;
int Ind = 0;
if (Time < LTrj[(int)SInd].Time)
{
for (Ind = (int)SInd; Ind > Head; Ind--)
{
if ((Time <= (LTrj[Ind].Time + GP.FmZero)) && (Time >= (LTrj[Ind].Time - GP.FmZero)))
{
Found = true;
break;
}
}
}
else
{
for (Ind = (int)SInd; Ind < Tail; Ind++)
{
if ((Time <= (LTrj[Ind].Time + GP.FmZero)) && (Time >= (LTrj[Ind].Time - GP.FmZero)))
{
Found = true;
break;
}
}
}
return (Found == false ? null : (int?)Ind);
}
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.