Last change
on this file since 13975 was 13975, checked in by Mathieu Morlighem, 12 years ago |
merged trunk-jpl and trunk for revision 13974
|
File size:
1.2 KB
|
Line | |
---|
1 | /*!\file IsInPoly.c
|
---|
2 | * \brief: from a contour, determine which nodes are in domain.
|
---|
3 | */
|
---|
4 |
|
---|
5 | #include <math.h>
|
---|
6 | #include "../../toolkits/toolkits.h"
|
---|
7 | #include "./exp.h"
|
---|
8 | #include "../shared.h"
|
---|
9 |
|
---|
10 | #ifdef HAVE_CONFIG_H
|
---|
11 | #include <config.h>
|
---|
12 | #else
|
---|
13 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | /*pnpoly{{{*/
|
---|
17 | int pnpoly(int npol, double *xp, double *yp, double x, double y, int edgevalue) {
|
---|
18 | int i, j, c = 0;
|
---|
19 | double n1, n2, normp, scalar;
|
---|
20 |
|
---|
21 | /*first test, are they colinear? if yes, is the point in the middle of the segment*/
|
---|
22 | if (edgevalue != 2 ){
|
---|
23 | for (i = 0, j = npol-1; i < npol; j = i++) {
|
---|
24 | n1=pow(yp[i]-yp[j],2.0)+pow(xp[i]-xp[j],2.0);
|
---|
25 | n2=pow(y-yp[j],2.0)+pow(x-xp[j],2.0);
|
---|
26 | normp=pow(n1*n2,0.5);
|
---|
27 | scalar=(yp[i]-yp[j])*(y-yp[j])+(xp[i]-xp[j])*(x-xp[j]);
|
---|
28 |
|
---|
29 | if (scalar == normp){
|
---|
30 | if (n2<=n1){
|
---|
31 | c = edgevalue;
|
---|
32 | return c;
|
---|
33 | }
|
---|
34 | }
|
---|
35 | }
|
---|
36 | }
|
---|
37 | /*second test : point is neither on a vertex, nor on a side, where is it ?*/
|
---|
38 | for (i = 0, j = npol-1; i < npol; j = i++) {
|
---|
39 | if ((((yp[i]<=y) && (y<yp[j])) ||
|
---|
40 | ((yp[j]<=y) && (y<yp[i]))) &&
|
---|
41 | (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i])){
|
---|
42 | c = !c;
|
---|
43 | }
|
---|
44 | }
|
---|
45 | return c;
|
---|
46 | }/*}}}*/
|
---|
Note:
See
TracBrowser
for help on using the repository browser.