source: trunk/INTERP2/check_inside.pro @ 2

Last change on this file since 2 was 2, checked in by pinsard, 18 years ago

initial import from /usr/work/fvi/OPA/geomag/

File size: 2.1 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;
5; NAME: check_inside.pro
6;
7; PURPOSE: Find in which grid cell stands a given longitude/latitude position
8;
9; CATEGORY : Subroutine
10;
11; CALLING SEQUENCE : pro check_inside, xx,yy,zz, x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,result
12;
13; INPUTS :
14;         xx,yy,zz : cartesian coordinates of P the point that has to be located
15;         in grid.
16;         x1,y1,z1 : coordinates of A point of grid (See
17;         documentation)
18;         x2,y2,z2 : coordinates of B point of grid (See
19;         documentation)
20;         x3,y3,z3 : coordinates of C point of grid (See
21;         documentation)
22;         x4,y4,z4 : coordinates of D point of grid (See
23;         documentation)
24; OUTPUTS :
25;         result : location of the P point in grid
26; COMMON BLOCKS:
27;         None
28;
29; SIDE EFFECTS:
30;
31; RESTRICTIONS:
32;
33; EXAMPLE:
34;
35; MODIFICATION HISTORY: 08/2002 Robinson Hordoir
36;
37;------------------------------------------------------------
38;------------------------------------------------------------
39;------------------------------------------------------------
40
41pro check_inside, xx,yy,zz, x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,result
42
43
44
45ABx=x2-x1
46ABy=y2-y1
47
48BPx=xx-x2
49BPy=yy-y2
50BPz=zz-z2
51
52
53
54AB_Vect_BP=ABx*BPy-BPx*ABy
55BP=sqrt(BPx*BPx+BPy*BPy+BPz*BPz)
56
57
58BCx=x3-x2
59BCy=y3-y2
60
61CPx=xx-x3
62CPy=yy-y3
63CPz=zz-z3
64
65
66BC_Vect_CP=BCx*CPy-BCy*CPx
67CP=sqrt(CPx*CPx+CPy*CPy+CPz*CPz)
68
69CDx=x4-x3
70CDy=y4-y3
71
72DPx=xx-x4
73DPy=yy-y4
74DPz=zz-z4
75
76
77CD_Vect_DP=CDx*DPy-CDy*DPx
78DP=sqrt(DPx*DPx+DPy*DPy+DPz*DPz)
79
80DAx=x1-x4
81DAy=y1-y4
82
83APx=xx-x1
84APy=yy-y1
85APz=zz-z1
86
87DA_Vect_AP=DAx*APy-DAy*APx
88AP=sqrt(APx*APx+APy*APy+APz*APz)
89
90Dist=AP+BP+CP+DP
91
92
93
94result= where( ( (AB_Vect_BP LE 0.) AND (BC_Vect_CP LE 0.) AND (CD_Vect_DP LE 0.) AND (DA_Vect_AP LE 0.) ) OR      $
95               ( (AB_Vect_BP GE 0.) AND (BC_Vect_CP GE 0.) AND (CD_Vect_DP GE 0.) AND (DA_Vect_AP GE 0.) )  )                       
96
97
98
99Dist_result=Dist(result)
100
101min_dist=where(Dist_result EQ min(Dist_result))
102
103result=result(min_dist)
104
105
106end
Note: See TracBrowser for help on using the repository browser.