]> git.mxchange.org Git - flightgear.git/commitdiff
Beginning of convex hull genereration routine.
authorcurt <curt>
Fri, 4 Sep 1998 23:04:47 +0000 (23:04 +0000)
committercurt <curt>
Fri, 4 Sep 1998 23:04:47 +0000 (23:04 +0000)
GenAirports/Makefile.am
GenAirports/area.cxx
GenAirports/area.hxx
GenAirports/convex_hull.cxx [new file with mode: 0644]
GenAirports/convex_hull.hxx [new file with mode: 0644]
GenAirports/main.cxx
GenAirports/point2d.cxx [new file with mode: 0644]
GenAirports/point2d.hxx [new file with mode: 0644]

index a5d9d981c51c4a5f748cf42b200fb86ca4e206bb..e3593d4928496965a6d2ed4a406cd78d4cca0c5e 100644 (file)
 
 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.
 #
index cfefd744d1635d853a03c0d842854fbeb0379a8b..aa9907618337673c47dcdf0c0691c8b702f02b77 100644 (file)
@@ -29,6 +29,7 @@
 #include <Include/fg_constants.h>
 
 #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.
 //
index 8ef5146944928552972adf36fb5f17a42a423450..a1bbd342e436a8b937e46ccbca5e40097076062b 100644 (file)
 
 #include <list>
 
+#include "point2d.hxx"
 
-typedef struct {
-    union {
-       double x;
-       double dist;
-       double lon;
-    };
-    union {
-       double y;
-       double theta;
-       double lat;
-    };
-} point2d;
-
-
-// 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 (file)
index 0000000..223bb45
--- /dev/null
@@ -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 <stdio.h>
+
+#include <list>
+#include <map>
+
+#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 (file)
index 0000000..ca0b1fc
--- /dev/null
@@ -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 <list>
+#include <map>
+
+#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<double> > 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.
+//
+//
index fa5464c5654bbaca04b5566cfe7432104ba15135..9a42f9021d7ccefda0bb08ebf3f5f2979e285258 100644 (file)
@@ -41,6 +41,7 @@
 #include <Include/fg_zlib.h>
 
 #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 (file)
index 0000000..7552244
--- /dev/null
@@ -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 <math.h>
+
+#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 (file)
index 0000000..1995240
--- /dev/null
@@ -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 <list>
+
+
+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.
+//
+//