nux-1.14.0
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #include "../NuxCore.h" 00024 #include "Trigonometry.h" 00025 #include "Constants.h" 00026 00027 namespace nux 00028 { 00029 00030 // Assume the spherical coordinate system relatively to a right handed xyz, 00031 // with Z pointing up. 00032 // 0 <= phi < 180 00033 // 0 <= theta < 360 ->>> along X axis, theta = 0. 00034 Vector3 SphericalToCartesianXBaseDeg (float r, float theta, float phi) 00035 { 00036 Vector3 v; 00037 v.x = r * std::cos (theta * Const::pi / 180.0f) * std::sin (phi * Const::pi / 180.0f); 00038 v.y = r * std::sin (theta * Const::pi / 180.0f) * std::sin (phi * Const::pi / 180.0f); 00039 v.z = r * std::cos (phi * Const::pi / 180.0f); 00040 return v; 00041 } 00042 00043 Vector3 SphericalToCartesianXBaseRad (float r, float theta, float phi) 00044 { 00045 Vector3 v; 00046 v.x = r * std::cos (theta) * std::sin (phi); 00047 v.y = r * std::sin (theta) * std::sin (phi); 00048 v.z = r * std::cos (phi); 00049 return v; 00050 } 00051 00052 // Assume the spherical coordinate system relatively to a right handed xyz, 00053 // with Y pointing up. 00054 // 0 <= phi < 180 00055 // 0 <= theta < 360 ->>> along Z axis, theta = 0. 00056 Vector3 SphericalToCartesianZBaseDeg (float r, float theta, float phi) 00057 { 00058 Vector3 v; 00059 v.z = r * std::cos (theta * Const::pi / 180.0f) * std::sin (phi * Const::pi / 180.0f); 00060 v.x = r * std::sin (theta * Const::pi / 180.0f) * std::sin (phi * Const::pi / 180.0f); 00061 v.y = r * std::cos (phi * Const::pi / 180.0f); 00062 return v; 00063 } 00064 00065 Vector3 SphericalToCartesianZBaseRad (float r, float theta, float phi) 00066 { 00067 Vector3 v; 00068 v.z = r * std::cos (theta) * std::sin (phi); 00069 v.x = r * std::sin (theta) * std::sin (phi); 00070 v.y = r * std::cos (phi); 00071 return v; 00072 } 00073 00074 Vector3 CartesianToSphericalXBaseRad (float x, float y, float z) 00075 { 00076 float r, theta, phi; 00077 r = std::sqrt (x * x + y * y + z * z); 00078 theta = std::atan (y / x); 00079 phi = std::acos (z / r); 00080 return Vector3 (r, theta, phi); 00081 } 00082 00083 Vector3 CartesianToSphericalZBaseDeg (float x, float y, float z) 00084 { 00085 float r, theta, phi; 00086 r = std::sqrt (x * x + y * y + z * z); 00087 theta = std::atan (x / z); 00088 phi = std::acos (y / r); 00089 return Vector3 (r, theta, phi); 00090 } 00091 00092 } 00093