//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
Title | # Comments | Views | Activity |
---|---|---|---|
How can I use SQL Stored Procedure to return FedEx Zone | 17 | 41 | |
Combine two datatables into one based on a value from second datatable | 4 | 32 | |
How to add <appSettings> to the webconfig file | 2 | 20 | |
Vb. Net application freezes | 9 | 30 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
26 Experts available now in Live!