1 package org.bukkit.util;
3 import java.util.LinkedHashMap;
5 import java.util.Random;
6 import org.bukkit.Location;
7 import org.bukkit.World;
8 import org.bukkit.configuration.serialization.ConfigurationSerializable;
9 import org.bukkit.configuration.serialization.SerializableAs;
17 @SerializableAs(
"Vector")
19 private static final long serialVersionUID = -2657651106777219169L;
21 private static Random random =
new Random();
26 private static final double epsilon = 0.000001;
61 public Vector(
double x,
double y,
double z) {
74 public Vector(
float x,
float y,
float z) {
155 return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2));
164 return Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2);
178 return Math.sqrt(Math.pow(x - o.
x, 2) + Math.pow(y - o.
y, 2) + Math.pow(z - o.
z, 2));
188 return Math.pow(x - o.
x, 2) + Math.pow(y - o.
y, 2) + Math.pow(z - o.
z, 2);
198 double dot = dot(other) / (length() * other.
length());
200 return (
float) Math.acos(dot);
210 x = (x + other.
x) / 2;
211 y = (y + other.
y) / 2;
212 z = (z + other.
z) / 2;
223 double x = (this.x + other.
x) / 2;
224 double y = (this.y + other.
y) / 2;
225 double z = (this.z + other.
z) / 2;
226 return new Vector(x, y, z);
276 return x * other.
x + y * other.
y + z * other.
z;
291 double newX = y * o.
z - o.
y * z;
292 double newY = z * o.
x - o.
z * x;
293 double newZ = x * o.
y - o.
x * y;
307 double length = length();
338 return x >= min.
x && x <= max.
x && y >= min.
y && y <= max.
y && z >= min.
z && z <= max.
z;
349 return (Math.pow(origin.
x - x, 2) + Math.pow(origin.
y - y, 2) + Math.pow(origin.
z - z, 2)) <= Math.pow(radius, 2);
517 if (!(obj instanceof
Vector)) {
521 Vector other = (Vector) obj;
523 return Math.abs(x - other.
x) < epsilon && Math.abs(y - other.
y) < epsilon && Math.abs(z - other.
z) < epsilon && (this.getClass().equals(obj.getClass()));
535 hash = 79 * hash + (int) (Double.doubleToLongBits(
this.x) ^ (Double.doubleToLongBits(this.x) >>> 32));
536 hash = 79 * hash + (int) (Double.doubleToLongBits(
this.y) ^ (Double.doubleToLongBits(this.y) >>> 32));
537 hash = 79 * hash + (int) (Double.doubleToLongBits(
this.z) ^ (Double.doubleToLongBits(this.z) >>> 32));
550 }
catch (CloneNotSupportedException e) {
560 return x +
"," + y +
"," + z;
570 return new Location(world, x, y, z);
582 return new Location(world, x, y, z, yaw, pitch);
611 return new Vector(Math.min(v1.
x, v2.
x), Math.min(v1.
y, v2.
y), Math.min(v1.
z, v2.
z));
622 return new Vector(Math.max(v1.
x, v2.
x), Math.max(v1.
y, v2.
y), Math.max(v1.
z, v2.
z));
632 return new Vector(random.nextDouble(), random.nextDouble(), random.nextDouble());
636 Map<String, Object> result =
new LinkedHashMap<String, Object>();
638 result.put(
"x", getX());
639 result.put(
"y", getY());
640 result.put(
"z", getZ());
650 if (args.containsKey(
"x")) {
651 x = (Double) args.get(
"x");
653 if (args.containsKey(
"y")) {
654 y = (Double) args.get(
"y");
656 if (args.containsKey(
"z")) {
657 z = (Double) args.get(
"z");
660 return new Vector(x, y, z);