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