/// <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);
    }
Example #2
0
    public void AddPoint(Vector3 r, Vector3 v, float t)
    {
        Tpoint tpoint = new Tpoint();

        tpoint.r = r;
        tpoint.v = v;
        tpoint.t = t;
        // Slow launching rocket can end up at same point for two frames - avoid adding a duplicate
        // Performance: Is there a way to not add an if inside a highly used method?
        try {
            tpoints.Add(tpoint, tpoint);
        } catch (System.ArgumentException) {
            // just skip this point if it already exists
        }
    }
Example #3
0
    bool checkPoint(Vector3 point, Tpoint parentPoint)
    {
        //check if the point being checked is the endpoint
        if(point == endPoint)
        {
            //break out of function, return that the endpoint is found via bool
            return true;
        }
        //check if the point being checked is already occupied
        if(gridScript.getGridTile((int)point.x,(int)point.y) != 0)
        {
            //break out of function
            return false;
        }

        for(int i = 0; i < usedPoints.Count; i++)
        {
            if(point == usedPoints[i])
            {
                //break out of function
                return false;
            }
        }
        for(int j = 0; j < pendingPoints.Count; j++)
        {
            if(point == pendingPoints[j].position)
            {
                //break out of function
                return false;
            }
        }

        Tpoint newTpoint = new Tpoint();
        newTpoint.position = point;

        newTpoint.parent = parentPoint;

        newTpoint.G = parentPoint.G + 1;
        newTpoint.H = Mathf.Abs((int)(newTpoint.position.x - endPoint.x)) + Mathf.Abs((int)(newTpoint.position.y - endPoint.y));
        newTpoint.F = newTpoint.G + newTpoint.H;

        pendingPoints.Add (newTpoint);

        return false;
    }
Example #4
0
        public int Compare(System.Object o1, System.Object o2)
        {
            Tpoint t1 = (Tpoint)o1;
            Tpoint t2 = (Tpoint)o2;

            // order by x, y then z
            if (t1.r.x < t2.r.x)
            {
                return(-1);
            }
            else if (t1.r.x > t2.r.x)
            {
                return(1);
            }
            else
            {
                if (t1.r.y < t2.r.y)
                {
                    return(-1);
                }
                else if (t1.r.y > t2.r.y)
                {
                    return(1);
                }
                else
                {
                    if (t1.r.z < t2.r.z)
                    {
                        return(-1);
                    }
                    else if (t1.r.z > t2.r.z)
                    {
                        return(1);
                    }
                    else
                    {
                        return(0);
                    }
                }
            }
        }
Example #5
0
    bool checkSurrounding(Tpoint point)
    {
        Vector3 pointToCheck;

        pointToCheck = point.position;
        pointToCheck.y += 1;
        if(checkPoint(pointToCheck, point))
        {
            return true;
        }

        pointToCheck = point.position;
        pointToCheck.y -= 1;
        if(checkPoint(pointToCheck, point))
        {
            return true;
        }

        pointToCheck = point.position;
        pointToCheck.x -= 1;
        if(checkPoint(pointToCheck, point))
        {
            return true;
        }

        pointToCheck = point.position;
        pointToCheck.x += 1;
        if(checkPoint(pointToCheck, point))
        {
            return true;
        }

        return false;
    }