Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.craftstuebchen.particles;
- import org.bukkit.Location;
- import org.bukkit.entity.Entity;
- import org.bukkit.util.Vector;
- import java.util.Random;
- public class MathUtils {
- public static Random random = new Random();
- public static final Vector rotateAroundAxisX(Vector v, double angle) {
- double y, z, cos, sin;
- cos = Math.cos(angle);
- sin = Math.sin(angle);
- y = v.getY() * cos - v.getZ() * sin;
- z = v.getY() * sin + v.getZ() * cos;
- return v.setY(y).setZ(z);
- }
- public static final Vector rotateAroundAxisY(Vector v, double angle) {
- double x, z, cos, sin;
- cos = Math.cos(angle);
- sin = Math.sin(angle);
- x = v.getX() * cos + v.getZ() * sin;
- z = v.getX() * -sin + v.getZ() * cos;
- return v.setX(x).setZ(z);
- }
- public static final Vector rotateAroundAxisZ(Vector v, double angle) {
- double x, y, cos, sin;
- cos = Math.cos(angle);
- sin = Math.sin(angle);
- x = v.getX() * cos - v.getY() * sin;
- y = v.getX() * sin + v.getY() * cos;
- return v.setX(x).setY(y);
- }
- public static final Vector rotateVector(Vector v, double angleX, double angleY, double angleZ) {
- rotateAroundAxisX(v, angleX);
- rotateAroundAxisY(v, angleY);
- rotateAroundAxisZ(v, angleZ);
- return v;
- }
- public static final double angleToXAxis(Vector vector) {
- return Math.atan2(vector.getX(), vector.getY());
- }
- public static Vector getRandomVector() {
- double x = random.nextDouble() * 2.0D - 1.0D;
- double y = random.nextDouble() * 2.0D - 1.0D;
- double z = random.nextDouble() * 2.0D - 1.0D;
- return new Vector(x, y, z).normalize();
- }
- public static Vector getRandomCircleVector() {
- double rnd = random.nextDouble() * 2.0D * 3.141592653589793D;
- double x = Math.cos(rnd);
- double z = Math.sin(rnd);
- return new Vector(x, 0.0D, z);
- }
- public static double randomDouble(double min, double max) {
- return Math.random() < 0.5 ? ((1 - Math.random()) * (max - min) + min) : (Math.random() * (max - min) + min);
- }
- public static float randomRangeFloat(float min, float max) {
- return (float) (Math.random() < 0.5 ? ((1 - Math.random()) * (max - min) + min) : (Math.random() * (max - min) + min));
- }
- /**
- * Returns a random integer between the value min and the value max.
- * @param min the minimum integer value.
- * @param max the maximum integer value.
- * @return a random integer between two values.
- */
- public static int randomRangeInt(int min, int max) {
- return (int) (Math.random() < 0.5 ? ((1 - Math.random()) * (max - min) + min) : (Math.random() * (max - min) + min));
- }
- public static double offset(Entity a, Entity b) {
- return offset(a.getLocation().toVector(), b.getLocation().toVector());
- }
- public static double offset(Location a, Location b) {
- return offset(a.toVector(), b.toVector());
- }
- public static double offset(Vector a, Vector b) {
- return a.subtract(b).length();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement