Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
flightzone.c
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2007 Arnold Schroeter
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *
23  */
24 
49 #include "flightzone.h"
50 
51 typedef struct { COORD_TYPE x;
53  } POINT;
54 
56  12, 18,
57  12, 25,
58  15, 29,
59  18, 25,
60  18, 18,
61  13.5, 16,
62  0 , 0}; // last corner is a dummy, which must not be deleted!!!
63 
64 POINT Orthogonal[20]; // Attention!!! array must be at least as long as Corner[]
65 
66 unsigned char bNumberOfCorners = 0;
67 
68 /*******************************************************************
69 ; function name: vInitIsInsideBoundaries
70 ; description:
71 ;*******************************************************************/
73 {
74  unsigned char i;
75 
76  bNumberOfCorners = sizeof(Corner)/sizeof(POINT) - 1; // last corner is always a dummy
77 
78  Corner[bNumberOfCorners].x = Corner[0].x;
79  Corner[bNumberOfCorners].y = Corner[0].y;
80 
81  for (i = 0; i < bNumberOfCorners; i++)
82  {
83  Orthogonal[i].x = Corner[i+1].y - Corner[i].y;
84  Orthogonal[i].y = - (Corner[i+1].x - Corner[i].x);
85 
86 #if 0
87  printf("%d: corner (%f, %f), orthogonal (%f, %f)\n",
88  i,
89  Corner[i].x, Corner[i].y,
90  Orthogonal[i].x, Orthogonal[i].y);
91 #endif
92  }
93 
94 }
95 
96 /*******************************************************************
97 ; function name: iIsInsideBoundaries
98 ; description:
99 ;
100 ; parameters:
101 ; returns: 1 if point is inside boundaries
102 ; 0 if point is outside boundaries
103 ;*******************************************************************/
105 {
106 
107  int r = 1;
108  static unsigned char i;
109 
110  i = 0;
111 
112  while ( (i < bNumberOfCorners)
113  && (r == 1)
114  )
115  {
116  if ( ( (x - Corner[i].x) * Orthogonal[i].x
117  + (y - Corner[i].y) * Orthogonal[i].y
118  ) < 0. )
119  {
120  r = 0;
121  }
122 
123  ++i;
124  }
125 
126  return r;
127 }
128 
129 
check whether a point is inside the polygon limiting the competition area
COORD_TYPE x
Definition: flightzone.c:51
POINT Orthogonal[20]
Definition: flightzone.c:64
#define COORD_TYPE
Definition: flightzone.h:42
COORD_TYPE y
Definition: flightzone.c:52
int iIsInsideBoundaries(COORD_TYPE x, COORD_TYPE y)
Definition: flightzone.c:104
unsigned char bNumberOfCorners
Definition: flightzone.c:66
void vInitIsInsideBoundaries(void)
Definition: flightzone.c:72
POINT Corner[]
Definition: flightzone.c:55