Loading [MathJax]/extensions/TeX/AMSmath.js
LALInspiral 5.0.3.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
LALInsidePolygon.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Thomas Cokelaer
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with with program; see the file COPYING. If not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17* MA 02110-1301 USA
18*/
19
20#include <lal/LALInspiralBank.h>
21
22/**
23 * \ingroup LALInspiralBank_h
24 * \brief Module to check whether a point with coordinates (x,y) is inside
25 * a polygon defined by the vectors (vx, vy), which size (n) must be
26 * provided. The functions returns 1 if the point is inside or 0 otherwise.
27 *
28 * \author Cokelaer. T
29 *
30 * ### Notes ###
31 *
32 * Tested in matlab codes and some BCV tests within lal/lalapps.
33 *
34 */
35void LALInsidePolygon( LALStatus *status, /**< LAL status pointer */
36 REAL4 *inputx, /**< [in] two arrays of floats defining the polygon */
37 REAL4 *inputy, /**< [in] two arrays of floats defining the polygon */
38 INT4 n, /**< [in] the size of the vectors */
39 REAL4 x, /**< [in] the coordinate of the point */
40 REAL4 y, /**< [in] the coordinate of the point */
41 INT4 *valid /**< [out] 0 if outside and 1 if inside */
42 )
43{
44
45
48 ASSERT (n>=3, status, LALINSPIRALBANKH_ENULL, LALINSPIRALBANKH_MSGENULL);
49
50 {
51 int i, j, c = 0;
52 for (i = 0, j = n-1; i < n; j = i++) {
53 if ((((inputy[i] <= y) && (y < inputy[j])) ||
54 ((inputy[j] <= y) && (y < inputy[i]))) &&
55 (x < (inputx[j] - inputx[i]) * (y - inputy[i]) / (inputy[j] - inputy[i]) + inputx[i]))
56 c = !c;
57 }
58 *valid = c;
59 }
60
63
64}
#define ATTATCHSTATUSPTR(statusptr)
#define ASSERT(assertion, statusptr, code, mesg)
#define DETATCHSTATUSPTR(statusptr)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
double i
int32_t INT4
float REAL4
void LALInsidePolygon(LALStatus *status, REAL4 *inputx, REAL4 *inputy, INT4 n, REAL4 x, REAL4 y, INT4 *valid)
Module to check whether a point with coordinates (x,y) is inside a polygon defined by the vectors (vx...
#define LALINSPIRALBANKH_ENULL
Null pointer.
list y
c
int n
x