/// <summary>
        /// Sorts structures by distance. Both vertical and horizontal distances are accounted for.
        /// </summary>
        /// <param name="obj">The other RelativePosition object to compare with.</param>
        /// <returns>-1 if this structure is less than obj, 0 if they are equal, and 1 if obj is greater than this structure.</returns>
        public int CompareTo(object obj)
        {
            RelativePosition r = (RelativePosition)obj;
            double           instanceDistance = distance + vDistance;
            double           objDistance      = r.distance + r.vDistance;

            if (instanceDistance > objDistance)
            {
                return(1);
            }
            if (instanceDistance < objDistance)
            {
                return(-1);
            }
            return(0);
        }
Beispiel #2
0
        //Returns a RelativePosition structure that defines the
        //position of jbect 2 to object 1, from the perspective of object 1.
        public static RelativePosition getPosition(double x1, double y1, double z1, int dir1,
                                                   double x2, double y2, double z2, int dir2,
                                                   bool isObject)
        {
            RelativePosition r = new RelativePosition();

            r.distance = getDistanceBetween(x1, y1, x2, y2);
            r.degrees  = GetDegreesBetween(x1, y1, x2, y2);
            int      f1   = getDegreeValue(dir1 - 80);
            int      f2   = getDegreeValue(dir1 + 80);
            Rotation rDir = getShortestRotation(dir1, r.degrees);

            r.isAhead = inRange(f1, f2, r.degrees);

            //Since front view is at dir1, back view is dir1+180, and the
            //respective spread.
            r.isBehind = inRange(getDegreeValue(dir1 + 180 - 80),
                                 getDegreeValue(dir1 + 180 + 80),
                                 r.degrees);

            ////check for view
            //isObject is true if the target object is
            //something that is not a flying object. eg. a SAM battery,
            //in which case views will not be relevant.
            if (!isObject)
            {
                int oD = getDegreeValue(r.degrees + 180);
                ////since d is the degree at which object1 must face to be on a
                ////collision path with object2, d+180 is the exact
                ////degree mark object2 must be on to face object1 on a collision path.
                r.isNoseFacing = inRange(getDegreeValue(oD - 30),
                                         getDegreeValue(oD + 30),
                                         dir2);
                oD            -= 180;
                r.isTailFacing = inRange(getDegreeValue(oD - 30),
                                         getDegreeValue(oD + 30),
                                         dir2);
                r.isWingFacing = !r.isNoseFacing && !r.isTailFacing;
            }             //if !isObject

            r.degreesDifference = getDifference(dir1, r.degrees);

            if (rDir == Rotation.counterClockwise)
            {
                r.relativeDegrees = 360 - r.degreesDifference;
            }
            else if (rDir == Rotation.clockwise)
            {
                r.relativeDegrees = r.degreesDifference;
            }
            else if (rDir == Rotation.equal)
            {
                r.relativeDegrees = 180;
            }
            else if (rDir == Rotation.stationary)
            {
                r.relativeDegrees = 0;
            }

            r.clockMark = getClockValue(r.relativeDegrees);
            r.vDistance = z2 - z1;
            return(r);
        }