function getLineEnds($x1, $y1, $x2, $y2) { $offset = 20; $angle = getAngle($x1, $y1, $x2, $y2); $c1x = (int) ($x1 + $offset * cos($angle)); $c1y = (int) ($y1 + $offset * sin($angle)); $c2x = (int) ($x2 - $offset * cos($angle)); $c2y = (int) ($y2 - $offset * sin($angle)); return array($c1x, $c1y, $c2x, $c2y); }
function optimizePoly(array $_poly) { $curangle = getAngle($_poly[0], $_poly[1]); $ret = array($_poly[0]); for ($i = 1, $l = count($_poly) - 1; $i < $l; ++$i) { $angle = getAngle($_poly[$i], $_poly[$i + 1]); if ($angle != $curangle) { $curangle = $angle; $ret[] = $_poly[$i]; } } $ret[] = $_poly[$i]; return $ret; }
break; } } } // preskoči avione koji nisu u okviru prozora if ($lat < $latMin || $lat > $latMax || $lon < $lonMin || $lon > $lonMax) { continue; } $node = $dom->createElement("airplane"); $airplaneNode = $parnode->appendChild($node); $airplaneNode->setAttribute("id", $row['OID']); $airplaneNode->setAttribute("start_time", $start_time); $airplaneNode->setAttribute("end_time", $row['end_time']); $airplaneNode->setAttribute("lat", $lat); $airplaneNode->setAttribute("lon", $lon); $airplaneNode->setAttribute("alt", $alt); $airplaneNode->setAttribute("point_name", $point_name); $angle = getAngle($lat1ForAngle, $lon1ForAngle, $lat, $lon); $airplaneNode->setAttribute("angle", $angle); $planesCounter++; if ($planesCounter == $maxFlights) { break; } } // upis u XML echo $dom->saveXML(); function getAngle($lat1, $lon1, $lat2, $lon2) { $angle = atan2($lon2 - $lon1, $lat2 - $lat1); return rad2deg($angle); }