Packagecom.threerings.geom
Classpublic class Vector2

Basic 2D vector implementation.



Public Properties
 PropertyDefined by
  angle : Number
[read-only] Returns the angle represented by this Vector2, in radians.
Vector2
  length : Number
Returns this vector's length.
Vector2
  lengthSquared : Number
[read-only] Returns the square of this vector's length.
Vector2
  x : Number = 0
Vector2
  y : Number = 0
Vector2
Public Methods
 MethodDefined by
  
Vector2(x:Number = 0, y:Number = 0)
Constructs a Vector2 from the given values.
Vector2
  
Returns a copy of this vector added to 'v'.
Vector2
  
Adds another Vector2 to this, in place.
Vector2
  
Returns a copy of this Vector2.
Vector2
  
dot(v:Vector2):Number
Returns the dot product of this vector with vector v.
Vector2
  
equals(v:Object):Boolean
Returns true if this vector is equal to v.
Vector2
  
fromAngle(radians:Number, len:Number = 1):Vector2
[static] Creates a Vector2 of magnitude 'len' that has been rotated about the origin by 'radians'.
Vector2
  
fromPoint(p:Point):Vector2
[static] Converts Point p to a Vector2.
Vector2
  
fromPoints(s:Point, t:Point):Vector2
[static] Creates a new Vector2 pointing from s to t.
Vector2
  
getPerp(ccw:Boolean = true):Vector2
Returns a vector that is perpendicular to this one.
Vector2
  
[static] Returns a new vector that is the linear interpolation of vectors a and b at proportion p, where p is in [0, 1], p = 0 means the result is equal to a, and p = 1 means the result is equal to b.
Vector2
  
Returns a copy of the vector, inverted.
Vector2
  
Inverts the vector.
Vector2
  
Returns a normalized copy of the vector.
Vector2
  
Normalizes this vector in place.
Vector2
  
Normalizes the vector in place and returns its original length.
Vector2
  
rotate(radians:Number):Vector2
Returns a rotated copy of this vector.
Vector2
  
rotateLocal(radians:Number):Vector2
Rotates the vector in place by 'radians'.
Vector2
  
scale(value:Number):Vector2
Returns (this value).
Vector2
  
scaleLocal(value:Number):Vector2
Scales this vector by value.
Vector2
  
set(x:Number, y:Number):void
Sets the vector's components to the given values.
Vector2
  
similar(v:Vector2, epsilon:Number):Boolean
Returns true if the components of v are equal to the components of this Vector2, within the given epsilon.
Vector2
  
[static] Returns the smaller of the two angles between v1 and v2, in radians.
Vector2
  
Returns (this - v).
Vector2
  
Subtracts another vector from this one, in place.
Vector2
  
toPoint():Point
Converts the Vector2 to a Point.
Vector2
  
toString():String
Returns a string representation of the Vector2.
Vector2
Public Constants
 ConstantDefined by
  INFINITE : Vector2
[static] Infinite vector - often the result of normalizing a zero vector.
Vector2
Property detail
angleproperty
angle:Number  [read-only]

Returns the angle represented by this Vector2, in radians.

Implementation
    public function get angle():Number
lengthproperty 
length:Number  [read-write]

Returns this vector's length.

Implementation
    public function get length():Number
    public function set length(value:Number):void
lengthSquaredproperty 
lengthSquared:Number  [read-only]

Returns the square of this vector's length.

Implementation
    public function get lengthSquared():Number
xproperty 
public var x:Number = 0
yproperty 
public var y:Number = 0
Constructor detail
Vector2()constructor
public function Vector2(x:Number = 0, y:Number = 0)

Constructs a Vector2 from the given values.

Parameters
x:Number (default = 0)
 
y:Number (default = 0)
Method detail
add()method
public function add(v:Vector2):Vector2

Returns a copy of this vector added to 'v'.

Parameters
v:Vector2

Returns
Vector2
addLocal()method 
public function addLocal(v:Vector2):Vector2

Adds another Vector2 to this, in place. Returns a reference to 'this', for chaining.

Parameters
v:Vector2

Returns
Vector2
clone()method 
public function clone():Vector2

Returns a copy of this Vector2.

Returns
Vector2
dot()method 
public function dot(v:Vector2):Number

Returns the dot product of this vector with vector v.

Parameters
v:Vector2

Returns
Number
equals()method 
public function equals(v:Object):Boolean

Returns true if this vector is equal to v.

Parameters
v:Object

Returns
Boolean
fromAngle()method 
public static function fromAngle(radians:Number, len:Number = 1):Vector2

Creates a Vector2 of magnitude 'len' that has been rotated about the origin by 'radians'.

Parameters
radians:Number
 
len:Number (default = 1)

Returns
Vector2
fromPoint()method 
public static function fromPoint(p:Point):Vector2

Converts Point p to a Vector2.

Parameters
p:Point

Returns
Vector2
fromPoints()method 
public static function fromPoints(s:Point, t:Point):Vector2

Creates a new Vector2 pointing from s to t.

Parameters
s:Point
 
t:Point

Returns
Vector2
getPerp()method 
public function getPerp(ccw:Boolean = true):Vector2

Returns a vector that is perpendicular to this one. If ccw = true, the perpendicular vector is rotated 90 degrees counter-clockwise from this vector, otherwise it's rotated 90 degrees clockwise.

Parameters
ccw:Boolean (default = true)

Returns
Vector2
interpolate()method 
public static function interpolate(a:Vector2, b:Vector2, p:Number):Vector2

Returns a new vector that is the linear interpolation of vectors a and b at proportion p, where p is in [0, 1], p = 0 means the result is equal to a, and p = 1 means the result is equal to b.

Parameters
a:Vector2
 
b:Vector2
 
p:Number

Returns
Vector2
invert()method 
public function invert():Vector2

Returns a copy of the vector, inverted.

Returns
Vector2
invertLocal()method 
public function invertLocal():Vector2

Inverts the vector.

Returns
Vector2
normalize()method 
public function normalize():Vector2

Returns a normalized copy of the vector.

Returns
Vector2
normalizeLocal()method 
public function normalizeLocal():Vector2

Normalizes this vector in place. Returns a reference to 'this', for chaining.

Returns
Vector2
normalizeLocalAndGetLength()method 
public function normalizeLocalAndGetLength():Number

Normalizes the vector in place and returns its original length.

Returns
Number
rotate()method 
public function rotate(radians:Number):Vector2

Returns a rotated copy of this vector.

Parameters
radians:Number

Returns
Vector2
rotateLocal()method 
public function rotateLocal(radians:Number):Vector2

Rotates the vector in place by 'radians'. Returns a reference to 'this', for chaining.

Parameters
radians:Number

Returns
Vector2
scale()method 
public function scale(value:Number):Vector2

Returns (this value).

Parameters
value:Number

Returns
Vector2
scaleLocal()method 
public function scaleLocal(value:Number):Vector2

Scales this vector by value.

Parameters
value:Number

Returns
Vector2
set()method 
public function set(x:Number, y:Number):void

Sets the vector's components to the given values.

Parameters
x:Number
 
y:Number
similar()method 
public function similar(v:Vector2, epsilon:Number):Boolean

Returns true if the components of v are equal to the components of this Vector2, within the given epsilon.

Parameters
v:Vector2
 
epsilon:Number

Returns
Boolean
smallerAngleBetween()method 
public static function smallerAngleBetween(v1:Vector2, v2:Vector2):Number

Returns the smaller of the two angles between v1 and v2, in radians. Result will be in range [0, pi].

Parameters
v1:Vector2
 
v2:Vector2

Returns
Number
subtract()method 
public function subtract(v:Vector2):Vector2

Returns (this - v).

Parameters
v:Vector2

Returns
Vector2
subtractLocal()method 
public function subtractLocal(v:Vector2):Vector2

Subtracts another vector from this one, in place. Returns a reference to 'this', for chaining.

Parameters
v:Vector2

Returns
Vector2
toPoint()method 
public function toPoint():Point

Converts the Vector2 to a Point.

Returns
Point
toString()method 
public function toString():String

Returns a string representation of the Vector2.

Returns
String
Constant detail
INFINITEconstant
public static const INFINITE:Vector2

Infinite vector - often the result of normalizing a zero vector.