**MOTION IMAGERY CORNER POINT SEQUENCER**

*;*

**G06T3/00**

**G06T17/05**WO2009065003A1 | 2009-05-22 |

US20050073532A1 | 2005-04-07 |

AHMED MOHAMMED EMTIAZ ET AL: "Bar 1-visibility representation of optimal 1-planar graph", 2013 INTERNATIONAL CONFERENCE ON ELECTRICAL INFORMATION AND COMMUNICATION TECHNOLOGY (EICT), IEEE, 13 February 2014 (2014-02-13), pages 1 - 5, XP032580662, DOI: 10.1109/EICT.2014.6777827

None

CLAIMS What is claimed is: 1. A computer-implemented method for ordering vertices in a stream of image frames encapsulating Earth-viewing data, the computer-implemented method comprising: a. receiving, in the stream of image frames, an image frame including four vertices of a terrestrial area, acquired by an optical sensor at an image plane of a remote sensing camera; b. assigning a provisional index to each of the four vertices; c. establishing a first point of intersection of primary lines defined by pairwise ordered sets of vertices; d. loading the first point of intersection into computer memory; e. interrogating the first point of intersection as to a sign of a signed remainder with respect to each of two secondary lines defined by the pairwise ordered sets of vertices; f. in the case of opposite remainder sign with respect to the two secondary lines, swapping a first and a second of the provisional indices to obtain a rectified index for each of the four vertices; g. establishing a second point of intersection of primary lines defined by pairwise ordered sets of vertices; h. loading the second point of intersection into computer memory; i. interrogating the second point of intersection as to a sign of a signed remainder with respect to each of the two primary lines defined by the pairwise ordered sets of vertices; j. in the case of opposite remainder sign with respect to the two primary lines, swapping a second and a third of the provisional indices to obtain a rectified index for each of the four vertices, and otherwise using the provisional index of each of the four vertices as the rectified index of each of the four vertices; and k. fitting the four vertices into a tiling of the surface of the Earth based on the rectified indices of each of the four vertices. 2. The method according to Claim 1, wherein the optical sensor of the remote sensing camera includes a rectangular array of pixels. 3. The method according to Claim 1, wherein assigning a provisional index includes assigning vertex indices as received at a specified stage of processing the data stream. 4. The method according to Claim 1, wherein establishing a point of intersection of primary lines includes simultaneous solution of two linear equations, wherein each linear equation characterizes a line passing through a distinct pair of vertices. 5. A computer program product for ordering vertices in a stream of image frames encapsulating Earth-viewing data, the computer program product comprising a non-transitory computer-readable medium on which are stored computer instructions such that, when executed by a processor, the instructions cause the processor to: a. receive, in the stream of image frames, an image frame including four vertices of a terrestrial area, acquired by an optical sensor at an image plane of a remote sensing camera; b. assign a provisional index to each of the four vertices; c. establish a first point of intersection of primary lines defined by pairwise ordered sets of vertices; d. load the first point of intersection into computer memory; e. interrogate the first point of intersection as to a sign of a signed remainder with respect to each of two secondary lines defined by the pairwise ordered sets of vertices; f. in the case of opposite remainder sign with respect to the two secondary lines, swap a first and a second of the provisional indices to obtain a rectified index for each of the four vertices; g. establish a second point of intersection of primary lines defined by pairwise ordered sets of vertices; h. load the second point of intersection into computer memory; i. interrogate the second point of intersection as to a sign of a signed remainder with respect to each of the two primary lines defined by the pairwise ordered sets of vertices; j. in the case of opposite remainder sign with respect to the two primary lines, swap a second and a third of the provisional indices to obtain a rectified index for each of the four vertices, and otherwise use the provisional index of each of the four vertices as the rectified index of each of the four vertices; and j. fit the four vertices into a tiling of the surface of the Earth based on the rectified indices of each of the four vertices. 6. The computer program product according to Claim 5, wherein the optical sensor of the remote sensing camera includes a rectangular array of pixels. 7. The computer program product according to Claim 5, wherein assigning a provisional index includes assigning vertex indices as received at a specified stage of processing the data stream. 8. The computer program product according to Claim 5, wherein establishing a point of intersection of primary lines includes simultaneous solution of two linear equations, wherein each linear equation characterizes a line passing through a distinct pair of vertices. |

[0001] The present application claims priority from US Patent Application Serial

No. 15/466,993, filed March 23, 2017, which is incorporated herein by reference.

[0002] A portion of the disclosure of this patent document contains material which is subject to copyright protection. The copyright owner has no objection to the facsimile reproduction by anyone of the patent document or the patent disclosure, as it appears in the Patent and Trademark Office patent file or records, but otherwise reserves all copyright rights whatsoever.

TECHNICAL FIELD

[0003] The present invention relates to computer processing of Earth images, and, more particularly, to rectifying quadrilateral-bounded images that have become corrupted and unusable in the course of computer processing.

BACKGROUND ART

[0004] In order to render Earth imagery data interoperable among a multitude of systems and users, the Motion Imagery Standards Board (MISB) has prescribed a standard format for transmitting and storing images of the Earth derived from down-looking cameras of various sorts at all wavelengths. MISB Standards are summarized in the Motion Imagery Standards Profile, MISP- 2015.1 : Motion Imagery Handbook (MISB, 2015), which may be accessed at http://www.gwg.nga.milA and which is incorporated herein by reference, and may serve, as a normative reference, and where terms might otherwise be ambiguous, for definition of terms as used herein. MISB Standard 0601, in particular, details the Unmanned Air System (UAS) Datalink Local Set (LS) for UAS platforms. MISB Standard 0601 incorporates NITF Standards document MIL- STD-2500C of the National Imagery Transmission Format (NITF), which is also incorporated herein by reference. [0005] MISB standards apply to any type of imaging data, such as Visible Light, Infrared,

LIDAR cloud, RADAR return, Acoustical, or any type of data, from any type of modality, as do all of the teachings of the present invention.

[0006] Corner points (synonymously referred to herein as "vertices") are transmitted as metadata (tags 26-33, according to the ITF standard cited above) within packets encapsulating motion imagery obtained from an airborne platform. The ordering of identified vertices of frames of imaging data may become corrupted during various stages of transmission or processing, but must accord with MISB standards for correct projection of imaging data onto Earth coordinates. While there are various ways to detect irregularities in the orientation of frame vertices and to correct them, some of which are routinely practiced, in order for images at any facet of the processing stream to be useful, irregularities in the orientation of frame vertices must be efficiently detected and cured. Since video frames occur at a high rate, it is necessary to detect and correct such irregularities rapidly. A new and particularly efficient method for detecting and curing such irregularities is provided herein, in accordance with embodiments of the present invention as taught below.

SUMMARY OF EMBODIMENTS OF THE PRESENT INVENTION

[0007] In accordance with an embodiment of the present invention, a computer- implemented method is provided for ordering vertices in a stream of image frames encapsulating Earth-viewing data. The computer-implemented method has steps of:

a. receiving in the stream of image frames, an image frame including four vertices of a terrestrial area, acquired by a rectangular optical sensor at an image plane of a remote sensing camera;

b. assigning a provisional index to each of the four vertices;

c. establishing a first point of intersection of primary lines defined by pairwise ordered sets of vertices;

d. loading the first point of intersection into computer memory;

e. interrogating the first point of intersection as to a sign of a signed remainder with respect to each of two secondary lines defined by the pairwise ordered sets of vertices; f. in the case of opposite remainder sign with respect to the two secondary lines, swapping a first and a second of the provisional indices to obtain a rectified index for each of the four vertices;

g. establishing a second point of intersection of primary lines defined by pairwise ordered sets of vertices;

h. loading the second point of intersection into computer memory;

i. interrogating the second point of intersection as to a sign of a signed remainder with respect to each of the two primary lines defined by the pairwise ordered sets of vertices;

j. in the case of opposite remainder sign with respect to the two primary lines, swapping a second and a third of the provisional indices to obtain a rectified index for each of the four vertices, and otherwise using the provisional index of each of the four vertices as the rectified index of each of the four vertices; and

k. fitting the four vertices into a tiling of the surface of the Earth based on the rectified indices of each of the four vertices.

[0008] In accordance with other embodiments of the present invention, the optical sensor of the remote sensing camera may include a rectangular array of pixels. Assigning a provisional index may include assigning vertex indices as received at a specified stage of processing the data stream.

[0009] In further embodiments of the invention, establishing a point of intersection of primary lines may include simultaneous solution of two linear equations, with each linear equation characterizing a line passing through a distinct pair of vertices. Assigning a provisional index may include assigning vertex indices as received at a specified stage of processing the data stream.

[0010] In accordance with another aspect of the invention, a computer program product is provided for ordering vertices in a stream of image frames encapsulating Earth-viewing data. The computer program product has a non-transitory computer-readable medium on which are stored computer instructions such that, when executed by a processor, the instructions cause the processor to:

a. receive, in the stream of image frames, an image frame including four vertices of a terrestrial area, acquired by an optical sensor at an image plane of a remote sensing camera;

b. assign a provisional index to each of the four vertices; c. establish a first point of intersection of primary lines defined by pairwise ordered sets of vertices;

d. load the first point of intersection into computer memory;

e. interrogate the first point of intersection as to a sign of a signed remainder with respect to each of two secondary lines defined by the pairwise ordered sets of vertices;

f. in the case of opposite remainder sign with respect to the two secondary lines, swap a first and a second of the provisional indices to obtain a rectified index for each of the four vertices; g. establish a second point of intersection of primary lines defined by pairwise ordered sets of vertices;

h. load the second point of intersection into computer memory;

i. interrogate the second point of intersection as to a sign of a signed remainder with respect to each of the two primary lines defined by the pairwise ordered sets of vertices;

j. in the case of opposite remainder sign with respect to the two primary lines, swap a second and a third of the provisional indices to obtain a rectified index for each of the four vertices, and otherwise use the provisional index of each of the four vertices as the rectified index of each of the four vertices; and

k. fit the four vertices into a tiling of the surface of the Earth based on the rectified indices of each of the four vertices.

[0011] In accordance with other embodiments of the present invention, the optical sensor of the remote sensing camera may include a rectangular array of pixels. Assigning a provisional index may include assigning vertex indices as received at a specified stage of processing the data stream.

[0012] In further embodiments of the invention, establishing a point of intersection of primary lines may include simultaneous solution of two linear equations, with each linear equation characterizing a line passing through a distinct pair of vertices. Assigning a provisional index may include assigning vertex indices as received at a specified stage of processing the data stream.

BRIEF DESCRIPTION OF THE DRAWINGS

[0013] The invention will be more fully understood by referring to the following Detailed

Description of Specific Embodiments in conjunction with the Drawings, of which: [0014] Fig. 1 depicts numbered corner coordinates in a rectangle imaged onto a rectangular sensor aboard an Earth- viewing platform. Fig. 1 appears as Fig. 7-3 of MISB Standard 0601.

[0015] Fig. 2 shows the ordering of corner points of a quadrilateral outlining a captured image in accordance with the standards of MISB 0601.

[0016] Figs. 3A and 3B show two variant misorderings of corner points.

[0017] Figs. 4A and 4B depict intersecting-line quadrilateral corner ordering in accordance with an embodiment of the present invention.

[0018] Fig. 5 is a flowchart depicting steps in the detection and correction of misordered corner points in accordance with an embodiment of the present invention.

[0019] Figs. 6A-6C show representative initial vertex orderings as instances of the application of an embodiment of the present invention.

DETAILED DESCRIPTION OF SPECIFIC EMBODIMENTS

[0020] Definitions. The term "image" shall refer to any multidimensional representation, whether in tangible or otherwise perceptible form, or otherwise, wherein a value (scalar or otherwise) of some characteristic (amplitude, intensity, etc.) is associated with each of a plurality of locations (or, vectors in a Euclidean space, typically "R ^{2 } or "R ^{3 }) corresponding to dimensional coordinates of an object in physical space, though not necessarily mapped one-to-one thereonto. Thus, for example, the graphical display of the spatial distribution of some field, either scalar or vectorial, such as brightness or color, constitutes an image. So, also, does an array of numbers, such as a 2D or 3D holographic dataset, in a computer memory or holographic medium. Similarly, "imaging" refers to the rendering of a stated physical characteristic in terms of one or more images.

[0021] The verb "rectify," as used herein and in any appended claims, shall denote bringing data into conformity with specified standards. The word "correct" may be used synonymously with the word "rectify."

[0022] The term "index" refers to an ordered numbering of elements of a set, and, more particularly, in the present context, to an ordered numbering of corner points of a polygon.

[0023] The term "vertex" shall be used synonymously with "corner point" to represent one of the set of points where segments defining the extremal edges of a polygonal image intersect pairwise. [0024] A "corner point sequencer" receives a description of the locations of corner points and tests their order to establish whether they correctly correspond to corners of a polygon bounding an image, and, if not, orders the corner points correctly.

[0025] Referring to Fig. 1, Earth imagery data are routinely acquired by a down-looking sensor (or "sensor") 101 aboard an Earth-viewing platform 115, such as an unmanned aerial vehicle (UAV), for example. Sensor 101 is disposed in an image plane of a remote sensing camera 103, and typically provides imagery data in the format of a rectangular array of pixels, which are processed and transmitted for analysis or dissemination. Due to the viewing angle of the sensor relative to Earth, the area projected onto rectangular sensor 101 is bounded by a quadrilateral 105, with angles that are no longer right angles but that are transformed by virtue of the slanted viewing angle. In order to process quadrilateral 105 for viewing or analysis in Earth-based coordinates, MISB Standard 0601 requires ordering of corner points (otherwise referred to herein as "vertices") 1, 2, 3 and 4 of each quadrilateral 105, as the data appear in any stage of transmission or processing, in a clockwise order. Thus, the vertices must be associated with indices that increment in the specified order and sense. Conformance to the standard is required in order to properly render images in the Earth frame, allowing projection onto a map of video from an Earth- viewing vehicle 115 using telemetry data derived from sensor 101 aboard the Earth- viewing vehicle.

[0026] Quadrilateral 105, shown in Fig. 2, represents the projection of an image derived by sensor 101 onto the Earth frame. Each side 110 of quadrilateral 105 corresponds to an edge of sensor 101. According to the MISB 0601 standard, corner points 1, 2, 3 and 4 are ordered clockwise from the upper left corner. However, the telemetry, or subsequent processing, is sometimes not ordered correctly, resulting in misordered corner points, as depicted in Figs. 3A and 3B. The swapping of two points represents the most common case of incorrectly ordered corner points.

[0027] Vertex indices, as they are received at a specified stage of processing, or at any stage of processing, may be assigned as provisional indices corresponding to respective corner points, and then corrected, in accordance with teachings of the present invention.

[0028] Geometrical Terms Referring to a Quadrilateral: As used herein, and in any appended claims, an "internal angle" (or "interior angle") is the angle formed by two adjacent sides of a quadrilateral if, and only if, a point within the angle is in the interior of the quadrilateral. A quadrilateral is "convex" if, and only if, no internal angle exceeds 180°. A quadrilateral shall be referred to herein as "normal" if it is convex and if no more than two of its interior angles are right angles.

[0029] In accordance with embodiments of the present invention, a method is provided for detecting and correcting incorrectly ordered corner points, as now described. Referring to Fig. 4A, a top line 301 passes through points 1 and 2. Once a Cartesian reference frame has been specified, "top" refers to the line segment that passes though the point with the highest ordinate value and the next sequentially provisionally indexed point, in this case, points 1 and 2. Similarly, a bottom line 302 passes through points 3 and 4 (in the instance depicted in Fig. 4A). If top line 301 and bottom line 302 (jointly, "primary lines") intersect, their intersection is referred to as point A.

[0030] The term "primary lines," as used herein and in any appended claims, shall denote the lines passing through the pairs of corner points 1 and 2, and 3 and 4, respectively, as the points are provisionally indexed, as described above.

[0031] Lines passing through the pairs of corner points 1 and 2, 2 and 3, 3 and 4, and 4 and

1 are referred to herein as "bounding lines." If left and right lines 303 and 304 (jointly, "secondary lines") of quadrilateral 105 intersect, their intersection is denoted point B.

[0032] Swapping of two corner points 3 and 4, as depicted in Fig. 4B, as may occur through corruption of the data, generates a figure referred to herein as a "bowtie." The index of any corner point prior to rectification shall be referred to herein, and in any appended claims, as the "provisional index", while the index of any corner point subsequent to rectification shall be referred to herein, and in any appended claims, as the "rectified index" of that corner point.

[0033] If lines connecting corner points 1, 2, 3 and 4 divide the plane into a bounded region and an unbounded region, the unbounded region may be referred to herein as the "outside" of quadrilateral 105. It can be shown that in a "normal" quadrilateral (as defined above), both intersection points A and B lie outside quadrilateral 105, as shown in Fig. 4A. On the other hand, if one of the intersection points A and B does not lie outside quadrilateral 105, it shall be said to lie inside quadrilateral 105, as shown in Fig. 4B. Existence of a single intersection point B inside quadrilateral 105 is an indication that two of corner points 1, 2, 3 and 4 have been swapped, and that the corresponding indices must be exchanged in order to prevent the bowtie configuration of Fig. 4B. [0034] In methods of the invention, each of the bounding lines 301, 302, 303 and 304 is cast in slope-intercept form (either homogeneous, or inhomogeneous):

y = m * x + b ; or equivalently

Remainder = m * x + b— y = 0 .

[0035] Simultaneous solution of the Top line 301 and Bottom line 302 lines yields their common intersection point A, which is loaded into computer memory. The primary lines (as defined above) are tested first, in accordance with a preferred embodiment of the present invention. The coordinates (x, y) of the intersection point A are substituted into the equations of the remaining two lines (referred to as the "secondary" lines), Left line 303 and Right line 304. Mutatis mutandis, the intersection point B is loaded into computer memory, and subsequently substituted into the equations of top and bottom lines 301 and 302.

[0036] The term "Signed Remainder" is defined as the Remainder times the sign of the slope of a line, thus:

Signed Remainder = (m * x + b— y = 0) x sgn(m), where sgn(m) is the sign of m.

[0037] If intersection point A lies on line 303, then the Signed Remainder is zero, and intersection point A is on line 303. If intersection point A lies above the line 303, and the slope m is positive, the Signed Remainder is negative. Whether the Signed Remainder is positive or negative shall be referred to herein, and in any appended claims, as the "sign" of the Signed Remainder, or the "remainder sign." Determining whether the sign of the signed remainder is positive or negative may be referred to herein as interrogating the point of intersection as to the sign of the remainder.

[0038] If intersection point A is below line 303, and the slope m is positive, the Signed

Remainder is positive. If intersection point A is to the right of the line 303, and the slope is positive, the Signed Remainder is positive. If intersection point A is to the left of line 303, and the slope is positive, the Signed Remainder is negative. Thus, if the remainders of the two bounding lines 303 and 304 have opposite signs, the intersection point A lies inside the quadrilateral.

[0039] Otherwise, the intersection point A lies outside the quadrilateral. Opposite signs of the signed remainders for the two bounding lines 303 and 304 implies that two corner points 3 and 4 need to be swapped. If the top and bottom lines 301 and 302 intersect inside the quadrilateral 105, then either the corner points 1 and 3 (in Fig. 4B) on the left need to be swapped, or the points 2 and 4 on the right need to be swapped. If the left and right lines 303 and 304 intersect inside the quadrilateral 105, then the corner points on the top (1 and 2 in Fig. 4B) need to be swapped or the points on the bottom (3 and 4 in Fig. 4B) need to be swapped.

[0040] In cases where a bounding line is vertical (and its slope m is undefined), a distinct test is performed to determine whether the intersection of the corresponding primary (or secondary) line lies inside or outside quadrilateral 105.

[0041] The method that has been described is summarized in the flowchart shown in Fig. 5.

In a first step 501, equations of the four bounding lines 301, 302, 303 and 304 (shown in Fig. 4A) are calculated. Then the intersection point A of the Top and Bottom lines is found (503), if it exists, with the existence represented by the Boolean value of the bTopBottom variable. Similarly, the intersection point B of the Right and Left lines is found (505), if it exists, with the existence represented by the Boolean value of the bLeftRight variable.

[0042] If the primary lines are parallel (506), then the test of intersection of the primary lines is bypassed. If bTopBottom is true and if the intersection point A is inside the Left and Right lines, then the corner points lying on the Top or Bottom lines respectively (otherwise referred to herein as the "Top" points and the "Bottom" points) are swapped (507). Mutatis mutandis, if the intersection point B is inside the Top and Bottom lines, then the corner points lying on the Left or Right lines respectively (otherwise referred to herein as the "Left" points and the "Right" points) are swapped (509). Once the corner point indices have been rectified, the corresponding bounded images are fit (511) into an Earth surface tiling, using standard processing methods.

[0043] The remaining question is the determination of which points to swap. The selection is a matter of design choice. Typically, any swapping error is consistent over a range of values of viewing parameters.

[0044] Using an arbitrary point swap selection, along with the slope intersection method described above, may advantageously minimize calculations and the time required to swap the points and it has an inherent built-in check to see whether the bowtie of Fig. 4B exists. To particular advantage, methods in accordance with the present invention are implemented without calling trigonometric functions. This feature provides an unexpected advantage over any other known methods of detecting and rectifying quadrilaterally bounded images within a data stream of motion imagery. [0045] Application of embodiments of the present invention in particular illustrative cases of initial vertex orderings is now described with reference to Figs. 6A-6C. In Fig. 6A, top line EF and bottom line GH intersect in a point A outside quadrilateral EFGH, the Remainder of which with respect to line EH is positive (it lies above line EH, but the slope of line EH is negative, so the Signed Remainder of the intersection A of lines line EF and line GH with respect to line EH is negative. Similarly, the Remainder of the intersection of lines EF and line GH with respect to line FG is negative (it lies below line FG ). The slope of line FG is positive, thus the Signed Remainder of the intersection of lines line EF and line GH with respect to line FG is also negative. Since the Signed Remainders of the intersection A of lines of lines EF and line GH with respect to both of the secondary lines EH and line FG are negative, the intersection A lies outside quadrilateral EFGH and no swapping of indices is called for the primary lines. Similar considerations confirm that no swapping of indices is called for in the case of the secondary lines.

[0046] Analogous analyses, based on the method described herein, leads to the conclusion that quadrilateral KLMN shown in Fig. 6B and quadrilateral PQRS shown in Fig. 6C are bowties, and that vertices must be swapped, as called for by embodiments of the present invention.

[0047] The above described methods may be performed, and the above described systems may be implemented, by a computer system, including a processor, by executing appropriate instructions stored in a memory. A computer program product for rectifying images has been described with reference to a processor controlled by instructions stored in a memory. The memory may be random access memory (RAM), read-only memory (ROM), flash memory or any other memory, or combination thereof, suitable for storing control software or other instructions and data. Some of the functions performed by the transformation methods and apparatus have been described with reference to flowcharts and/or block diagrams. Those skilled in the art should readily appreciate that functions, operations, decisions, etc. of all or a portion of each block, or a combination of blocks, of the flowcharts or block diagrams may be implemented as computer program instructions, software, hardware, firmware or combinations thereof. Those skilled in the art should also readily appreciate that instructions or programs defining the functions of the present invention may be delivered to a processor in many forms, including, but not limited to, information permanently stored on tangible non-transitory non-writable storage media (e.g. read-only memory devices within a computer, such as ROM, or devices readable by a computer I/O attachment, such as CD-ROM or DVD disks), information alterably stored on tangible non-transitory writable storage media (e.g. floppy disks, removable flash memory and hard drives) or information conveyed to a computer through communication media, including wired or wireless computer networks. In addition, while the invention may be embodied in software, the functions necessary to implement the invention may optionally or alternatively be embodied in part or in whole using firmware and/or hardware components, such as combinatorial logic, Application Specific Integrated Circuits (ASICs), Field-Programmable Gate Arrays (FPGAs) or other hardware or some combination of hardware, software and/or firmware components.

[0048] While the invention is described through the above-described exemplary embodiments, it will be understood by those of ordinary skill in the art that modifications to, and variations of, the illustrated embodiments may be made without departing from the inventive concepts disclosed herein. For example, although some aspects of the shadow estimation method have been described with reference to a flowchart, those skilled in the art should readily appreciate that functions, operations, decisions, etc. of all or a portion of each block, or a combination of blocks, of the flowchart may be combined, separated into separate operations or performed in other orders. Moreover, while the embodiments are described in connection with various illustrative data structures, one skilled in the art will recognize that the system may be embodied using a variety of data structures. Furthermore, disclosed aspects, or portions of these aspects, may be combined in ways not listed above. Accordingly, the invention should not be viewed as being limited to the disclosed embodiments.

[0049] An example of computer code that may be used to practice the computer- implemented method described herein is now provided.

©2017 Intergraph Corporation

void CKLVParser0601 ::FixBowTie(double *pdGroundCornerlLat, double

*pdGroundCornerlLong,

double *pdGroundCorner2Lat, double *pdGroundCorner2Long,

double *pdGroundCorner3Lat, double *pdGroundCorner3Long,

double *pdGroundCorner4Lat, double *pdGroundCorner4Long,

bool bSwapRight, bool bSwapBottom)

{

if (sNAN == *pdGroundCornerlLat || sNAN == *pdGroundCornerlLong ||

sNAN == *pdGroundCorner2Lat || sNAN == *pdGroundCorner2Long || sNAN == *pdGroundCorner3Lat || sNAN == *pdGroundCorner3Long || sNAN == *pdGroundCorner4Lat || sNAN == *pdGroundCorner4Long)

{

return;

}

// treat the lat long as points in a cartesian x,y graph

// Determine the equation of the four line

bool bAB Intersect = false;

bool b Swapped = false;

// Line A from point 1 to point 2

double dASlope = 0;

double dASlopeSign = 1.0;

double dAIntercept = 0;

double dARun = *pdGroundCorner2Long - *pdGroundCornerlLong;

double dARise = *pdGroundCorner2Lat - *pdGroundCornerlLat;

if (dARun != 0)

{

dASlope = dARise / dARun;

if (dASlope < 0)

{

dASlopeSign = -1.0;

}

dAIntercept = *pdGroundCornerlLat - dASlope * *pdGroundCornerlLong;

}

else

{

// A vertical line

// Slope is infinite

// Intercept is all vertical point at point x(lLong)

}

// Line B from point 4 to point 3

double dYABIntersect = 0;

double dXABIntersect = 0;

double dBSlope = 0;

double dBSlopeSign = 1.0;

double dBIntercept = 0;

double dBRun = *pdGroundCorner4Long - *pdGroundCorner3Long;

double dBRise = *pdGroundCorner4Lat - *pdGroundCorner3Lat;

if (dBRun != 0)

{

dBSlope = dBRise / dBRun;

if (dBSlope < 0)

{

dBSlopeSign = -1.0; }

dBIntercept = *pdGroundCorner3Lat - dBSlope * *pdGroundCorner3Long;

}

else

{

// A vertical line

// Slope is infinite

// Intercept is all vertical point at point x(lLong)

}

// See if the opposite lines intersect

if (dBRun != 0 && dARun != 0)

{

// General case

if (dBSlope != dASlope)

{

// They must intersect

dXABIntersect = (dBIntercept - dAIntercept) / (dASlope - dBSlope);

dYABIntersect = dASlope * ((dBIntercept - dAIntercept) / (dASlope - dBSlope)) + dAIntercept;

bAB Intersect = true;

}

// Othewise they are coincident or parallel and do not intersect

}

else if (0 == dBRun && 0 == dARun)

{

// Both are vertical and are either coincident or do not itersect

// Do nothing

}

else if (0 == dBRun && 0 != dARun)

{

// B id vertical and A sloped

// B is the Long value or X

dXABIntersect = *pdGroundCorner3Long;

dYABIntersect = dASlope * dXABIntersect + dAIntercept;

bAB Intersect = true;

}

else

{

// A is vertical and B sloped

// A is the Long value or X

dXABIntersect = *pdGroundCornerlLong;

dYABIntersect = dBSlope * dXABIntersect + dBIntercept;

bAB Intersect = true;

} // Second set of lines

bool bCDIntersect = false;

// Line C from point 2 to point 3

double dCSlope = 0;

double dCSlopeSign = 1.0;

double dCIntercept = 0;

double dCRun = *pdGroundCorner3Long - *pdGroundCorner2Long;

double dCRise = *pdGroundCorner3Lat - *pdGroundCorner2Lat;

if (dCRun != 0)

{

dCSlope = dCRise / dCRun;

if (dCSlope < 0)

{

dCSlopeSign = -1.0;

}

dCIntercept = *pdGroundCorner2Lat - dCSlope * *pdGroundCorner2Long;

}

// Else it is a vertical line

// Slope is infinite

// Intercept is all vertical point at point x(lLong)

// Line D from point 4 to point 1

double dYCDIntersect = 0;

double dXCDIntersect = 0;

double dDSlope = 0;

double dDSlopeSign = 1.0;

double dDIntercept = 0;

double dDRun = *pdGroundCorner4Long - *pdGroundCornerlLong;

double dDRise = *pdGroundCorner4Lat - *pdGroundCornerlLat;

if (dDRun != 0)

{

dDSlope = dDRise / dDRun;

if (dDSlope < 0)

{

dDSlopeSign = -1.0;

}

dDIntercept = *pdGroundCorner4Lat - dDSlope * *pdGroundCorner4Long;

}

// Else it is a vertical line

// Slope is infinite

// Intercept is all vertical point at point x(lLong)

// See if the opposite lines intersect

if (dDRun != 0 && dCRun != 0)

{ // General case

if (dDSlope != dCSlope)

{

// They must intersect

dXCDIntersect = (dDIntercept - dCIntercept) / (dCSlope - dDSlope);

dYCDIntersect = dCSlope * ((dDIntercept - dCIntercept) / (dCSlope - dDSlope)) + dCIntercept;

bCDIntersect = true;

}

// Othewise they are coincident or parallel and do not intersect

}

else if (0 == dDRun && 0 = dCRun)

{

// Both are vertical and are either coincident or do not itersect

// Do nothing

}

else if (0 == dDRun && 0 ! = dCRun)

{

// D is vertical and C sloped

// D is the Long value or X

dXCDIntersect = *pdGroundCorner4Long;

dYCDIntersect = dCSlope * dXCDIntersect + dCIntercept;

bCDIntersect = true;

}

else

{

// C is vertical and D sloped

// C is the Long value or X

dXCDIntersect = *pdGroundCorner2Long;

dYCDIntersect = dDSlope * dXCDIntersect + dDIntercept;

bCDIntersect = true;

}

// Determine if the intersect point is inside the bounding rectangle. If so it is a bowtie if (bABIntersect)

{

// see if it is between lines C and D

double dYC = (dCSlope * dXABIntersect + dCIntercept - dYABIntersect) * dCSlopeSign;

double dYD = (dDSlope * dXABIntersect + dDIntercept - dYABIntersect) * dDSlopeSign;

// If they have opposite signs, it is a bowtie

if ((dYC >= 0 && dYD <= 0) II (dYC <= 0 && dYD >= 0))

{

// Swap points 2 and 3 or you could do 1 and 4 if (bSwapRight)

{

double dLatTemp = *pdGroundCorner2Lat;

double dLongTemp = *pdGroundCorner2Long;

*pdGroundCorner2Lat = *pdGroundCorner3Lat;

*pdGroundCorner2Long = *pdGroundCorner3Long;

*pdGroundCorner3Lat = dLatTemp;

*pdGroundCorner3Long = dLongTemp; else

{

double dLatTemp = *pdGroundCorner4Lat;

double dLongTemp = *pdGroundCorner4Long;

*pdGroundCorner4Lat = *pdGroundCornerlLat;

*pdGroundCorner4Long = *pdGroundCornerlLong;

*pdGroundCornerlLat = dLatTemp;

*pdGroundCornerlLong = dLongTemp; dBSlope = 0;

dBSlopeSign = 1.0;

dBIntercept = 0;

dBRun = *pdGroundCorner4Long - *pdGroundCorner3Long;

dBRise = *pdGroundCorner4Lat - *pdGroundCorner3Lat;

if (dBRun != 0)

{

dBSlope = dBRise / dBRun;

if (dBSlope < 0)

{

dBSlopeSign = -1.0;

}

dBIntercept = *pdGroundCorner3Lat - dBSlope

* pdGroundCorner3 Long; else

{

// A vertical line

// Slope is infinite

// Intercept is all vertical point at point x(lLong)

if (bCDIntersect && !bSwapped)

{

// see if it is between lines A and B double dYA = (dASlope * dXCDIntersect + dAIntercept - dYCDIntersect) * dASlopeSign;

double dYB = (dB Slope * dXCDIntersect + dBIntercept - dYCDIntersect) * dBSlopeSign;

// If they have opposite signs, it is a bowtie

if ((dYA >= 0 && dYB <= 0) || (dYA <= 0 && dYB >= 0))

{

// Swap points 3 and 4 or you could do 1 and 2

if (bSwapBottom)

{

b Swapped = true;

double dLatTemp = *pdGroundCorner3Lat;

double dLongTemp = *pdGroundCorner3Long;

*pdGroundCorner3Lat = *pdGroundCorner4Lat;

*pdGroundCorner3Long = *pdGroundCorner4Long;

*pdGroundCorner4Lat = dLatTemp;

*pdGroundCorner4Long = dLongTemp;

}

else

{

double dLatTemp = *pdGroundCornerlLat;

double dLongTemp = *pdGroundCornerlLong;

*pdGroundCornerlLat = *pdGroundCorner2Lat;

*pdGroundCornerlLong = *pdGroundCorner2Long;

*pdGroundCorner2Lat = dLatTemp;

*pdGroundCorner2Long = dLongTemp;

}

}

}

}