Exemple #1
0
    public void Basic()
    {
        TrajectoryData tdata = new TrajectoryData();

        for (float x = 0; x < 10f; x++)
        {
            Vector3 r = new Vector3(x, 0, 0);
            tdata.AddPoint(r, Vector3.zero, x);
        }
        // check each entry is less than next

        for (int i = 0; i < tdata.Count() - 1; i++)
        {
            TrajectoryData.Tpoint tp1 = tdata.GetByIndex(i);
            TrajectoryData.Tpoint tp2 = tdata.GetByIndex(i + 1);
            Assert.IsTrue(tp1.r.x < tp2.r.x);
        }
    }
    /// <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>();

        tpoints.Sort(new TpointCompare());
        tdata.Sort();
        // 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[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 (comparer.Compare(tp_i, tp_j) > 0)
            {
                j++;
            }
            else
            {
                i++;
            }
        }
        List <Intercept> uniqueIntercepts = RemoveDuplicates(intercepts, deltaDistance, deltaTime);

        // sort
        uniqueIntercepts.Sort(interceptComparer);
        return(uniqueIntercepts);
    }