Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Got distance formula from here: http://hotmath.com/hotmath_help/topics/distance-formula.html
- Got mid-point calculation formula from here: http://onlinemschool.com/math/assistance/cartesian_coordinate/p_center/
- Knowing the mid points will help us triangulate if no RSSI radiuses intersect.
- Good example of Haversine's formula: http://www.movable-type.co.uk/scripts/latlong.html
- (Sorry, my high school days are failing me, I had to look up the formulas and not waste time trying to figure them out).
- Once we gather data, we'll have to change the $centimetersToRSSI value, perhaps to some type of formula like (with calculating attenuation from environment):
- $centimetersToRSSI=(1 / SQR(x));
- or
- $centimetersToRSSI=(1 / (x^2));
- where x is the input RSSI.
- See the following link for light propagation in 3 dimensional space: http://en.wikipedia.org/wiki/Inverse-square_law
- Line-line intersection: http://en.wikipedia.org/wiki/Line-line_intersection
- Lat=Y
- Long=X
- Found a good online graphics plotting program here:
- https://www.desmos.com/calculator
- */
- $centimetersToRSSI=(getQueryData("cmtorssi") >= 0 || getQueryData("cmtorssi") !="") ? getQueryData("cmtorssi") : 3; // Measure the RSSI at point blank from beacon to receiver. Move beacon away from receiver until you are at about -80dBm. Take the distance walked (Accurately in centimeters) and divide by the RSSI difference (eg: (500cms / (-22dBm - -80dBm)) = 8.62). This *must* be as accurate as possible.
- if (!$included) {
- $nodeLat=NULL;
- $nodeLong=NULL;
- $nodeRecievedRSSI=NULL;
- }
- for ($i=0; $i < count($_GET['nodelat']); $i++) {
- $nodeLat[]=((getQueryData("nodelat", $i) !="") ? floatval(getQueryData("nodelat", $i)) : 0);
- $nodeLong[]=((getQueryData("nodelong", $i) !="") ? floatval(getQueryData("nodelong", $i)) : 0);
- $nodeRecievedRSSI[]=((getQueryData("noderssi", $i) !="") ? getQueryData("noderssi", $i) : -60);
- }
- if (count($nodeLat) != count($nodeLong) || count($nodeLat) != count($nodeRecievedRSSI)) {
- echo "<br />\nWarning: Latitude (" . count($nodeLat) . "), longitude (" . count($nodeLat) . ") and received RSSI (" . count($nodeRecievedRSSI) . ") array data does not match. One or more of these parameters has more or less indexes then the other. There will be errors.<br />\n";
- } else {
- $totalScanningNodes=count($nodeLat);
- }
- if ($totalScanningNodes >= 2) {
- $testOut=calculateTricircularIntersectionCoordinates($nodeLat, $nodeLong, $nodeRecievedRSSI);
- }
- if (count($nodeLat) != count($nodeLong) || count($nodeLat) != count($nodeRecievedRSSI)) {
- echo "Warning: Latitude (" . count($nodeLat) . "), longitude (" . count($nodeLat) . ") and received RSSI (" . count($nodeRecievedRSSI) . ") array data does not match. One or more of these parameters has more indexes then the other";
- }
- if (!$testOut) {
- echo "Error";
- } else {
- echo "Output:";
- outputDebugValues($testOut);
- //outputDebugValues($testOut, true); // Uncomment this to dump the array without all the special formatting.
- }
- /*
- echo "\n<br />\n nodeLat (Y):";
- print_o($nodeLat);
- echo "<br />\n nodeLong (X):";
- print_o($nodeLong);
- echo "<br />\n nodeRecievedRSSI (R):";
- print_o($nodeRecievedRSSI);
- */
- function calculateTricircularIntersectionCoordinates($nodeLatitudes, $nodeLongitudes, $nodeRadiuses)
- // Basically pass in an array of X, Y and R and find out where they intersect with each other.
- {
- if (count($nodeLatitudes) != count($nodeLongitudes) || count($nodeLatitudes) != count($nodeRadiuses)) { return false; } // X, Y and R amounts do not match, so exit the function, returning false.
- $smallRadius=min($nodeRadiuses);
- $bigRadius=max($nodeRadiuses);
- $minKey=array_keys($nodeRadiuses, min($nodeRadiuses)); //Find the smallest radius' key in the array.
- $totalNodeLoops=count($nodeLatitudes); //One less than the total amount, so that we don't have a node try to calculate the distance to itself.
- for ($i=0;$i<$totalNodeLoops;$i++) { //Compare each node with all the other nodes and create a list of how far they are from each other (Along with the midpoints and that from calculateCartesianCoordinateDelta()).
- for ($k=$i+1;$k<$totalNodeLoops;$k++) {
- $theReturn[$i . "_to_" . $k]["cartesiandeltas"]=calculateCartesianCoordinateDelta($nodeLongitudes[$i], $nodeLatitudes[$i], $nodeLongitudes[$k], $nodeLatitudes[$k]); //Stores result from calculateCartesianCoordinateDelta() into '[$i_to_$k] ["cartesiandeltas"]' multidimensional array.
- $theReturn[$i . "_to_" . $k]["rssiintersect"]= calculateRadiiVectorCoordinates($nodeLongitudes[$i], $nodeLatitudes[$i], $nodeRadiuses[$i], $nodeLongitudes[$k], $nodeLatitudes[$k], $nodeRadiuses[$k], $i, $k);
- }
- }
- return $theReturn;
- }
- function calculateDistance($dX1, $dY1, $dX2, $dY2){
- $xDistance = abs($dX1 - $dX2);
- $yDistance = abs($dY1 - $dY2);
- $distance = sqrt($xDistance*$xDistance + $yDistance*$yDistance);
- return $distance;
- }
- function calculateCartesianCoordinateDelta($dX1, $dY1, $dX2, $dY2)
- // Calculates and returns the difference in location.
- {
- $dXDelta=$dX2 - $dX1;
- $dYDelta=$dY2 - $dY1;
- $deltaDistance = calculateDistance($dX1, $dY1, $dX2, $dY2);
- //$deltaDistance = sqrt(((abs($dXDelta) * abs($dXDelta)) + (abs($dYDelta) * abs($dYDelta)))); // -- Made into another function as this calculation is used in multiple functions
- // This returns the midpoint distance between the two scanners
- $midPointX = (abs($dXDelta) / 2) + min($dX1,$dX2); //Midpoint X
- $midPointY = (abs($dYDelta) / 2) + min($dY1,$dY2); //Midpoint Y
- $theReturn["distance"]=$deltaDistance;
- $theReturn["midx"]=$midPointX;
- $theReturn["midy"]=$midPointY;
- return $theReturn;
- }
- function calculateRadiiVectorCoordinates($node1X, $node1Y, $node1R, $node2X, $node2Y, $node2R, $node1Index=1, $node2Index=2, $clockwiseRotation=true)
- {
- // Work out the triangle
- $dispX = $node2X - $node1X;
- $dispY = $node2Y - $node1Y;
- $scannerDistance = calculateDistance($node1X,$node1Y,$node2X,$node2Y);
- // Find the angle between hypotenuse and X plane
- if($dispY == 0){
- // If dispY is 0, then it's a straight line parallel to the Y axis
- $angle = 0;
- } elseif($dispX == 0){
- // If dispX is 0, then it's a straight line tangent to the X axis
- $angle = deg2rad(90);
- } else {
- $angle = atan(abs($dispY)/abs($dispX));
- }
- // Find the distance of the midpoint from node1
- $overlap = abs($node1R + $node2R)-$scannerDistance;
- $midPointDistance = $node1R-($overlap/2);
- // Make a new triangle and work out the x and y displacement
- $midX = cos($angle)*$midPointDistance;
- $midY = sin($angle)*$midPointDistance;
- // Find the intersection points of the two circles
- // Find angleB
- $angleB = acos($midPointDistance/$node1R);
- // Find first intersection point
- $intersectPX = $node1R * (cos($angle + $angleB));
- $intersectPY = $node1R * (sin($angle + $angleB));
- // Find second intersection point
- $intersectNX = $node1R * (cos($angle - $angleB));
- $intersectNY = $node1R * (sin($angle - $angleB));
- // Calculating the cartesian angle between vector
- $v1 = sqrt(pow($node1X, 2)) + (pow($node1Y,2));
- $v2 = sqrt(pow($node2X, 2)) + (pow($node2Y,2));
- $anglePre=((($node1X * $node2X) + ($node1Y * $node2Y)) / ($v1 * $v2));
- if ($node1X==$node2X && $node1Y==$node2Y) {
- $angleRel=0; // or 360
- } else {
- if ($clockwiseRotation) {
- if (($node1X-$node2X)< 0) {
- $angleRel=atan2(($node1X-$node2X),($node1Y-$node2Y));
- $angleDegs=rad2deg($angleRel*-1);
- } else {
- $angleRel=(atan2(($node1X-$node2X),($node1Y-$node2Y))*-1) + (2 * pi());
- $angleDegs=rad2deg($angleRel);
- if ($angleDegs==360) {
- $angleDegs=0;
- }
- }
- } else {
- if ($dispX < 0) {
- $angleRel=atan2(($node1X-$node2X),($node1Y-$node2Y)) + (2 * pi());
- $angleDegs=rad2deg($angleRel);
- } else {
- $angleRel=atan2(($node1X-$node2X),($node1Y-$node2Y));
- $angleDegs=rad2deg($angleRel);
- }
- }
- }
- // Sort the triangle
- switch ($angleRel){
- case ($angleRel == 0 || $angleRel == (pi() * 2)):
- $quadrantSector = 14; // Vertical line North
- $midX = $node1X;
- $midY = $node1Y - $midPointDistance;
- $intersectPX = $node1X + $intersectPX;
- $intersectPY = $node1X + $intersectPY;
- break;
- case $angleRel == (pi()/2):
- $quadrantSector = 12; // Horizontal line East
- $midX = $node1X + $midPointDistance;
- $midY = $node1Y;
- $intersectPX = $node1X + $intersectPX;
- $intersectPY = $node1X + $intersectPY;
- break;
- case $angleRel == pi():
- $quadrantSector = 23; // Vertical line South
- $midX = $node1X;
- $midY = $node1Y + $midPointDistance;
- $intersectPX = $node1X + $intersectPX;
- $intersectPY = $node1X - $intersectPY;
- break;
- case $angleRel == pi() + (pi()/2):
- $quadrantSector = 34; // Horizontal line West
- $midX = $node1X - $midPointDistance;
- $midY = $node1Y;
- $intersectPX = $node1X - $intersectPX;
- $intersectPY = $node1X + $intersectPY;
- break;
- case $angleRel > 0 && $angleRel < (pi()/2):
- $quadrantSector = 1;
- $midX = $node1X + $midX;
- $midY = $node1Y - $midY;
- $intersectPX = $node1X + $intersectPX;
- $intersectPY = $node1Y - $intersectPY;
- $intersectNX = $node1X + $intersectNX;
- $intersectNY = $node1Y - $intersectNY;
- break;
- case $angleRel > (pi()/2) && $angleRel < pi():
- $quadrantSector = 2;
- $midX = $node1X + $midX;
- $midY = $node1Y + $midY;
- $intersectPX = $node1X + $intersectPX;
- $intersectPY = $node1Y + $intersectPY;
- $intersectNX = $node1X + $intersectNX;
- $intersectNY = $node1Y + $intersectNY;
- break;
- case $angleRel > pi() && $angleRel < (pi() + (pi()/2)):
- $quadrantSector = 3;
- $midX = $node1X - $midX;
- $midY = $node1Y + $midY;
- $intersectPX = $node1X - $intersectPX;
- $intersectPY = $node1Y + $intersectPY;
- $intersectNX = $node1X - $intersectNX;
- $intersectNY = $node1Y + $intersectNY;
- break;
- case $angleRel > (pi() + M) && $angleRel < (pi() * 2):
- $quadrantSector = 4;
- $midX = $node1X - $midX;
- $midY = $node1Y - $midY;
- $intersectPX = $node1X - $intersectPX;
- $intersectPY = $node1Y - $intersectPY;
- $intersectNX = $node1X - $intersectNX;
- $intersectNY = $node1Y - $intersectNY;
- break;
- }
- /* OLD IF STATEMENTS
- if($dispY == 0 && ($node1X > $node2X)){
- // Horizontal line West
- $q = "3&4";
- $midX = $node1X - $midPointDistance;
- $midY = $node1Y;
- $intersect1X = $node1X - $intersect1X;
- $intersect1Y = $node1X + $intersect1Y;
- } elseif($dispY == 0 && ($node1X < $node2X)){
- // Horizontal line East
- $q = "1&2";
- $midX = $node1X + $midPointDistance;
- $midY = $node1Y;
- $intersect1X = $node1X + $intersect1X;
- $intersect1Y = $node1X + $intersect1Y;
- } elseif($dispX == 0 && ($node1Y > $node2Y)){
- // Vertical line North
- $q = "1&4";
- $midX = $node1X;
- $midY = $node1Y - $midPointDistance;
- $intersect1X = $node1X + $intersect1X;
- $intersect1Y = $node1X + $intersect1Y;
- } elseif($dispX == 0 && ($node1Y < $node2Y)){
- // Vertical line South
- $q = "2&3";
- $midX = $node1X;
- $midY = $node1Y + $midPointDistance;
- $intersect1X = $node1X + $intersect1X;
- $intersect1Y = $node1X - $intersect1Y;
- } elseif($dispX>0 && $dispY<0){
- // node2 is NE of node1
- $q = 1;
- $midX = $node1X + $midX;
- $midY = $node1Y - $midY;
- $intersect1X = $node1X + $intersect1X;
- $intersect1Y = $node1Y - $intersect1Y;
- $intersect2X = $node1X + $intersect2X;
- $intersect2Y = $node1Y - $intersect2Y;
- } elseif($dispX>0 && $dispY>0){
- // node2 is SE of node1
- $q = 2;
- $midX = $node1X + $midX;
- $midY = $node1Y + $midY;
- $intersect1X = $node1X + $intersect1X;
- $intersect1Y = $node1Y + $intersect1Y;
- $intersect2X = $node1X + $intersect2X;
- $intersect2Y = $node1Y + $intersect2Y;
- } elseif($dispX<0 && $dispY>0){
- // node2 is SW of node1
- $q = 3;
- $midX = $node1X - $midX;
- $midY = $node1Y + $midY;
- $intersect1X = $node1X - $intersect1X;
- $intersect1Y = $node1Y + $intersect1Y;
- $intersect2X = $node1X - $intersect2X;
- $intersect2Y = $node1Y + $intersect2Y;
- } elseif($dispX<0 && $dispY<0){
- // node2 is NW of node1
- $q = 4;
- $midX = $node1X - $midX;
- $midY = $node1Y - $midY;
- $intersect1X = $node1X - $intersect1X;
- $intersect1Y = $node1Y - $intersect1Y;
- $intersect2X = $node1X - $intersect2X;
- $intersect2Y = $node1Y - $intersect2Y;
- }*/
- // Return array
- $theReturn["node" . $node1Index . "X"]=$node1X;
- $theReturn["node" . $node1Index . "Y"]=$node1Y;
- $theReturn["node" . $node2Index . "X"]=$node2X;
- $theReturn["node" . $node2Index . "Y"]=$node2Y;
- $theReturn["node" . $node1Index . "R"]=$node1R;
- $theReturn["node" . $node2Index . "R"]=$node2R;
- $theReturn["nodeIndex1"]=$node1Index;
- $theReturn["nodeIndex2"]=$node2Index;
- $theReturn["scannerDistance"]=$scannerDistance;
- $theReturn["scannerVectorX"]=$dispX;
- $theReturn["scannerVectorY"]=$dispY;
- $theReturn["radiiMidPointDistance"]=$midPointDistance;
- $theReturn["radiiMidpointX"]=$midX;
- $theReturn["radiimidpointY"]=$midY;
- $theReturn["radiiIntersectPX"]=$intersectPX;
- $theReturn["radiiIntersectPY"]=$intersectPY;
- $theReturn["radiiIntersectNX"]=$intersectNX;
- $theReturn["radiiIntersectNY"]=$intersectNY;
- $theReturn["angleRad"]=$angleRel;
- $theReturn["angleDeg"]=$angleDegs;
- $theReturn["relativeQuadrant"]=$quadrantSector;
- $theReturn["overlap"]=$overlap;
- $theReturn["angleBDeg"]=$angleB;
- $theReturn["angle + angleB"]=$angle + $angleB;
- $theReturn["anglePre"]=$anglePre;
- //$theReturn["nodelineintersecttest"]=calculateLineIntersectionCoordinates(15, 12.5, 10, 20, 10,15, 20, 15); //For an input of: 15, 12.5, 10, 20, 10,15, 20, 15 Answer should be around: 13, 15
- return $theReturn;
- }
- function calculateLineIntersectionCoordinates($l1x1, $l1y1, $l1x2, $l1y2, $l2x1, $l2y1, $l2x2, $l2y2)
- // Provide 2 line coordinates and this will calculate where they intersect.
- {
- $theReturn["X"]=((((($l1x1*$l1y2)-($l1y1*$l1x2)) * ($l2x1-$l2x2)) - (($l1x1-$l1x2) * (($l2x1*$l2y2) - ($l2y1*$l2x2)))) / ((($l1x1 - $l1x2) * ($l2y1 - $l2y2)) - (($l1y1-$l1y2)*($l2x1-$l2x2))));
- $theReturn["Y"]=((((($l1x1*$l1y2)-($l1y1*$l1x2)) * ($l2y1-$l2y2)) - (($l1y1-$l1y2) * (($l2x1*$l2y2) - ($l2y1*$l2x2)))) / ((($l1x1 - $l1x2) * ($l2y1 - $l2y2)) - (($l1y1-$l1y2)*($l2x1-$l2x2))));
- return $theReturn;
- }
- function outputDebugValues($debugArray, $flatDump=false)
- {
- if ($flatDump) {
- print_o($debugArray);
- return 0;
- }
- $outputText="";
- foreach ($debugArray as $nodeIndex => $nodeSet)
- {
- $outputText[$nodeIndex]["Link"]="Calculate Order: " . "Node " . $debugArray[$nodeIndex]["rssiintersect"]["nodeIndex1"] . " to Node " . $debugArray[$nodeIndex]["rssiintersect"]["nodeIndex2"];
- $outputText[$nodeIndex]["Node " . $debugArray[$nodeIndex]["rssiintersect"]["nodeIndex1"]]["Position"]="X, Y: [" . $debugArray[$nodeIndex]["rssiintersect"]["node" . $debugArray[$nodeIndex]["rssiintersect"]["nodeIndex1"] . "X"] . ", " . $debugArray[$nodeIndex]["rssiintersect"]["node" . $debugArray[$nodeIndex]["rssiintersect"]["nodeIndex1"]. "Y"] . "]";
- $outputText[$nodeIndex]["Node " . $debugArray[$nodeIndex]["rssiintersect"]["nodeIndex1"]]["Radius"]="R: [" . $debugArray[$nodeIndex]["rssiintersect"]["node" . $debugArray[$nodeIndex]["rssiintersect"]["nodeIndex1"] . "R"] . "]";
- $outputText[$nodeIndex]["Node " . $debugArray[$nodeIndex]["rssiintersect"]["nodeIndex2"]]["Position"]="X, Y: [" . $debugArray[$nodeIndex]["rssiintersect"]["node" . $debugArray[$nodeIndex]["rssiintersect"]["nodeIndex2"] . "X"] . ", " . $debugArray[$nodeIndex]["rssiintersect"]["node" . $debugArray[$nodeIndex]["rssiintersect"]["nodeIndex2"]. "Y"] . "]";
- $outputText[$nodeIndex]["Node " . $debugArray[$nodeIndex]["rssiintersect"]["nodeIndex2"]]["Radius"]="R: [" . $debugArray[$nodeIndex]["rssiintersect"]["node" . $debugArray[$nodeIndex]["rssiintersect"]["nodeIndex2"] . "R"] . "]";
- $outputText[$nodeIndex]["Relative View"]["Mid-Point Coordinate"]="X, Y: [" . $debugArray[$nodeIndex]["cartesiandeltas"]["midx"] . ", " . $debugArray[$nodeIndex]["cartesiandeltas"]["midy"] . "]";
- $outputText[$nodeIndex]["Relative View"]["Mid-Point Distance"]="Distance: [" . $debugArray[$nodeIndex]["cartesiandeltas"]["distance"] . "]";
- $outputText[$nodeIndex]["Relative View"]["Relative Cartesian Vector"]="X, Y: [" . $debugArray[$nodeIndex]["rssiintersect"]["scannerVectorX"] . ", " . $debugArray[$nodeIndex]["rssiintersect"]["scannerVectorY"] . "]";
- $outputText[$nodeIndex]["Relative View"]["Relative Angle Measure"]="Degrees: [" . $debugArray[$nodeIndex]["rssiintersect"]["angleDeg"] . "]";
- $outputText[$nodeIndex]["Relative View"]["Relative Angle Calculator"]="Radians: [" . $debugArray[$nodeIndex]["rssiintersect"]["angleRad"] . "]";
- $outputText[$nodeIndex]["Relative View"]["Relative Quadrant"]="Sector: [" . $debugArray[$nodeIndex]["rssiintersect"]["relativeQuadrant"] . "]";
- $outputText[$nodeIndex]["Relative View"]["Relative Quadrant Angle"]="Radians: [" . $debugArray[$nodeIndex]["rssiintersect"]["angle + angleB"] . "]";
- $outputText[$nodeIndex]["Radii"]["Mid-Point Coordinate"]="X, Y: [" . $debugArray[$nodeIndex]["rssiintersect"]["radiiMidpointX"] . ", " . $debugArray[$nodeIndex]["rssiintersect"]["radiimidpointY"] . "]";
- $outputText[$nodeIndex]["Radii"]["Mid-Point Distance"]="Distance: [" . $debugArray[$nodeIndex]["rssiintersect"]["radiiMidPointDistance"] . "]";
- $outputText[$nodeIndex]["Radii Intersection"]["Intersect Positive Coordinate"]="X, Y: [" . $debugArray[$nodeIndex]["rssiintersect"]["radiiIntersectPX"] . ", " . $debugArray[$nodeIndex]["rssiintersect"]["radiiIntersectPY"] . "]";
- $outputText[$nodeIndex]["Radii Intersection"]["Intersect Negative Coordinate"]="X, Y: [" . $debugArray[$nodeIndex]["rssiintersect"]["radiiIntersectNX"] . ", " . $debugArray[$nodeIndex]["rssiintersect"]["radiiIntersectNY"] . "]";
- }
- foreach ($debugArray as $nodeIndex => $nodeSet)
- {
- $outputText["Link List Calculation Order"][]=$nodeIndex;
- }
- foreach ($debugArray as $nodeIndex => $nodeSet)
- {
- $outputText["Calculation Data"]["Node " . $debugArray[$nodeIndex]["rssiintersect"]["nodeIndex1"]]="X, Y, R: [" . $debugArray[$nodeIndex]["rssiintersect"]["node" . $debugArray[$nodeIndex]["rssiintersect"]["nodeIndex1"] . "X"] . ", " . $debugArray[$nodeIndex]["rssiintersect"]["node" . $debugArray[$nodeIndex]["rssiintersect"]["nodeIndex1"]. "Y"] . ", " . $debugArray[$nodeIndex]["rssiintersect"]["node" . $debugArray[$nodeIndex]["rssiintersect"]["nodeIndex1"]. "R"] . "]";
- $outputText["Calculation Data"]["Node " . $debugArray[$nodeIndex]["rssiintersect"]["nodeIndex2"]]="X, Y, R: [" . $debugArray[$nodeIndex]["rssiintersect"]["node" . $debugArray[$nodeIndex]["rssiintersect"]["nodeIndex2"] . "X"] . ", " . $debugArray[$nodeIndex]["rssiintersect"]["node" . $debugArray[$nodeIndex]["rssiintersect"]["nodeIndex2"]. "Y"] . ", " . $debugArray[$nodeIndex]["rssiintersect"]["node" . $debugArray[$nodeIndex]["rssiintersect"]["nodeIndex2"]. "R"] . "]";
- }
- print_o($outputText);
- }
- if (!function_exists('getQueryData')) {
- function getQueryData($dataToGet, $queryIndex=-1, $noFilter=false, $requestPriority="get", $filterType=FILTER_SANITIZE_SPECIAL_CHARS)
- {
- // WARNING: Setting $filterInput to false WILL NOT sanitize any data.
- if ($noFilter=="") { $noFilter=false; }
- if ($filterType=="") { $filterType=FILTER_SANITIZE_SPECIAL_CHARS; }
- $requestPriority=strtolower($requestPriority);
- $outputString="";
- if ($queryIndex > -1) {
- if ((isset($_REQUEST[$dataToGet][$queryIndex])) && (is_array($_REQUEST[$dataToGet]))) {
- if ($noFilter!=true) {
- if ($requestPriority=="get") {
- $outputString = filter_input(INPUT_GET, $dataToGet, $filterType, FILTER_REQUIRE_ARRAY);
- $outputString=$outputString[$queryIndex];
- if ($outputString=="") {
- $outputString = filter_input(INPUT_POST, $dataToGet, $filterType, FILTER_REQUIRE_ARRAY);
- $outputString=$outputString[$queryIndex];
- }
- } else {
- $outputString = filter_input(INPUT_POST, $dataToGet, $filterType, FILTER_REQUIRE_ARRAY);
- $outputString=$outputString[$queryIndex];
- if ($outputString=="") {
- $outputString = filter_input(INPUT_GET, $dataToGet, $filterType, FILTER_REQUIRE_ARRAY);
- $outputString=$outputString[$queryIndex];
- }
- }
- } else {
- $outputString=$_REQUEST[$dataToGet][$queryIndex];
- }
- } else {
- if ($noFilter!=true) {
- if ($requestPriority=="get") {
- $outputString = filter_input(INPUT_GET, $dataToGet, $filterType);
- if ($outputString=="") {
- $outputString = filter_input(INPUT_POST, $dataToGet, $filterType);
- }
- } else {
- $outputString = filter_input(INPUT_POST, $dataToGet, $filterType);
- if ($outputString=="") {
- $outputString = filter_input(INPUT_GET, $dataToGet, $filterType);
- }
- }
- } else {
- $outputString=$_REQUEST[$dataToGet];
- }
- }
- } else {
- if ($noFilter!=true) {
- if ($requestPriority=="get") {
- $outputString = filter_input(INPUT_GET, $dataToGet, $filterType);
- if ($outputString=="") {
- $outputString = filter_input(INPUT_POST, $dataToGet, $filterType);
- }
- } else {
- $outputString = filter_input(INPUT_POST, $dataToGet, $filterType);
- if ($outputString=="") {
- $outputString = filter_input(INPUT_GET, $dataToGet, $filterType);
- }
- }
- } else {
- $outputString=$_REQUEST[$dataToGet];
- }
- }
- return $outputString;
- }
- }
- function print_o($dataToPrint)
- {
- echo "<pre>";
- print_r($dataToPrint);
- echo "</pre>";
- }
- /*
- OLD STUFF, WILL BE REMOVED SOON.
- function calculateRadiiVectorCoordinatesOld2($node1X, $node1Y, $node1R, $node $node2X, $node2Y, $node2R){
- // Work out the triangle
- $dispX = $node2X - $node1X;
- $dispY = $node2Y - $node1Y;
- $scannerDistance = calculateDistance($node1X,$node1Y,$node2X,$node2Y);
- // Find the angle between hypotenuse and X plane
- if($dispY == 0){
- // If dispY is 0, then it's a straight line parallel to the Y axis
- $angle = 0;
- } elseif($dispX == 0){
- // If dispX is 0, then it's a straight line tangent to the X axis
- $angle = deg2rad(90);
- } else {
- $angle = atan(abs($dispY)/abs($dispX));
- }
- // Find the distance of the midpoint from node1
- $overlap = abs($node1R + $node2R)-$scannerDistance;
- $midPointDistance = $node1R-($overlap/2);
- // Make a new triangle and work out the x and y displacement
- $midX = cos($angle)*$midPointDistance;
- $midY = sin($angle)*$midPointDistance;
- // Find the intersection points of the two circles
- // Find angleB
- $angleB = acos($midPointDistance/$node1R);
- // Find first intersection point
- $intersect1X = $node1R * (cos($angle + $angleB));
- $intersect1Y = $node1R * (sin($angle + $angleB));
- // Find second intersection point
- $intersect2X = $node1R * (cos($angle - $angleB));
- $intersect2Y = $node1R * (sin($angle - $angleB));
- // Sort the triangle
- if($dispY == 0 && ($node1X > $node2X)){
- // Horizontal line West
- $q = "3&4";
- $midX = $node1X - $midPointDistance;
- $midY = $node1Y;
- } elseif($dispY == 0 && ($node1X < $node2X)){
- // Horizontal line East
- $q = "1&2";
- $midX = $node1X + $midPointDistance;
- $midY = $node1Y;
- } elseif($dispX == 0 && ($node1Y > $node2Y)){
- // Vertical line North
- $q = "1&4";
- $midX = $node1X;
- $midY = $node1Y - $midPointDistance;
- } elseif($dispX == 0 && ($node1Y < $node2Y)){
- // Vertical line South
- $q = "2&3";
- $midX = $node1X;
- $midY = $node1Y + $midPointDistance;
- } elseif($dispX>0 && $dispY<0){
- // node2 is NE of node1
- $q = 1;
- $midX = $node1X + $midX;
- $midY = $node1Y - $midY;
- $intersect1X = $node1X + $intersect1X;
- $intersect1Y = $node1Y - $intersect1Y;
- $intersect2X = $node1X + $intersect2X;
- $intersect2Y = $node1Y - $intersect2Y;
- } elseif($dispX>0 && $dispY>0){
- // node2 is SE of node1
- $q = 2;
- $midX = $node1X + $midX;
- $midY = $node1Y + $midY;
- $intersect1X = $node1X + $intersect1X;
- $intersect1Y = $node1Y + $intersect1Y;
- $intersect2X = $node1X + $intersect2X;
- $intersect2Y = $node1Y + $intersect2Y;
- } elseif($dispX<0 && $dispY>0){
- // node2 is SW of node1
- $q = 3;
- $midX = $node1X - $midX;
- $midY = $node1Y + $midY;
- $intersect1X = $node1X - $intersect1X;
- $intersect1Y = $node1Y + $intersect1Y;
- $intersect2X = $node1X - $intersect2X;
- $intersect2Y = $node1Y + $intersect2Y;
- } elseif($dispX<0 && $dispY<0){
- // node2 is NW of node1
- $q = 4;
- $midX = $node1X - $midX;
- $midY = $node1Y - $midY;
- $intersect1X = $node1X - $intersect1X;
- $intersect1Y = $node1Y - $intersect1Y;
- $intersect2X = $node1X - $intersect2X;
- $intersect2Y = $node1Y - $intersect2Y;
- }
- // Return array
- $theReturn["node1"]="[".$node1X.",".$node1Y."]";
- $theReturn["node2"]="[".$node2X.",".$node2Y."]";
- $theReturn["scannerDistance"]=$scannerDistance;
- $theReturn["scannerVector"]="[".$dispX.",".$dispY."]";
- //$theReturn["dispX"]=$dispX;
- //$theReturn["dispY"]=$dispY;
- //$theReturn["angleRad"]=$angle;
- //$theReturn["angleDeg"]=rad2deg($angle);
- $theReturn["quadrant"]=$q;
- //$theReturn["node1R"]=$node1R;
- //$theReturn["node2R"]=$node2R;
- $theReturn["overlap"]=$overlap;
- $theReturn["midPointDistance"]=$midPointDistance;
- $theReturn["midpoint"]="[".$midX.",".$midY."]";
- //$theReturn["angleBDeg"]=rad2deg($angleB);
- //$theReturn["angle + angleB"]=rad2deg($angle + $angleB);
- $theReturn["intersect1"]="[".$intersect1X.",".$intersect1Y."]";
- $theReturn["intersect2"]="[".$intersect2X.",".$intersect2Y."]";
- return $theReturn;
- }
- function calculateRadiiVectorCoordinatesOLD($node1X, $node1Y, $node1R, $node2X, $node2Y, $node2R)
- {
- // THIS IS THE OLD VERSION OF THE PREV FUNCTION -- Ryoma
- //Calculates where the cooords of the vector line where it intersects each point's circle's circumference.
- // Some explanation of the paramters -- Ryoma
- //$node1X & $node1Y = scanner1 location
- //$node2X & $node2Y = scanner2 location
- //$node1R is the distance scanner1 detected
- //$node2R is the distance scanner2 detected
- // First find the vector node1.node2
- $dispX = $node1X - $node2X;
- $dispY = $node1Y - $node2Y;
- $vector = array($dispX, ($dispY*-1));
- //$angle=acos((($node1X * $node2X) + ($node1Y * $node2Y)) / ((sqrt((pow($node1X, 2)) + (pow($node1Y, 2)))) * (sqrt((pow($node2X, 2)) + (pow($node2Y, 2))))));
- //$angle=acos((($node1X * $node2X) + ($node1Y * $node2Y)) / ((sqrt((pow($node1X, 2)) + (pow($node1Y, 2)))) * (sqrt((pow($node2X, 2)) + (pow($node2Y, 2))))));
- $anglePre=((($node1X * $node2X) + ($node1Y * $node2Y)) / ((sqrt((pow($node1X, 2)) + (pow($node1Y, 2)))) * (sqrt((pow($node2X, 2)) + (pow($node2Y, 2))))));
- $angle=acos($anglePre);
- //$angle=acos(-0.5); //
- // Get the angle from node1 to node2
- /*if ($dispX==0) { //Don't divide by 0... world will end.
- if ($node2Y > $node1Y) {
- $angle = (pi()/2)*-1;
- } else {
- $angle = pi()/2;
- }
- } else {
- $angle = atan($dispY / $dispX);
- } // */
- //$angle = atan($dispY / $dispX);
- /* if ($angle > 0) {
- $angle= abs($angle);
- } else {
- $angle= (2 * pi())+$angle;
- } // *./
- //$angleRads=$angle* (180/pi());
- $clockwiseRotation=true;
- if ($node1X==$node2X && $node1Y==$node2Y) {
- $angle=0; // or 360
- } else {
- if ($clockwiseRotation) {
- if ($dispX < 0) {
- $angle=atan2($dispX,$dispY);
- $angleDegs=rad2deg($angle*-1);
- } else {
- $angle=(atan2($dispX,$dispY)*-1) + (2 * pi());
- $angleDegs=rad2deg($angle);
- if ($angleDegs==360) {
- $angleDegs=0;
- }
- }
- } else {
- if ($dispX < 0) {
- $angle=atan2($dispX,$dispY) + (2 * pi());
- $angleDegs=rad2deg($angle);
- } else {
- $angle=atan2($dispX,$dispY);
- $angleDegs=rad2deg($angle);
- }
- }
- }
- $anglePre=((($node1X * $node2X) + ($node1Y * $node2Y)) / ((sqrt((pow($node1X, 2)) + (pow($node1Y, 2)))) * (sqrt((pow($node2X, 2)) + (pow($node2Y, 2))))));
- // $node1R location
- $nodeRadius1CoordX = sin($angle)*$node1R;
- $nodeRadius1CoordY = cos($angle)*$node1R;
- // Find the distance between node1.node2
- $scannerDistance = abs(sqrt(($dispX^2)+($dispY^2)));
- // I'm going to be lazy and find the distance of Node2R from Node1 to find the location using node1 as a reference point.
- $node2Distance = abs($scannerDistance - $node2R);
- $nodeRadius2CoordX = sin($angle)*$node2Distance;
- $nodeRadius2CoordY = cos($angle)*$node2Distance;
- // To calculate the mid point, find the distance of the midpoint from node1
- $midpointDistance = abs((($scannerDistance - ($node1R + $node2R))/2)+$node1R);
- // Now find the X, Y coords
- $midpointX = sin($angle)*$midpointDistance;
- $midpointY = sin($angle)*$midpointDistance;
- // Return array
- $theReturn["noder1x"]=$nodeRadius1CoordX;
- $theReturn["noder1y"]=$nodeRadius1CoordY;
- $theReturn["noder2x"]=$nodeRadius2CoordX;
- $theReturn["noder2y"]=$nodeRadius2CoordY;
- $theReturn["vectorx"]=$dispX;
- $theReturn["vectory"]=$dispY;
- $theReturn["vectoranglerads"]=$angle;
- $theReturn["vectorangledegrees"]=$angleDegs;
- $theReturn["vectoranglepre"]=$anglePre;
- $theReturn["radiimid"]=$midpointDistance;
- $theReturn["radiix"]=$midpointX;
- $theReturn["radiiy"]=$midpointY;
- return $theReturn;
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement