GODPAPER | All Packages | All Classes | Index | Frames No Frames |
Vector2D

Package | com.lookbackon.AI.steeringBehavior
Class | public class Vector2D
Inheritance | Vector2D Object

A basic 2-dimensional vector class.

Public Properties

| Property | Defined By
--- | --- | ---
|  | angle : Number Gets / sets the angle of this vector. | Vector2D
|  | length : Number Sets / gets the length or magnitude of this vector. | Vector2D
|  | lengthSQ : Number [read-only] Gets the length of this vector, squared. | Vector2D
|  | perp : Vector2D [read-only] Finds a vector that is perpendicular to this vector. | Vector2D
|  | x : Number Sets / gets the x value of this vector. | Vector2D
|  | y : Number Sets / gets the y value of this vector. | Vector2D

Public Methods

| Method | Defined By
--- | --- | ---
|  | Vector2D(x:Number = 0, y:Number = 0) Constructor. | Vector2D
|  | add(v2:Vector2D):Vector2D Adds a vector to this vector, creating a new Vector2D instance to hold the result. | Vector2D
|  | angleBetween(v1:Vector2D, v2:Vector2D):Number [static] Calculates the angle between two vectors. | Vector2D
|  | clone():Vector2D Generates a copy of this vector. | Vector2D
|  | crossProd(v2:Vector2D):Number Calculates the cross product of this vector and another given vector. | Vector2D
|  | dist(v2:Vector2D):Number Calculates the distance from this vector to another given vector. | Vector2D
|  | distSQ(v2:Vector2D):Number Calculates the distance squared from this vector to another given vector. | Vector2D
|  | divide(value:Number):Vector2D Divides this vector by a value, creating a new Vector2D instance to hold the result. | Vector2D
|  | dotProd(v2:Vector2D):Number Calculates the dot product of this vector and another given vector. | Vector2D
|  | draw(graphics:Graphics, color:uint = 0):void Can be used to visualize the vector. | Vector2D
|  | equals(v2:Vector2D):Boolean Indicates whether this vector and another Vector2D instance are equal in value. | Vector2D
|  | isNormalized():Boolean Whether or not this vector is normalized, i.e. | Vector2D
|  | isZero():Boolean Whether or not this vector is equal to zero, i.e. | Vector2D
|  | multiply(value:Number):Vector2D Multiplies this vector by a value, creating a new Vector2D instance to hold the result. | Vector2D
|  | normalize():Vector2D Normalizes this vector. | Vector2D
|  | reverse():Vector2D Reverses the direction of this vector. | Vector2D
|  | sign(v2:Vector2D):int Determines if a given vector is to the right or left of this vector. | Vector2D
|  | subtract(v2:Vector2D):Vector2D Subtacts a vector to this vector, creating a new Vector2D instance to hold the result. | Vector2D
|  | toString():String Generates a string representation of this vector. | Vector2D
|  | truncate(max:Number):Vector2D Ensures the length of the vector is no longer than the given value. | Vector2D
|  | zero():Vector2D Sets this vector's x and y values, and thus length, to zero. | Vector2D

Property Detail

angle | property

`angle:Number`

Gets / sets the angle of this vector. Changing the angle changes the x and y but retains the same length.

Implementation
`public function get angle():Number`
`public function set angle(value:Number):void`

length | property |

`length:Number`

Sets / gets the length or magnitude of this vector. Changing the length will change the x and y but not the angle of this vector.

Implementation
`public function get length():Number`
`public function set length(value:Number):void`

lengthSQ | property |

`lengthSQ:Number` [read-only]

Gets the length of this vector, squared.

Implementation
`public function get lengthSQ():Number`

perp | property |

`perp:Vector2D` [read-only]

Finds a vector that is perpendicular to this vector.

Implementation
`public function get perp():Vector2D`

x | property |

`x:Number`

Sets / gets the x value of this vector.

Implementation
`public function get x():Number`
`public function set x(value:Number):void`

y | property |

`y:Number`

Sets / gets the y value of this vector.

Implementation
`public function get y():Number`
`public function set y(value:Number):void`
Constructor Detail

Vector2D | () | Constructor

`public function Vector2D(x:Number = 0, y:Number = 0)`

Constructor.

Parameters

| `x:Number` (default = `0`)``
| `y:Number` (default = `0`)``

Method Detail

add | () | method

`public function add(v2:Vector2D):Vector2D`

Adds a vector to this vector, creating a new Vector2D instance to hold the result.

Parameters

| `v2:Vector2D` — A Vector2D instance.

Returns

| `Vector2D` — Vector2D A new vector containing the results of the addition.

angleBetween | () | method |

`public static function angleBetween(v1:Vector2D, v2:Vector2D):Number`

Calculates the angle between two vectors.

Parameters

| `v1:Vector2D` — The first Vector2D instance.
| `v2:Vector2D` — The second Vector2D instance.

Returns

| `Number` — Number the angle between the two given vectors.

clone | () | method |

`public function clone():Vector2D`

Generates a copy of this vector.

Returns

| `Vector2D` — Vector2D A copy of this vector.

crossProd | () | method |

`public function crossProd(v2:Vector2D):Number`

Calculates the cross product of this vector and another given vector.

Parameters

| `v2:Vector2D` — Another Vector2D instance.

Returns

| `Number` — Number The cross product of this vector and the one passed in as a parameter.

dist | () | method |

`public function dist(v2:Vector2D):Number`

Calculates the distance from this vector to another given vector.

Parameters

| `v2:Vector2D` — A Vector2D instance.

Returns

| `Number` — Number The distance from this vector to the vector passed as a parameter.

distSQ | () | method |

`public function distSQ(v2:Vector2D):Number`

Calculates the distance squared from this vector to another given vector.

Parameters

| `v2:Vector2D` — A Vector2D instance.

Returns

| `Number` — Number The distance squared from this vector to the vector passed as a parameter.

divide | () | method |

`public function divide(value:Number):Vector2D`

Divides this vector by a value, creating a new Vector2D instance to hold the result.

Parameters

| `value:Number` — A Vector2D instance.

Returns

| `Vector2D` — Vector2D A new vector containing the results of the division.

dotProd | () | method |

`public function dotProd(v2:Vector2D):Number`

Calculates the dot product of this vector and another given vector.

Parameters

| `v2:Vector2D` — Another Vector2D instance.

Returns

| `Number` — Number The dot product of this vector and the one passed in as a parameter.

draw | () | method |

`public function draw(graphics:Graphics, color:uint = 0):void`

Can be used to visualize the vector. Generally used for debug purposes only.

Parameters

| `graphics:Graphics` — The Graphics instance to draw the vector on.
| `color:uint` (default = `0`)`` — The color of the line used to represent the vector.

equals | () | method |

`public function equals(v2:Vector2D):Boolean`

Indicates whether this vector and another Vector2D instance are equal in value.

Parameters

| `v2:Vector2D` — A Vector2D instance.

Returns

| `Boolean` — Boolean True if the other vector is equal to this one, false if not.

isNormalized | () | method |

`public function isNormalized():Boolean`

Whether or not this vector is normalized, i.e. its length is equal to one.

Returns

| `Boolean` — Boolean True if length is one, otherwise false.

isZero | () | method |

`public function isZero():Boolean`

Whether or not this vector is equal to zero, i.e. its x, y, and length are zero.

Returns

| `Boolean` — Boolean True if vector is zero, otherwise false.

multiply | () | method |

`public function multiply(value:Number):Vector2D`

Multiplies this vector by a value, creating a new Vector2D instance to hold the result.

Parameters

| `value:Number` — A Vector2D instance.

Returns

| `Vector2D` — Vector2D A new vector containing the results of the multiplication.

normalize | () | method |

`public function normalize():Vector2D`

Normalizes this vector. Equivalent to setting the length to one, but more efficient.

Returns

| `Vector2D` — Vector2D A reference to this vector.

reverse | () | method |

`public function reverse():Vector2D`

Reverses the direction of this vector.

Returns

| `Vector2D` — Vector2D A reference to this vector.

sign | () | method |

`public function sign(v2:Vector2D):int`

Determines if a given vector is to the right or left of this vector.

Parameters

| `v2:Vector2D`

Returns

| `int` — int If to the left, returns -1. If to the right, +1.

subtract | () | method |

`public function subtract(v2:Vector2D):Vector2D`

Subtacts a vector to this vector, creating a new Vector2D instance to hold the result.

Parameters

| `v2:Vector2D` — A Vector2D instance.

Returns

| `Vector2D` — Vector2D A new vector containing the results of the subtraction.

toString | () | method |

`public function toString():String`

Generates a string representation of this vector.

Returns

| `String` — String A description of this vector.

truncate | () | method |

`public function truncate(max:Number):Vector2D`

Ensures the length of the vector is no longer than the given value.

Parameters

| `max:Number` — The maximum value this vector should be. If length is larger than max, it will be truncated to this value.

Returns

| `Vector2D` — Vector2D A reference to this vector.

zero | () | method |

`public function zero():Vector2D`

Sets this vector's x and y values, and thus length, to zero.

Returns

| `Vector2D` — Vector2D A reference to this vector.

Thu Jan 16 2014, 01:11 PM +08:00