creating a class for mathematical calculations
parent
c93696c628
commit
20aef8acd2
|
@ -0,0 +1,46 @@
|
|||
package xyz.soper.arty.util;
|
||||
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
/**
|
||||
* A class that handles mathematical calculations related to the mortar.
|
||||
* Can calculate angles based on three-dimensional vectors and vice-versa
|
||||
*/
|
||||
public class ArtyMath {
|
||||
|
||||
/**
|
||||
* Calculates the elevation angle of the vector.
|
||||
* @param vector Vector to calculate angle from
|
||||
* @return Angle from the ground in radians
|
||||
*/
|
||||
public static double calculateElevation(Vector vector){
|
||||
//TODO: Rewrite this method using math from scratch instead of another method
|
||||
Vector groundProjection = new Vector(vector.getX(), 0, vector.getZ());
|
||||
return groundProjection.angle(vector);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates angle from east of the vector.
|
||||
* @param vector Vector to calculate angle from
|
||||
* @return Angle from east in radians
|
||||
*/
|
||||
public static double calculateDirection(Vector vector){
|
||||
vector.setY(0);
|
||||
Vector eastVector = new Vector(1,0,0);
|
||||
return eastVector.angle(vector);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the elevation and direction angles given to return a unit vector corresponding to the angles.
|
||||
* @param elevation Angle of elevation in radians
|
||||
* @param direction Angle of direction from east in radians
|
||||
* @return A unit vector with the given direction and elevation.
|
||||
*/
|
||||
public static Vector calculateVector(double elevation, double direction){
|
||||
double X = Math.cos(elevation)*Math.cos(direction);
|
||||
double Y = Math.sin(elevation);
|
||||
double Z = Math.cos(elevation)*Math.sin(direction);
|
||||
return new Vector(X, Y, Z);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue