-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathKoordinatentransformation.cpp
79 lines (70 loc) · 2.47 KB
/
Koordinatentransformation.cpp
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
/*
* Koordinatentransformation.cpp
*
* Copyright (c) 2011-2017 Stefan Bender
* Copyright (c) 2010-2011 Martin Langowski
*
* Initial version created on: 08.09.2010
* Author: Martin Langowski
*
* This file is part of scia_retrieval_2d
*
* scia_retrieval_2d is free software: you can redistribute it or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2.
* See accompanying COPYING.GPL2 file or http://www.gnu.org/licenses/gpl-2.0.html.
*/
#include <cmath>
#include<iostream>
////////////////////////////////////////////////////////////////////////////////
// Kugelkoordinaten
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////
// Funktionsstart int Umwandlung_Kugel_in_Karthesisch(double r,double phi,
// double theta,double& x,double& y,double& z);
////////////////////////////////////////////////
void Umwandlung_Kugel_in_Karthesisch(double r, double phi, double theta,
double &x, double &y, double &z)
{
// Winkel in Grad
const double deg = M_PI / 180.0;
const double cth = cos(deg * theta), sth = sin(deg * theta);
const double cph = cos(deg * phi), sph = sin(deg * phi);
x = r * cth * cph;
y = r * cth * sph;
z = r * sth;
}
////////////////////////////////////////////////
// ENDE int Umwandlung_Kugel_in_Karthesisch
////////////////////////////////////////////////
////////////////////////////////////////////////
// Funktionsstart int Umwandlung_Karthesisch_in_Kugel(double x,double y,
// double z,double& r,double& phi,double& theta);
////////////////////////////////////////////////
void Umwandlung_Karthesisch_in_Kugel(double x, double y, double z, double &r,
double &phi, double &theta)
{
// Winkel in Grad
// Der Punkt 0,0,0 ist ausgeschlossen
const double rad = 180.0 * M_1_PI;
r = sqrt(x * x + y * y + z * z);
if (r == 0.0) {
std::cout << " Umwandlung in Kugelkoordinaten von (0,0,0) nicht sinnvoll\n";
phi = 0;
theta = 0;
return;
}
theta = rad * asin(z / r);
if ((theta >= 90.0) || (theta <= -90.0)) {
// Phi quasi beliebig
phi = 0;
return;
}
phi = rad * atan2(y, x);
}
////////////////////////////////////////////////
// ENDE int Umwandlung_Karthesisch_in_Kugel
////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// ENDE Kugelkoordinaten
////////////////////////////////////////////////////////////////////////////////