## 4 Mobility Aware Duty Cycling Algorithm (MADCAL)
### The Communication Threshold
* Lines 9-11--if the distance to the circular path is less than the node interference distance, then the node is deemed to be significant, in that it shall be able to communicate directly with the MSN at some point. * Lines 12-14--coding relevant to significant nodes. The coordinates of the closest point to the circular path from the node are calculated as circlePoint, and the quartile in which the circlePoint resides calculated as nodeQuartile. * Line 15--the distance between firstSinkPos and circlePoint in a straight line is calculated as distanceBetweenPoints. * Line 16--calculate the angle of the circlePoint as angleOfNode, between 0 and 360 degrees, with zero the farthest east point of the circle and default starting point for the sink, although a zero sink start point is not compulsory. Calculation based initially on the firstSinkQuartile and nodeQuartile in order to ascertain the angle between sink start point and circlePoint. * Lines 17, 18--thresholdAfter is set to true in order that the coordinates of the threshold after the circlePoint may be calculated. The coordinates of the threshold after the circlePoint are calculated as sinkThresholdAfter using the establishThreshold function. * Lines 19, 20--thresholdAfter is set to false in order that the coordinates of the threshold before the circlePoint may be calculated. The coordinates of the threshold before the circlePoint are calculated as sinkThresholdBefore using the establishThreshold function. * Line 21--calculate the distance in a straight line between the two threshold coordinates, before and after, as thresholdDistance. * Lines 22, 23--calculate the quartile in which sinkThresholdBefore is located as beforeQuartile, followed by the coordinates of the opposite point to the threshold as thresholdOpposite, for use later in determining the sink position in relation to the node. * Lines 24, 25--the end of both coding only relevant to significant nodes and the initialisation procedure. * Line 26--start of the function to establish the coordinates of the communication threshold, inputting the radius of the circular path and whether the coordinates to be calculated are before or after the circlePoint. The threshold point is based upon a combination of node location and the point at which communication with the sink should no longer be possible, based on interference distance. * Line 27--calculate the distance from the centre of the circle to the static node as nodeDist. * Lines 28-30--calculate the angle of the circle centre to the furthest point of communication, and the circle centre to the node. * Line 31--in order to avoid excessively large thresholds, determine a factor by which this angle should be reduced based upon distToCircle divided by interDist. * Lines 32-38--establish a factor check based upon the speed of the MSN. The faster the sink speed may be, the more the angle of the threshold may be reduced by. * Lines 39-41--if the factor calculated is less than the factor check then the factor check value becomes the factor. * Line 42--the value of the angle of the threshold is multiplied by the factor in order to reduce it accordingly. * Lines 43-48--if sinkThresholdAfter is being calculated then the angle calculated is added to angleOfNode, otherwise the angle is subtracted from angleOfNode. This results in threshAngleDegrees. The threshAngleDegrees is then converted to radians. * Lines 49-52--the x and y coordinates of the threshold are calculated, returning the coordinate value threshold. The establishThreshold function ends.