gpsPointInPolygon (Functionblock) |
Top Previous Next |
This function block is used for calculating if a given point is within a defined polygon with up to 7 sides. The function block uses points that are given by DINTs. When using this function together with GPS positions, the latitude/longitude positions are normally converted to DINT values by the user's program. Typically, this is done in the following way: The degrees, minutes, and decimal minutes are each multiplied by a factor, so that the resulting DINT is formatted as follows:
DDD_MM_CCCC
where DDD is degrees (to be multiplied by 1,000,000), MM is minutes (to be multiplied by 10,000) and CCCC is decimal minutes. This means that all possible latitudes and longitudes can be contained within a DINT.
Please note: The polygon corners XY positions must be presented to the function block clockwise, and in order to close the polygon, the first non-used entry in the definition of the polygon must point to the first position in order to close the polygon. Please see the example below.
Input:
Position_X : DINT X part of the point to check.
Position_Y : DINT Y part of the point to check.
Polygon_X : ARRAY[1..8] OF DINT X part of each corner of the polygon.
Polygon_Y : ARRAY[1..8] OF DINT Y part of each corner of the polygon.
Corners : SINT Number of corners that define the polygon.
Output:
Within : BOOL TRUE if Position_X/Position_Y is within the defined polygon, FALSE if outside of polygon.
Declaration: FUNCTION_block gpsPointInPolygon;
Example: INCLUDE rtcu.inc |