From 20aef8acd2b079ff6d041d512016d77a789bdb9d Mon Sep 17 00:00:00 2001 From: Soper Date: Thu, 3 Jun 2021 16:19:04 -0400 Subject: [PATCH] creating a class for mathematical calculations --- src/xyz/soper/arty/util/ArtyMath.java | 46 +++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/xyz/soper/arty/util/ArtyMath.java diff --git a/src/xyz/soper/arty/util/ArtyMath.java b/src/xyz/soper/arty/util/ArtyMath.java new file mode 100644 index 0000000..3c37ee5 --- /dev/null +++ b/src/xyz/soper/arty/util/ArtyMath.java @@ -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); + } + +}