Bukkit  1.4.7-R1.0
org.bukkit.util.Vector Class Reference

Represents a mutable vector. More...

Inheritance diagram for org.bukkit.util.Vector:
Collaboration diagram for org.bukkit.util.Vector:

## Public Member Functions

Vector ()
Construct the vector with all components as 0.

Vector (int x, int y, int z)
Construct the vector with provided integer components.

Vector (double x, double y, double z)
Construct the vector with provided double components.

Vector (float x, float y, float z)
Construct the vector with provided float components.

Adds a vector to this one.

Vector subtract (Vector vec)
Subtracts a vector from this one.

Vector multiply (Vector vec)
Multiplies the vector by another.

Vector divide (Vector vec)
Divides the vector by another.

Vector copy (Vector vec)
Copies another vector.

double length ()
Gets the magnitude of the vector, defined as sqrt(x^2+y^2+z^2).

double lengthSquared ()
Gets the magnitude of the vector squared.

double distance (Vector o)
Get the distance between this vector and another.

double distanceSquared (Vector o)
Get the squared distance between this vector and another.

float angle (Vector other)
Gets the angle between this vector and another in radians.

Vector midpoint (Vector other)
Sets this vector to the midpoint between this vector and another.

Vector getMidpoint (Vector other)
Gets a new midpoint vector between this vector and another.

Vector multiply (int m)
Performs scalar multiplication, multiplying all components with a scalar.

Vector multiply (double m)
Performs scalar multiplication, multiplying all components with a scalar.

Vector multiply (float m)
Performs scalar multiplication, multiplying all components with a scalar.

double dot (Vector other)
Calculates the dot product of this vector with another.

Vector crossProduct (Vector o)
Calculates the cross product of this vector with another.

Vector normalize ()
Converts this vector to a unit vector (a vector with length of 1).

Vector zero ()
Zero this vector's components.

boolean isInAABB (Vector min, Vector max)
Returns whether this vector is in an axis-aligned bounding box.

boolean isInSphere (Vector origin, double radius)
Returns whether this vector is within a sphere.

double getX ()
Gets the X component.

int getBlockX ()
Gets the floored value of the X component, indicating the block that this vector is contained with.

double getY ()
Gets the Y component.

int getBlockY ()
Gets the floored value of the Y component, indicating the block that this vector is contained with.

double getZ ()
Gets the Z component.

int getBlockZ ()
Gets the floored value of the Z component, indicating the block that this vector is contained with.

Vector setX (int x)
Set the X component.

Vector setX (double x)
Set the X component.

Vector setX (float x)
Set the X component.

Vector setY (int y)
Set the Y component.

Vector setY (double y)
Set the Y component.

Vector setY (float y)
Set the Y component.

Vector setZ (int z)
Set the Z component.

Vector setZ (double z)
Set the Z component.

Vector setZ (float z)
Set the Z component.

boolean equals (Object obj)
Checks to see if two objects are equal.

int hashCode ()
Returns a hash code for this vector.

Vector clone ()
Get a new vector.

String toString ()
Returns this vector's components as x,y,z.

Location toLocation (World world)
Gets a Location version of this vector with yaw and pitch being 0.

Location toLocation (World world, float yaw, float pitch)
Gets a Location version of this vector.

BlockVector toBlockVector ()
Get the block vector of this vector.

Map< String, Object > serialize ()

Public Member Functions inherited from org.bukkit.configuration.serialization.ConfigurationSerializable
Map< String, Object > serialize ()
Creates a Map representation of this class.

## Static Public Member Functions

static double getEpsilon ()
Get the threshold used for equals().

static Vector getMinimum (Vector v1, Vector v2)
Gets the minimum components of two vectors.

static Vector getMaximum (Vector v1, Vector v2)
Gets the maximum components of two vectors.

static Vector getRandom ()
Gets a random vector with components having a random value between 0 and 1.

static Vector deserialize (Map< String, Object > args)

double x

double y

double z

## Detailed Description

Represents a mutable vector.

Because the components of Vectors are mutable, storing Vectors long term may be dangerous if passing code modifies the Vector later. If you want to keep around a Vector, it may be wise to call clone() in order to get a copy.

Definition at line 18 of file Vector.java.

## Constructor & Destructor Documentation

 org.bukkit.util.Vector.Vector ( )

Construct the vector with all components as 0.

Definition at line 35 of file Vector.java.

 org.bukkit.util.Vector.Vector ( int x, int y, int z )

Construct the vector with provided integer components.

Parameters
 x X component y Y component z Z component

Definition at line 48 of file Vector.java.

 org.bukkit.util.Vector.Vector ( double x, double y, double z )

Construct the vector with provided double components.

Parameters
 x X component y Y component z Z component

Definition at line 61 of file Vector.java.

 org.bukkit.util.Vector.Vector ( float x, float y, float z )

Construct the vector with provided float components.

Parameters
 x X component y Y component z Z component

Definition at line 74 of file Vector.java.

## Member Function Documentation

 Vector org.bukkit.util.Vector.add ( Vector vec )

Adds a vector to this one.

Parameters
 vec The other vector
Returns
the same vector

Definition at line 86 of file Vector.java.

 float org.bukkit.util.Vector.angle ( Vector other )

Gets the angle between this vector and another in radians.

Parameters
 other The other vector
Returns

Definition at line 197 of file Vector.java.

References org.bukkit.util.Vector.length().

 Vector org.bukkit.util.Vector.clone ( )

Get a new vector.

Returns
vector

Definition at line 547 of file Vector.java.

References org.bukkit.util.Vector.clone().

 Vector org.bukkit.util.Vector.copy ( Vector vec )

Copies another vector.

Parameters
 vec The other vector
Returns
the same vector

Definition at line 138 of file Vector.java.

 Vector org.bukkit.util.Vector.crossProduct ( Vector o )

Calculates the cross product of this vector with another.

The cross product is defined as:

x = y1 * z2 - y2 * z1
y = z1 * x2 - z2 * x1
z = x1 * y2 - x2 * y1

Parameters
 o The other vector
Returns
the same vector

Definition at line 290 of file Vector.java.

 static Vector org.bukkit.util.Vector.deserialize ( Map< String, Object > args )
static

Definition at line 645 of file Vector.java.

 double org.bukkit.util.Vector.distance ( Vector o )

Get the distance between this vector and another.

The value of this method is not cached and uses a costly square-root function, so do not repeatedly call this method to get the vector's magnitude. NaN will be returned if the inner result of the sqrt() function overflows, which will be caused if the distance is too long.

Parameters
 o The other vector
Returns
the distance

Definition at line 177 of file Vector.java.

 double org.bukkit.util.Vector.distanceSquared ( Vector o )

Get the squared distance between this vector and another.

Parameters
 o The other vector
Returns
the distance

Definition at line 187 of file Vector.java.

 Vector org.bukkit.util.Vector.divide ( Vector vec )

Divides the vector by another.

Parameters
 vec The other vector
Returns
the same vector

Definition at line 125 of file Vector.java.

 double org.bukkit.util.Vector.dot ( Vector other )

Calculates the dot product of this vector with another.

The dot product is defined as x1*x2+y1*y2+z1*z2. The returned value is a scalar.

Parameters
 other The other vector
Returns
dot product

Definition at line 275 of file Vector.java.

 boolean org.bukkit.util.Vector.equals ( Object obj )

Checks to see if two objects are equal.

Only two Vectors can ever return true. This method uses a fuzzy match to account for floating point errors. The epsilon can be retrieved with epsilon.

Definition at line 516 of file Vector.java.

 int org.bukkit.util.Vector.getBlockX ( )

Gets the floored value of the X component, indicating the block that this vector is contained with.

Returns
block X

Definition at line 367 of file Vector.java.

References org.bukkit.util.NumberConversions.floor().

 int org.bukkit.util.Vector.getBlockY ( )

Gets the floored value of the Y component, indicating the block that this vector is contained with.

Returns
block y

Definition at line 386 of file Vector.java.

References org.bukkit.util.NumberConversions.floor().

 int org.bukkit.util.Vector.getBlockZ ( )

Gets the floored value of the Z component, indicating the block that this vector is contained with.

Returns
block z

Definition at line 405 of file Vector.java.

References org.bukkit.util.NumberConversions.floor().

 static double org.bukkit.util.Vector.getEpsilon ( )
static

Get the threshold used for equals().

Returns
The epsilon.

Definition at line 599 of file Vector.java.

 static Vector org.bukkit.util.Vector.getMaximum ( Vector v1, Vector v2 )
static

Gets the maximum components of two vectors.

Parameters
 v1 The first vector. v2 The second vector.
Returns
maximum

Definition at line 621 of file Vector.java.

 Vector org.bukkit.util.Vector.getMidpoint ( Vector other )

Gets a new midpoint vector between this vector and another.

Parameters
 other The other vector
Returns
a new midpoint vector

Definition at line 222 of file Vector.java.

 static Vector org.bukkit.util.Vector.getMinimum ( Vector v1, Vector v2 )
static

Gets the minimum components of two vectors.

Parameters
 v1 The first vector. v2 The second vector.
Returns
minimum

Definition at line 610 of file Vector.java.

 static Vector org.bukkit.util.Vector.getRandom ( )
static

Gets a random vector with components having a random value between 0 and 1.

Returns
A random vector.

Definition at line 631 of file Vector.java.

 double org.bukkit.util.Vector.getX ( )

Gets the X component.

Returns
The X component.

Definition at line 357 of file Vector.java.

 double org.bukkit.util.Vector.getY ( )

Gets the Y component.

Returns
The Y component.

Definition at line 376 of file Vector.java.

 double org.bukkit.util.Vector.getZ ( )

Gets the Z component.

Returns
The Z component.

Definition at line 395 of file Vector.java.

 int org.bukkit.util.Vector.hashCode ( )

Returns a hash code for this vector.

Returns
hash code

Definition at line 532 of file Vector.java.

 boolean org.bukkit.util.Vector.isInAABB ( Vector min, Vector max )

Returns whether this vector is in an axis-aligned bounding box.

The minimum and maximum vectors given must be truly the minimum and maximum X, Y and Z components.

Parameters
 min Minimum vector max Maximum vector
Returns
whether this vector is in the AABB

Definition at line 337 of file Vector.java.

 boolean org.bukkit.util.Vector.isInSphere ( Vector origin, double radius )

Returns whether this vector is within a sphere.

Parameters
Returns
whether this vector is in the sphere

Definition at line 348 of file Vector.java.

 double org.bukkit.util.Vector.length ( )

Gets the magnitude of the vector, defined as sqrt(x^2+y^2+z^2).

The value of this method is not cached and uses a costly square-root function, so do not repeatedly call this method to get the vector's magnitude. NaN will be returned if the inner result of the sqrt() function overflows, which will be caused if the length is too long.

Returns
the magnitude

Definition at line 154 of file Vector.java.

Referenced by org.bukkit.util.Vector.angle().

 double org.bukkit.util.Vector.lengthSquared ( )

Gets the magnitude of the vector squared.

Returns
the magnitude

Definition at line 163 of file Vector.java.

 Vector org.bukkit.util.Vector.midpoint ( Vector other )

Sets this vector to the midpoint between this vector and another.

Parameters
 other The other vector
Returns
this same vector (now a midpoint)

Definition at line 209 of file Vector.java.

 Vector org.bukkit.util.Vector.multiply ( Vector vec )

Multiplies the vector by another.

Parameters
 vec The other vector
Returns
the same vector

Definition at line 112 of file Vector.java.

 Vector org.bukkit.util.Vector.multiply ( int m )

Performs scalar multiplication, multiplying all components with a scalar.

Parameters
 m The factor
Returns
the same vector

Definition at line 235 of file Vector.java.

 Vector org.bukkit.util.Vector.multiply ( double m )

Performs scalar multiplication, multiplying all components with a scalar.

Parameters
 m The factor
Returns
the same vector

Definition at line 248 of file Vector.java.

 Vector org.bukkit.util.Vector.multiply ( float m )

Performs scalar multiplication, multiplying all components with a scalar.

Parameters
 m The factor
Returns
the same vector

Definition at line 261 of file Vector.java.

 Vector org.bukkit.util.Vector.normalize ( )

Converts this vector to a unit vector (a vector with length of 1).

Returns
the same vector

Definition at line 306 of file Vector.java.

 Map org.bukkit.util.Vector.serialize ( )

Definition at line 635 of file Vector.java.

 Vector org.bukkit.util.Vector.setX ( int x )

Set the X component.

Parameters
 x The new X component.
Returns
This vector.

Definition at line 415 of file Vector.java.

Referenced by org.bukkit.Location.getDirection().

 Vector org.bukkit.util.Vector.setX ( double x )

Set the X component.

Parameters
 x The new X component.
Returns
This vector.

Definition at line 426 of file Vector.java.

 Vector org.bukkit.util.Vector.setX ( float x )

Set the X component.

Parameters
 x The new X component.
Returns
This vector.

Definition at line 437 of file Vector.java.

 Vector org.bukkit.util.Vector.setY ( int y )

Set the Y component.

Parameters
 y The new Y component.
Returns
This vector.

Definition at line 448 of file Vector.java.

 Vector org.bukkit.util.Vector.setY ( double y )

Set the Y component.

Parameters
 y The new Y component.
Returns
This vector.

Definition at line 459 of file Vector.java.

 Vector org.bukkit.util.Vector.setY ( float y )

Set the Y component.

Parameters
 y The new Y component.
Returns
This vector.

Definition at line 470 of file Vector.java.

 Vector org.bukkit.util.Vector.setZ ( int z )

Set the Z component.

Parameters
 z The new Z component.
Returns
This vector.

Definition at line 481 of file Vector.java.

Referenced by org.bukkit.Location.getDirection().

 Vector org.bukkit.util.Vector.setZ ( double z )

Set the Z component.

Parameters
 z The new Z component.
Returns
This vector.

Definition at line 492 of file Vector.java.

 Vector org.bukkit.util.Vector.setZ ( float z )

Set the Z component.

Parameters
 z The new Z component.
Returns
This vector.

Definition at line 503 of file Vector.java.

 Vector org.bukkit.util.Vector.subtract ( Vector vec )

Subtracts a vector from this one.

Parameters
 vec The other vector
Returns
the same vector

Definition at line 99 of file Vector.java.

 BlockVector org.bukkit.util.Vector.toBlockVector ( )

Get the block vector of this vector.

Returns
A block vector.

Definition at line 590 of file Vector.java.

 Location org.bukkit.util.Vector.toLocation ( World world )

Gets a Location version of this vector with yaw and pitch being 0.

Parameters
 world The world to link the location to.
Returns
the location

Definition at line 569 of file Vector.java.

 Location org.bukkit.util.Vector.toLocation ( World world, float yaw, float pitch )

Gets a Location version of this vector.

Parameters
 world The world to link the location to. yaw The desired yaw. pitch The desired pitch.
Returns
the location

Definition at line 581 of file Vector.java.

 String org.bukkit.util.Vector.toString ( )

Returns this vector's components as x,y,z.

Definition at line 559 of file Vector.java.

 Vector org.bukkit.util.Vector.zero ( )

Zero this vector's components.

Returns
the same vector

Definition at line 321 of file Vector.java.

## Member Data Documentation

 double org.bukkit.util.Vector.x
protected
 double org.bukkit.util.Vector.y
protected
 double org.bukkit.util.Vector.z
protected

The documentation for this class was generated from the following file: