creating a class for mathematical calculations

master
Soper Aylamo 2021-06-03 16:19:04 -04:00
parent c93696c628
commit 20aef8acd2
Signed by: Soper
GPG Key ID: A27AC885ACC3BEAE
1 changed files with 46 additions and 0 deletions

View File

@ -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);
}
}