Added math for Spherical coordinates

ref for math http://en.wikipedia.org/wiki/Spherical_coordinates

Might be adding more math methods later as i need them
This commit is contained in:
Robert Seifert 2013-06-05 03:03:09 -04:00
parent 0fcb2a0a54
commit c3684dc952

View file

@ -1,6 +1,24 @@
package dark.library.math;
import universalelectricity.core.vector.Vector3;
import dark.library.helpers.Pair;
public class LinearAlg
{
public Pair<Double, Double> vecToSphereAngles(Vector3 vec)
{
double radius = Math.sqrt((vec.x * vec.x) + (vec.y * vec.y) + (vec.z * vec.z));
double inclination = Math.acos(vec.z / radius);
double azimuth = Math.atan(vec.y / vec.z);
return new Pair<Double, Double>(inclination, azimuth);
}
public Vector3 sphereAnglesToVec(Double radius, Double inclination, Double azimuth)
{
double x = radius * Math.sin(inclination) * Math.cos(azimuth);
double y = radius * Math.sin(inclination) * Math.sin(azimuth);
double z = radius * Math.cos(inclination);
return new Vector3(x, y, z);
}
}