21include
'/usr/local/share/brigadoon/apache/os_passwords.php';
76 $dsn =
"mysql:host=$Host;dbname=$Database;charset=utf8mb4";
80 PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
81 PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
82 PDO::ATTR_EMULATE_PREPARES =>
true,
90 catch (PDOException $e)
95 die(
"FAILURE=DATABASE:Connection failed " . $e->getMessage());
133 $sql_query =
" select lor_name as region_name, :global_x - lor_edge_left as local_x, :global_y - lor_edge_lower as local_y, :global_z as local_z from ls_os_region ";
134 $sql_query .=
" where :global_x >= lor_edge_left and :global_x <= lor_edge_right and :global_y >= lor_edge_lower and :global_y <= lor_edge_upper ";
138 $stmt =
$pdo->prepare($sql_query);
139 $stmt->execute($GlobalArray);
140 $results = $stmt->fetchAll(PDO::FETCH_DEFAULT);
161 catch (PDOException $e)
166 die(
"FAILURE=DATABASE:Connection failed " . $e->getMessage());
183 $sql_query =
"select lor_edge_left + :local_x as global_x, lor_edge_lower + :local_y as global_y, :local_z as global_z from ls_os_region where lor_name = :region_name";
187 $stmt =
$pdo->prepare($sql_query);
188 $stmt->execute($LocalArray);
189 $results = $stmt->fetchAll(PDO::FETCH_DEFAULT);
200 catch (PDOException $e)
205 die(
"FAILURE=DATABASE:Connection failed " . $e->getMessage());
233 $delta_global[
'global_x'] = $ToGlobal[
'global_x'] - $FromGlobal[
'global_x'];
234 $delta_global[
'global_y'] = $ToGlobal[
'global_y'] - $FromGlobal[
'global_y'];
235 $delta_global[
'global_z'] = $ToGlobal[
'global_z'] - $FromGlobal[
'global_z'];
236 $ground_distance = sqrt($delta_global[
'global_x'] ** 2.0 + $delta_global[
'global_y'] ** 2.0);
237 $result[
'distance'] = sqrt($ground_distance ** 2.0 + $delta_global[
'global_z'] ** 2);
238 $result[
'bearing'] = atan2($delta_global[
'global_x'], $delta_global[
'global_y']);
239 $result[
'elevation'] = atan2($delta_global[
'global_z'], $ground_distance) ;
262 $total_distance = $CourseArray[
'distance'];
263 $elevation_angle = $CourseArray[
'elevation'];
264 $bearing_angle = $CourseArray[
'bearing'];
266 $ground_distance = $total_distance * cos($elevation_angle);
267 $delta_z = $total_distance * sin($elevation_angle);
269 $delta_x = $ground_distance * sin($bearing_angle);
270 $delta_y = $ground_distance * cos($bearing_angle);
272 $GlobalArray[
'global_x'] = $FromGlobal[
'global_x'] + $delta_x;
273 $GlobalArray[
'global_y'] = $FromGlobal[
'global_y'] + $delta_y;
274 $GlobalArray[
'global_z'] = $FromGlobal[
'global_z'] + $delta_z;
294 $from_array = [
'region_name'=>
'BRIGADOON13',
'local_x' => 128,
'local_y' => 256,
'local_z' => 128];
295 $to_array = [
'region_name'=>
'BRIGADOON13',
'local_x' => 256,
'local_y' => 128,
'local_z' => 256];
301 echo
"LocalToGlobal: Global X = ".$global[
'global_x'].
", Global Y = ".
$global[
'global_y'].
", Global Z = ".
$global[
'global_x'].
"\n\n";
305 echo
"GlobalToLocal: Region Name = ".$from_array[
'region_name'].
", local_x = ".
$from_array[
'local_x'].
", local_y = ".
$from_array[
'local_y'].
", local_z = ".
$from_array[
'local_z'].
"\n\n";
309 echo
"CourseFromTo: Distance = ".$course[
'distance'].
", bearing = ".rad2deg(
$course[
'bearing']).
", elevation = ".rad2deg(
$course[
'elevation']).
"\n\n";
315 echo
"FromCourseTo: Region Name = ".$from_array[
'region_name'].
", local_x = ".
$from_array[
'local_x'].
", local_y = ".
$from_array[
'local_y'].
", local_z = ".
$from_array[
'local_z'].
"\n\n";
A Class to do global to local conversion and some global calculations.
$Host
The Host running the Database.
GlobalToLocal($GlobalArray)
$Database
The name of the Database.
CourseFromTo($FromLocalArray, $ToLocalArray)
Find the course and distance from one point to another using local coordinates.
$Username
The Username to access the Database.
__construct($Database, $Host, $Username, $Password)
Open the Support Database for Use.
$Password
The password to access the Database.
LocalToGlobal($LocalArray)
Convert a local regional location into a global location.
FromCourseTo($FromLocalArray, $CourseArray)
Routine to Calculate a Destination from an origin and a Course.