PEARL Procedures rev-distro-1.6.0-0-gcf1399e-dirty Igor procedures for the analysis of PEARL data

- Main Page
- Related Pages
- Packages
- Namespaces
- Files

- File List
- Globals

pearl-polar-coordinates.ipf
Go to the documentation of this file.
1 #pragma rtGlobals=3
2 #pragma version = 1.1
3 #pragma IgorVersion = 6.1
4 #pragma ModuleName = PearlPolarCoordinates
5
6 // author: matthias.muntwiler@psi.ch
7 // Copyright (c) 2011-13 Paul Scherrer Institut
8 // $Id$
9
10 variable cart2polar(variable xx, variable yy, variable zz, variable* radius, variable* theta, variable* phi){
11 // converts a 3-vector from Cartesian to polar coordinates
12 variable xx, yy, zz
13 variable &radius, &theta, &phi// angles in degrees
14
15 radius = sqrt(xx^2 + yy^2 + zz^2)
16
17 if (radius > 0)
18 theta = acos(zz / radius) * 180 / pi
19 else
20 theta = 0
21 endif
22
23 if (xx > 0)
24 phi = atan(yy / xx) * 180 / pi
25 else if (xx < 0)
26 phi = atan(yy / xx) * 180 / pi + 180
27 else
28 if (yy > 0)
29 phi = 90
30 else
31 phi = 270
32 endif
33 endif
34 };
35
36 variable cart2polar_wave(wave in, wave out){
37 // converts a wave of 3-vectors from Cartesian to polar coordinates
38 wave in// wave with dimensions (3, N), N >= 1, (x, y, z)
39 wave out// wave same dimensions as in, (radius, theta, phi)
40 // angles in degrees
41
42 out[0][] = sqrt(in[0][q]^2 + in[1][q]^2 + in[2][q]^2)
43 out[1][] = acos(in[2][q] / out[0][q]) * 180 / pi
44 out[2][] = atan(in[1][q] / in[0][q]) * 180 / pi + 180 * (in[0][q] < 0)
45 out[2][] = numtype(out[2][q]) == 0 ? out[2][q] : 90 + 180 * (in[1][q] < 0)
46 };
47
48 variable polar2cart(variable radius, variable theta, variable phi, variable* xx, variable* yy, variable* zz){
49 // converts a 3-vector from Cartesian to polar coordinates
50 variable radius, theta, phi// angles in degrees
51 variable &xx, &yy, &zz
52
53 xx = radius * sin(theta * pi / 180) * cos(phi * pi / 180)
54 yy = radius * sin(theta * pi / 180) * sin(phi * pi / 180)
55 zz = radius * cos(theta * pi / 180)
56 };
57
58 variable polar2cart_wave(wave in, wave out){
59 // converts a wave of 3-vectors from polar to Cartesian coordinates
60 wave in// wave with dimensions (3, N), N >= 1, (radius, theta, phi)
61 // angles in degrees
62 wave out// wave same dimensions as in, (x, y, z)
63
64 out[0][] = in[0][q] * sin(in[1][q] * pi / 180) * cos(in[2][q] * pi / 180)
65 out[1][] = in[0][q] * sin(in[1][q] * pi / 180) * sin(in[2][q] * pi / 180)
66 out[2][] = in[0][q] * cos(in[1][q] * pi / 180)
67 };
68
69 variable polar_distance(variable polar1, variable azim1, variable polar2, variable azim2){
70 // returns the angle between two spherical coordinates
71 variable polar1, azim1
72 // angles in degrees
73 variable polar2, azim2
74 // angles in degrees
75
76 variable xx1, yy1, zz1
77 variable xx2, yy2, zz2
78
79 polar2cart(1, polar1, azim1, xx1, yy1, zz1)
80 polar2cart(1, polar2, azim2, xx2, yy2, zz2)
81
82 variable vv
83 vv = (xx1 * xx2 + yy1 * yy2 + zz1 * zz2) / sqrt(xx1^2 + yy1^2 + zz1^2) / sqrt(xx2^2 + yy2^2 + zz2^2)
84 return acos(vv) * 180 / pi
85 };
86
polar2cart_wave
variable polar2cart_wave(wave in, wave out)
Definition: pearl-polar-coordinates.ipf:58
cart2polar
variable cart2polar(variable xx, variable yy, variable zz, variable *radius, variable *theta, variable *phi)
Definition: pearl-polar-coordinates.ipf:10
cart2polar_wave
variable cart2polar_wave(wave in, wave out)
Definition: pearl-polar-coordinates.ipf:36
polar_distance
variable polar_distance(variable polar1, variable azim1, variable polar2, variable azim2)
Definition: pearl-polar-coordinates.ipf:69
polar2cart
variable polar2cart(variable radius, variable theta, variable phi, variable *xx, variable *yy, variable *zz)
Definition: pearl-polar-coordinates.ipf:48