# Vector

``` public class Vector ```
``` extends Object ``` ``` ```

 java.lang.Object ↳ com.viro.core.Vector

Vector represents a 3-component floating-point vector.

## Summary

### Fields

``` public float``` `x`

The X coordinate.

``` public float``` `y`

The Y coordinate.

``` public float``` `z`

The Z coordinate.

### Public constructors

``` Vector() ```

Construct a new Vector centered at the origin.

``` Vector(float x, float y, float z) ```

Construct a new Vector from the given coordinates.

``` Vector(double x, double y, double z) ```

Construct a new Vector from the given double coordinates by downcasting them to floats.

``` Vector(float[] coordinates) ```

Construct a new Vector from the given coordinates in an array of length 3.

### Public methods

``` Vector``` ``` add(Vector vB) ```

Add this Vector to the given Vector and return the result (neither this Vector nor the input Vector are mutated).

``` void``` ``` clear() ```

Zero out this Vector.

``` Vector``` ``` cross(Vector vB) ```

Compute the cross product between this Vector and the given Vector and return the result (neither this Vector nor the input Vector are mutated).

``` float``` ``` distance(Vector vB) ```

Return the Euclidean distance between the position defined by this Vector and the position defined by the given Vector.

``` float``` ``` dot(Vector vB) ```

Return the dot product of this Vector with the given Vector.

``` boolean``` ``` equals(Object object) ```
``` int``` ``` hashCode() ```
``` Vector``` ``` interpolate(Vector other, float t) ```

Interpolate between this Vector and the given Vector by the given value (between 0 and 1), and return the result (neither this Vector nor the input Vector are mutated).

``` float``` ``` magnitude() ```

Return the magnitude of this Vector.

``` Vector``` ``` midpoint(Vector other) ```

Return the midpoint between this Vector and the given Vector.

``` Vector``` ``` normalize() ```

Normalize this vector and return the result (this Vector is not mutated).

``` boolean``` ``` rayIntersectPlane(Vector point, Vector normal, Vector origin, Vector intPt) ```

Determine if the ray defined by the given origin, in the direction of this Vector, intersects the plane defined by the given point and normal vector.

``` Vector``` ``` rotateAboutAxis(Vector axisDir, Vector axisPos, float angleRad) ```

Rotate this Vector about the given axis, and return the result (neither this Vector nor the input Vector are mutated).

``` Vector``` ``` scale(float factor) ```

Scale each component of this Vector by the given amount and return the result (this Vector is not mutated).

``` void``` ``` set(float x, float y, float z) ```

Set the X, Y, and X components of this Vector.

``` void``` ``` set(Vector value) ```

Set this Vector to equal the given vector.

``` Vector``` ``` subtract(Vector vB) ```

Subtract the given Vector from this Vector and return the result (neither this Vector nor the input Vector are mutated).

``` float[]``` ``` toArray() ```

Get the contents of the Vector in an array.

``` String``` ``` toString() ```

## Fields

### x

`float x`

The X coordinate.

### y

`float y`

The Y coordinate.

### z

`float z`

The Z coordinate.

## Public constructors

### Vector

`Vector ()`

Construct a new Vector centered at the origin.

### Vector

```Vector (float x,
float y,
float z)```

Construct a new Vector from the given coordinates.

Parameters
`x` `float`: The X coordinate.

`y` `float`: The Y coordinate.

`z` `float`: The Z coordinate.

### Vector

```Vector (double x,
double y,
double z)```

Construct a new Vector from the given double coordinates by downcasting them to floats.

Parameters
`x` `double`: The X coordinate.

`y` `double`: The Y coordinate.

`z` `double`: The Z coordinate.

### Vector

`Vector (float[] coordinates)`

Construct a new Vector from the given coordinates in an array of length 3.

Parameters
`coordinates` `float`: The x, y, and z coordinates.

## Public methods

`Vector add (Vector vB)`

Add this Vector to the given Vector and return the result (neither this Vector nor the input Vector are mutated).

Parameters
`vB` `Vector`: The Vector to add to this one.

Returns
`Vector` The result.

### clear

`void clear ()`

Zero out this Vector.

### cross

`Vector cross (Vector vB)`

Compute the cross product between this Vector and the given Vector and return the result (neither this Vector nor the input Vector are mutated).

Parameters
`vB` `Vector`: The Vector to cross with this one.

Returns
`Vector` The cross product of the two Vectors.

### distance

`float distance (Vector vB)`

Return the Euclidean distance between the position defined by this Vector and the position defined by the given Vector.

Parameters
`vB` `Vector`: Return the distance to this position.

Returns
`float` The distance between the two positions.

### dot

`float dot (Vector vB)`

Return the dot product of this Vector with the given Vector.

Parameters
`vB` `Vector`: The Vector to dot with.

Returns
`float` The result of the dot product.

### equals

`boolean equals (Object object)`

Parameters
`object` `Object`

Returns
`boolean`

### hashCode

`int hashCode ()`

Returns
`int`

### interpolate

```Vector interpolate (Vector other,
float t)```

Interpolate between this Vector and the given Vector by the given value (between 0 and 1), and return the result (neither this Vector nor the input Vector are mutated).

Parameters
`other` `Vector`: The Vector to interpolate between.

`t` `float`: The interpolation amount (where 0 is this Vector and 1 is the input Vector).

Returns
`Vector` The interpolated Vector.

### magnitude

`float magnitude ()`

Return the magnitude of this Vector.

Returns
`float` The magnitude.

### midpoint

`Vector midpoint (Vector other)`

Return the midpoint between this Vector and the given Vector.

Parameters
`other` `Vector`: The Vector we return the midpoint from.

Returns
`Vector` The midpoint between the two Vectors.

### normalize

`Vector normalize ()`

Normalize this vector and return the result (this Vector is not mutated).

Returns
`Vector` The normalized Vector.

### rayIntersectPlane

```boolean rayIntersectPlane (Vector point,
Vector normal,
Vector origin,
Vector intPt)```

Determine if the ray defined by the given origin, in the direction of this Vector, intersects the plane defined by the given point and normal vector.

Parameters
`point` `Vector`: Any point on the plane.

`normal` `Vector`: The normal of the plane.

`origin` `Vector`: The origin of the ray.

`intPt` `Vector`: Store the point of intersection, if any, between the ray and plane here.

Returns
`boolean` True if the ray intersected the plane.

```Vector rotateAboutAxis (Vector axisDir,
Vector axisPos,

Rotate this Vector about the given axis, and return the result (neither this Vector nor the input Vector are mutated).

Parameters
`axisDir` `Vector`: The direction of the axis we are rotating about.

`axisPos` `Vector`: Any point on the axis we are rotating about.

`angleRad` `float`: The amount by which we should rotate, in radians.

Returns
`Vector` The rotated Vector.

### scale

`Vector scale (float factor)`

Scale each component of this Vector by the given amount and return the result (this Vector is not mutated).

Parameters
`factor` `float`: The factor by which to multiply each component of this Vector.

Returns
`Vector` The scaled Vector.

### set

```void set (float x,
float y,
float z)```

Set the X, Y, and X components of this Vector.

Parameters
`x` `float`: The X component.

`y` `float`: The Y component.

`z` `float`: The Z component.

### set

`void set (Vector value)`

Set this Vector to equal the given vector. Each component (x, y, z) will be copied from the given Vector.

Parameters
`value` `Vector`: The Vector whose values we will copy into this Vector.

### subtract

`Vector subtract (Vector vB)`

Subtract the given Vector from this Vector and return the result (neither this Vector nor the input Vector are mutated).

Parameters
`vB` `Vector`: The Vector to subtract from this one.

Returns
`Vector` The result.

### toArray

`float[] toArray ()`

Get the contents of the Vector in an array.

Returns
`float[]` Float array of length three with components [x, y, z].

### toString

`String toString ()`

Returns
`String`