public TrajectoryData() { comparer = new TpointCompare(); tpoints = new SortedList(comparer); interceptComparer = new InterceptComparer(); }
/// <summary> /// Compare this trajectory data set to another and find those points that are within /// the specified deltaDistance. DeltaDistance denotes the seperation in EACH /// co-ordinate (i.e. they are within in a BOX of size delta distance) to reduce CPU /// cost of calculating exact distance.) /// /// DeltaTime specifies the time within which multiple intercept points should be regarded /// as duplicates (in which case the intercept with the closest approach is used) /// /// List of intercepts is provided in time order (earliest first) /// </summary> /// <param name="tdata"></param> /// <param name="deltaDistance"></param> /// <param name="deltaTime"></param> /// <returns></returns> public List <Intercept> GetIntercepts(TrajectoryData tdata, float deltaDistance, float deltaTime) { List <Intercept> intercepts = new List <Intercept>(); TpointCompare compare = new TpointCompare(); // Concept: Lists are ordered so can walk each int i = 0; int j = 0; while ((i < tpoints.Count) && (j < tdata.Count())) { Tpoint tp_i = (Tpoint)tpoints.GetByIndex(i); Tpoint tp_j = (Tpoint)tdata.GetByIndex(j); // Debug.Log(string.Format("i={0} j={1} r_i={2} r_j={3}", i, j, tp_i.r, tp_j.r)); if (Mathf.Abs(tp_i.r.x - tp_j.r.x) < deltaDistance) { if (Mathf.Abs(tp_i.r.y - tp_j.r.y) < deltaDistance) { if (Mathf.Abs(tp_i.r.z - tp_j.r.z) < deltaDistance) { Intercept intercept = new Intercept(); intercept.tp1 = tp_i; intercept.tp2 = tp_j; intercept.dR = Vector3.Distance(tp_i.r, tp_j.r); intercept.dV = Vector3.Distance(tp_i.v, tp_j.v); intercept.dT = tp_i.t - tp_j.t; intercept.tp1_index = i; intercept.tp2_index = j; intercepts.Add(intercept); i++; j++; continue; } } } if (compare.Compare(tp_i, tp_j) > 0) { j++; } else { i++; } } List <Intercept> uniqueIntercepts = RemoveDuplicates(intercepts, deltaDistance, deltaTime); // sort uniqueIntercepts.Sort(interceptComparer); return(uniqueIntercepts); }