2
* Copyright 2010 Inalogic Inc.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3, as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the applicable version of the GNU Lesser General Public
12
* License for more details.
14
* You should have received a copy of both the GNU Lesser General Public
15
* License version 3 along with this program. If not, see
16
* <http://www.gnu.org/licenses/>
18
* Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
23
#include "../NuxCore.h"
24
#include "Trigonometry.h"
25
#include "Constants.h"
30
// Assume the spherical coordinate system relatively to a right handed xyz,
31
// with Z pointing up.
33
// 0 <= theta < 360 ->>> along X axis, theta = 0.
34
Vector3 SphericalToCartesianXBaseDeg (float r, float theta, float phi)
37
v.x = r * std::cos (theta * Const::pi / 180.0f) * std::sin (phi * Const::pi / 180.0f);
38
v.y = r * std::sin (theta * Const::pi / 180.0f) * std::sin (phi * Const::pi / 180.0f);
39
v.z = r * std::cos (phi * Const::pi / 180.0f);
43
Vector3 SphericalToCartesianXBaseRad (float r, float theta, float phi)
46
v.x = r * std::cos (theta) * std::sin (phi);
47
v.y = r * std::sin (theta) * std::sin (phi);
48
v.z = r * std::cos (phi);
52
// Assume the spherical coordinate system relatively to a right handed xyz,
53
// with Y pointing up.
55
// 0 <= theta < 360 ->>> along Z axis, theta = 0.
56
Vector3 SphericalToCartesianZBaseDeg (float r, float theta, float phi)
59
v.z = r * std::cos (theta * Const::pi / 180.0f) * std::sin (phi * Const::pi / 180.0f);
60
v.x = r * std::sin (theta * Const::pi / 180.0f) * std::sin (phi * Const::pi / 180.0f);
61
v.y = r * std::cos (phi * Const::pi / 180.0f);
65
Vector3 SphericalToCartesianZBaseRad (float r, float theta, float phi)
68
v.z = r * std::cos (theta) * std::sin (phi);
69
v.x = r * std::sin (theta) * std::sin (phi);
70
v.y = r * std::cos (phi);
74
Vector3 CartesianToSphericalXBaseRad (float x, float y, float z)
77
r = std::sqrt (x * x + y * y + z * z);
78
theta = std::atan (y / x);
79
phi = std::acos (z / r);
80
return Vector3 (r, theta, phi);
83
Vector3 CartesianToSphericalZBaseDeg (float x, float y, float z)
86
r = std::sqrt (x * x + y * y + z * z);
87
theta = std::atan (x / z);
88
phi = std::acos (y / r);
89
return Vector3 (r, theta, phi);