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