Merge math helper classes

This commit is contained in:
DarkGuardsman 2013-09-02 15:38:40 -04:00
parent c9a8298058
commit 3e9849b45e
2 changed files with 27 additions and 31 deletions

View file

@ -1,31 +0,0 @@
package dark.prefab.helpers;
import universalelectricity.core.vector.Vector3;
public class LinearAlg
{
/** @param vec - vector3 that is on the sphere
* @return new Vector3(radius, inclination, azimuth) */
public static Vector3 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 Vector3(radius, inclination, azimuth);
}
/** Turns radius and sphere cords into a vector3
*
* @param radius - sphere radius
* @param inclination -
* @param azimuth
* @return Vector3(x,y,z) */
public static 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);
}
}

View file

@ -2,6 +2,8 @@ package dark.prefab.helpers;
import java.util.Random;
import universalelectricity.core.vector.Vector3;
public class MathHelper extends net.minecraft.util.MathHelper
{
/** Generates an array of random numbers
@ -40,4 +42,29 @@ public class MathHelper extends net.minecraft.util.MathHelper
}
return array;
}
/** @param vec - vector3 that is on the sphere
* @return new Vector3(radius, inclination, azimuth) */
public static Vector3 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 Vector3(radius, inclination, azimuth);
}
/** Turns radius and sphere cords into a vector3
*
* @param radius - sphere radius
* @param inclination -
* @param azimuth
* @return Vector3(x,y,z) */
public static 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);
}
}