File: azimuthal-equidistant.glsl

package info (click to toggle)
python-vispy 0.6.6-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 21,344 kB
  • sloc: python: 57,412; javascript: 6,810; makefile: 63; sh: 5
file content (38 lines) | stat: -rw-r--r-- 1,286 bytes parent folder | download | duplicates (5)
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
// ----------------------------------------------------------------------------
// Copyright (c) 2014, Nicolas P. Rougier. All Rights Reserved.
// Distributed under the (new) BSD License.
// ----------------------------------------------------------------------------

float scale(float x) {
    float c = acos(x);
    if (c != 0.0)
        return c / sin(c);
    discard;
 }
float angle(float x) { return x; }

vec2 forward(float longitude, float latitude)
{
    float cos_lon = cos(longitude);
    float cos_lat = cos(latitude);
    float k = scale(cos_lon * cos_lat);
    return vec2( k * cos_lat * sin(longitude), k * sin(latitude));
}
vec2 forward(vec2 P) { return forward(P.x,P.y); }
vec3 forward(vec3 P) { return vec3(forward(P.x,P.y), P.z); }
vec4 forward(vec4 P) { return vec4(forward(P.x,P.y), P.z, P.w); }

vec2 inverse(float x, float y)
{
    float rho = sqrt(x*x + y*y);
    float c = angle(rho);
    float sinc = sin(c);
    float cosc = cos(c);
    //if (rho != 0)
    return vec2( atan(x*sinc, rho*cosc), asin(y*sinc/rho));
    //else
    //return vec2( atan(x*sinc, rho*cosc), asin(1e10));
}
vec2 inverse(vec2 P) { return inverse(P.x,P.y); }
vec3 inverse(vec3 P) { return vec3(inverse(P.x,P.y), P.z); }
vec4 inverse(vec4 P) { return vec4(inverse(P.x,P.y), P.z, P.w); }