diff --git a/GenAirports/Makefile.am b/GenAirports/Makefile.am index a5d9d981c..e3593d492 100644 --- a/GenAirports/Makefile.am +++ b/GenAirports/Makefile.am @@ -26,7 +26,11 @@ bin_PROGRAMS = genapts -genapts_SOURCES = area.cxx area.hxx main.cxx +genapts_SOURCES = \ + area.cxx area.hxx \ + convex_hull.cxx convex_hull.hxx \ + main.cxx \ + point2d.cxx point2d.hxx genapts_LDADD = \ $(top_builddir)/Lib/Bucket/libBucket.a \ @@ -37,6 +41,9 @@ INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib #--------------------------------------------------------------------------- # $Log$ +# Revision 1.2 1998/09/04 23:04:47 curt +# Beginning of convex hull genereration routine. +# # Revision 1.1 1998/09/01 19:34:32 curt # Initial revision. # diff --git a/GenAirports/area.cxx b/GenAirports/area.cxx index cfefd744d..aa9907618 100644 --- a/GenAirports/area.cxx +++ b/GenAirports/area.cxx @@ -29,6 +29,7 @@ #include #include "area.hxx" +#include "point2d.hxx" // calc new x, y for a rotation @@ -69,15 +70,6 @@ point2d calc_lon_lat( point2d orig, point2d offset ) { } -point2d cart_to_polar_2d(point2d in) { - point2d result; - result.dist = sqrt( in.x * in.x + in.y * in.y ); - result.theta = atan2(in.y, in.x); - - return(result); -} - - list < point2d > batch_cart_to_polar_2d( list < point2d > in_list) { @@ -150,6 +142,9 @@ gen_area(point2d origin, double angle, list < point2d > cart_list) last = rad_list.end(); while ( current != last ) { p = calc_lon_lat(origin_rad, *current); + // convert from radians to degress + p.lon *= RAD_TO_DEG; + p.lat *= RAD_TO_DEG; // printf("(%.8f, %.8f)\n", p.lon, p.lat); result_list.push_back(p); current++; @@ -203,7 +198,7 @@ gen_runway_area( double lon, double lat, double heading, printf("\n"); */ - // rotate, transform, and convert points to lon, lat + // rotate, transform, and convert points to lon, lat in degrees result_list = gen_area(origin, heading, tmp_list); /* @@ -223,6 +218,9 @@ gen_runway_area( double lon, double lat, double heading, // $Log$ +// Revision 1.2 1998/09/04 23:04:48 curt +// Beginning of convex hull genereration routine. +// // Revision 1.1 1998/09/01 19:34:33 curt // Initial revision. // diff --git a/GenAirports/area.hxx b/GenAirports/area.hxx index 8ef514694..a1bbd342e 100644 --- a/GenAirports/area.hxx +++ b/GenAirports/area.hxx @@ -29,22 +29,10 @@ #include - -typedef struct { - union { - double x; - double dist; - double lon; - }; - union { - double y; - double theta; - double lat; - }; -} point2d; +#include "point2d.hxx" -// generate an area for a runway +// generate an area for a runway (return result points in degrees) list < point2d > gen_runway_area( double lon, double lat, double heading, double length, double width); @@ -54,6 +42,9 @@ gen_runway_area( double lon, double lat, double heading, // $Log$ +// Revision 1.2 1998/09/04 23:04:49 curt +// Beginning of convex hull genereration routine. +// // Revision 1.1 1998/09/01 19:34:33 curt // Initial revision. // diff --git a/GenAirports/convex_hull.cxx b/GenAirports/convex_hull.cxx new file mode 100644 index 000000000..223bb45db --- /dev/null +++ b/GenAirports/convex_hull.cxx @@ -0,0 +1,120 @@ +// convex_hull.cxx -- calculate the convex hull of a set of points +// +// Written by Curtis Olson, started September 1998. +// +// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ +// (Log is kept at end of this file) +// + + +#include + +#include +#include + +#ifdef NEEDNAMESPACESTD +using namespace std; +#endif + +#include "convex_hull.hxx" +#include "point2d.hxx" + +// calculate the convex hull of a set of points, return as a list of +// point2d +list_container convex_hull( list_container input_list ) +{ + list_iterator current, last; + map_iterator map_current, map_last; + + // list of translated points + list_container trans_list; + + // points sorted by radian degrees + map_container radians_map; + + // will contain the convex hull + list_container con_hull; + + point2d p, average; + double sum_x, sum_y; + int in_count; + + // STEP ONE: Find an average midpoint of the input set of points + current = input_list.begin(); + last = input_list.end(); + in_count = input_list.size(); + sum_x = sum_y = 0.0; + + while ( current != last ) { + sum_x += (*current).x; + sum_y += (*current).y; + + current++; + } + + average.x = sum_x / in_count; + average.y = sum_y / in_count; + + printf("Average center point is %.4f %.4f\n", average.x, average.y); + + // STEP TWO: Translate input points so average is at origin + current = input_list.begin(); + last = input_list.end(); + trans_list.erase( trans_list.begin(), trans_list.end() ); + + while ( current != last ) { + p.x = (*current).x - average.x; + p.y = (*current).y - average.y; + printf("p is %.6f %.6f\n", p.x, p.y); + trans_list.push_back(p); + current++; + } + + // STEP THREE: convert to radians and sort by theta + current = trans_list.begin(); + last = trans_list.end(); + radians_map.erase( radians_map.begin(), radians_map.end() ); + + while ( current != last ) { + p = cart_to_polar_2d(*current); + radians_map[p.theta] = p.dist; + current++; + } + + printf("Sorted list\n"); + map_current = radians_map.begin(); + map_last = radians_map.end(); + while ( map_current != map_last ) { + p.x = (*map_current).first; + p.y = (*map_current).second; + + printf("p is %.6f %.6f\n", p.x, p.y); + + map_current++; + } + + return con_hull; +} + + +// $Log$ +// Revision 1.1 1998/09/04 23:04:51 curt +// Beginning of convex hull genereration routine. +// +// diff --git a/GenAirports/convex_hull.hxx b/GenAirports/convex_hull.hxx new file mode 100644 index 000000000..ca0b1fc60 --- /dev/null +++ b/GenAirports/convex_hull.hxx @@ -0,0 +1,61 @@ +// convex_hull.hxx -- calculate the convex hull of a set of points +// +// Written by Curtis Olson, started September 1998. +// +// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ +// (Log is kept at end of this file) +// + + +#ifndef _CONVEX_HULL_HXX +#define _CONVEX_HULL_HXX + + +#include +#include + +#ifdef NEEDNAMESPACESTD +using namespace std; +#endif + +#include "point2d.hxx" + + +// stl list typedefs +typedef list < point2d > list_container; +typedef list_container::iterator list_iterator; + +// stl mapp typedefs +typedef map < double, double, less > map_container; +typedef map_container::iterator map_iterator; + + +// calculate the convex hull of a set of points, return as a list of +// point2d +list_container convex_hull( list_container input_list ); + + +#endif // _CONVEX_HULL_HXX + + +// $Log$ +// Revision 1.1 1998/09/04 23:04:51 curt +// Beginning of convex hull genereration routine. +// +// diff --git a/GenAirports/main.cxx b/GenAirports/main.cxx index fa5464c56..9a42f9021 100644 --- a/GenAirports/main.cxx +++ b/GenAirports/main.cxx @@ -41,6 +41,7 @@ #include #include "area.hxx" +#include "convex_hull.hxx" // process and airport + runway list @@ -84,12 +85,12 @@ void process_airport( string last_airport, list < string > & runway_list ) { last = apt_list.end(); while ( current != last ) { // printf( "(%.4f, %.4f)\n", - printf( "%.5f %.5f\n", - current->lon * RAD_TO_DEG, - current->lat * RAD_TO_DEG ); + printf( "%.5f %.5f\n", current->lon, current->lat ); current++; } printf("\n"); + + convex_hull(apt_list); } diff --git a/GenAirports/point2d.cxx b/GenAirports/point2d.cxx new file mode 100644 index 000000000..755224477 --- /dev/null +++ b/GenAirports/point2d.cxx @@ -0,0 +1,45 @@ +// point2d.cxx -- 2d coordinate routines +// +// Written by Curtis Olson, started September 1998. +// +// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ +// (Log is kept at end of this file) +// + + +#include + +#include "point2d.hxx" + + +// convert a point from cartesian to polar coordinates +point2d cart_to_polar_2d(point2d in) { + point2d result; + result.dist = sqrt( in.x * in.x + in.y * in.y ); + result.theta = atan2(in.y, in.x); + + return(result); +} + + +// $Log$ +// Revision 1.1 1998/09/04 23:04:53 curt +// Beginning of convex hull genereration routine. +// +// diff --git a/GenAirports/point2d.hxx b/GenAirports/point2d.hxx new file mode 100644 index 000000000..199524047 --- /dev/null +++ b/GenAirports/point2d.hxx @@ -0,0 +1,59 @@ +// point2d.hxx -- define a 2d point class +// +// Written by Curtis Olson, started February 1998. +// +// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ +// (Log is kept at end of this file) +// + + +#ifndef _POINT2D_HXX +#define _POINT2D_HXX + + +#include + + +class point2d { +public: + union { + double x; + double dist; + double lon; + }; + union { + double y; + double theta; + double lat; + }; +}; + + +// convert a point from cartesian to polar coordinates +point2d cart_to_polar_2d(point2d in); + + +#endif // _POINT2D_HXX + + +// $Log$ +// Revision 1.1 1998/09/04 23:04:53 curt +// Beginning of convex hull genereration routine. +// +//