File: proj_sconics.c

package info (click to toggle)
vtk 5.8.0-13
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 130,524 kB
  • sloc: cpp: 1,129,256; ansic: 708,203; tcl: 48,526; python: 20,875; xml: 6,779; yacc: 4,208; perl: 3,121; java: 2,788; lex: 931; sh: 660; asm: 471; makefile: 299
file content (187 lines) | stat: -rw-r--r-- 5,016 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
** libproj -- library of cartographic projections
**
** Copyright (c) 2003, 2006   Gerald I. Evenden
*/
static const char
LIBPROJ_ID[] = "Id";
/*
** Permission is hereby granted, free of charge, to any person obtaining
** a copy of this software and associated documentation files (the
** "Software"), to deal in the Software without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Software, and to
** permit persons to whom the Software is furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be
** included in all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#define PROJ_PARMS__ \
  double  n; \
  double  rho_c; \
  double  rho_0; \
  double  sig; \
  double  c1, c2; \
  int    type;
#define PROJ_LIB__
#include  <lib_proj.h>
#define EULER 0
#define MURD1 1
#define MURD2 2
#define MURD3 3
#define PCONIC 4
#define TISSOT 5
#define VITK1 6
#define EPS10  1.e-10
#define EPS 1e-10
#define LINE2 "\n\tConic, Sph\n\tlat_1= and lat_2="
PROJ_HEAD(tissot, "Tissot")
  LINE2;
PROJ_HEAD(murd1, "Murdoch I")
  LINE2;
PROJ_HEAD(murd2, "Murdoch II")
  LINE2;
PROJ_HEAD(murd3, "Murdoch III")
  LINE2;
PROJ_HEAD(euler, "Euler")
  LINE2;
PROJ_HEAD(pconic, "Perspective Conic")
  LINE2;
PROJ_HEAD(vitk1, "Vitkovsky I")
  LINE2;
/* get common factors for simple conics */
  static int
phi12(PROJ *P, double *del) {
  double p1, p2;
  int err = 0;

  if (!proj_param(P->params, "tlat_1").i ||
    !proj_param(P->params, "tlat_2").i) {
    err = -41;
  } else {
    p1 = proj_param(P->params, "rlat_1").f;
    p2 = proj_param(P->params, "rlat_2").f;
    *del = 0.5 * (p2 - p1);
    P->sig = 0.5 * (p2 + p1);
    err = (fabs(*del) < EPS || fabs(P->sig) < EPS) ? -42 : 0;
    *del = *del;
  }
  return err;
}
FORWARD(s_forward); /* spheroid */
  double rho;

  switch (P->type) {
  case MURD2:
    rho = P->rho_c + tan(P->sig - lp.phi);
    break;
  case PCONIC:
    rho = P->c2 * (P->c1 - tan(lp.phi));
    break;
  default:
    rho = P->rho_c - lp.phi;
    break;
  }
  xy.x = rho * sin( lp.lam *= P->n );
  xy.y = P->rho_0 - rho * cos(lp.lam);
  return (xy);
}
INVERSE(s_inverse); /* ellipsoid & spheroid */
  double rho;

  rho = hypot(xy.x, xy.y = P->rho_0 - xy.y);
  if (P->n < 0.) {
    rho = - rho;
    xy.x = - xy.x;
    xy.y = - xy.y;
  }
  lp.lam = atan2(xy.x, xy.y) / P->n;
  switch (P->type) {
  case PCONIC:
    lp.phi = atan(P->c1 - rho / P->c2) + P->sig;
    break;
  case MURD2:
    lp.phi = P->sig - atan(rho - P->rho_c);
    break;
  default:
    lp.phi = P->rho_c - rho;
  }
  return (lp);
}
FREEUP; if (P) free(P); }
  static PROJ *
setup(PROJ *P) {
  double del, cs;
  int i;

  if ((i = phi12(P, &del)))
    E_ERROR(i);
  switch (P->type) {
  case TISSOT:
    P->n = sin(P->sig);
    cs = cos(del);
    P->rho_c = P->n / cs + cs / P->n;
    P->rho_0 = sqrt((P->rho_c - 2 * sin(P->phi0))/P->n);
    break;
  case MURD1:
    P->rho_c = sin(del)/(del * tan(P->sig)) + P->sig;
    P->rho_0 = P->rho_c - P->phi0;
    P->n = sin(P->sig);
    break;
  case MURD2:
    P->rho_c = (cs = sqrt(cos(del))) / tan(P->sig);
    P->rho_0 = P->rho_c + tan(P->sig - P->phi0);
    P->n = sin(P->sig) * cs;
    break;
  case MURD3:
    P->rho_c = del / (tan(P->sig) * tan(del)) + P->sig;
    P->rho_0 = P->rho_c - P->phi0;
    P->n = sin(P->sig) * sin(del) * tan(del) / (del * del);
    break;
  case EULER:
    P->n = sin(P->sig) * sin(del) / del;
    del *= 0.5;
    P->rho_c = del / (tan(del) * tan(P->sig)) + P->sig;  
    P->rho_0 = P->rho_c - P->phi0;
    break;
  case PCONIC:
    P->n = sin(P->sig);
    P->c2 = cos(del);
    P->c1 = 1./tan(P->sig);
    if (fabs(del = P->phi0 - P->sig) - EPS10 >= HALFPI)
      E_ERROR(-43);
    P->rho_0 = P->c2 * (P->c1 - tan(del));
    break;
  case VITK1:
    P->n = (cs = tan(del)) * sin(P->sig) / del;
    P->rho_c = del / (cs * tan(P->sig)) + P->sig;
    P->rho_0 = P->rho_c - P->phi0;
    break;
  }
  P->inv = s_inverse;
  P->fwd = s_forward;
  P->es = 0;
  return (P);
}
ENTRY0(euler) P->type = EULER; ENDENTRY(setup(P))
ENTRY0(tissot) P->type = TISSOT; ENDENTRY(setup(P))
ENTRY0(murd1) P->type = MURD1; ENDENTRY(setup(P))
ENTRY0(murd2) P->type = MURD2; ENDENTRY(setup(P))
ENTRY0(murd3) P->type = MURD3; ENDENTRY(setup(P))
ENTRY0(pconic) P->type = PCONIC; ENDENTRY(setup(P))
ENTRY0(vitk1) P->type = VITK1; ENDENTRY(setup(P))
/*
** Log: proj_sconics.c
** Revision 3.1  2006/01/11 01:38:18  gie
** Initial
**
*/