Packagecom.fileitup.fisixengine.core
Classpublic class Vector

A class which serves as the base for many of the engine's calculations.

In it's core, a Vector is simply used to store two values: x and y.
But the Vector class also supplies many methods for vector operations as well as static helper methods



Public Properties
 PropertyDefined by
  x : Number
Vector
  y : Number
Vector
Public Methods
 MethodDefined by
  
Vector(cX:Number, cY:Number)
Vector
  
Vector addition.
Vector
  
angleTo(v:Vector):Number
Calculates the angle between this vector to another
Vector
  
Returns a copy of the vector.
Vector
  
Calculates the distance squared between this vector to another
Vector
  
distanceTo(v:Vector):Number
Calculates the distance between this vector to another
Vector
  
divide(n:Number):Vector
Divides both the x and y values by the given number.
Vector
  
dot(v:Vector):Number
Dot product.
Vector
  
getAngle():Number
The angle of the vector in degrees.
Vector
  
getMagnitude():Number
Returns the magnitude, or length, of the vector.
Vector
  
Returns the magnitude, or length, of the vector multiplied by itself.
Vector
  
getNormal(cD:Number = 1):Vector
Returns the vector's right-hand normal
Vector
  
minus(n:Number):Vector
Subtracts a scalar from both the x and y components.
Vector
  
normalize(len:Number = 1):Vector
Normalizes the vector to unit length.
Vector
  
perp(v:Vector):Number
Perpendicular product.
Vector
  
plus(n:Number):Vector
Adds a scalar to both the x and y components
Vector
  
renderFrom(rX:Number, rY:Number, g:Graphics, col:uint = 0x660066):void
Render the vector from the given position
Vector
  
Reverses the vector's direction.
Vector
  
rotate(ang:Number):Vector
Rotates the vector by the given degree.
Vector
  
setAngle(ang:Number):void
Used to set the angle of the vector (in degrees).
Vector
  
setPos(pX:Number, pY:Number):Vector
Quickly set the x and y values of the vector
Vector
  
Vector subtraction.
Vector
  
times(n:Number):Vector
Multiplies both the x and y values by the given number.
Vector
  
toAngle(dx:Number, dy:Number):Number
[static]Returns a degree angle given its x and y components
Vector
  
toString():String
Vector
  
[static]Returns a vector starting at v1 and pointing to v2
Vector
  
vectorFromAngle(angle:Number, scale:Number = 1):Vector
[static]Creates a vector given the angle and length
Vector
  
Returns a vector starting at this vector and pointing to the given vector.
Vector
Property detail
xproperty
public var x:Number
yproperty 
public var y:Number
Constructor detail
Vector()constructor
public function Vector(cX:Number, cY:Number)Parameters
cX:Number
 
cY:Number
Method detail
add()method
public function add(v:Vector):Vector

Vector addition.

Parameters
v:Vector — The vector who's x and y values will be added to this vector's x and y values.

Returns
Vector
angleTo()method 
public function angleTo(v:Vector):Number

Calculates the angle between this vector to another

Parameters
v:Vector

Returns
Number
clone()method 
public function clone():Vector

Returns a copy of the vector. This is very usefull when you don't want to change the current vector, and can be used in combination with any other operation like normalize(), add(), or multiply().

Returns
Vector
distanceSquaredTo()method 
public function distanceSquaredTo(v:Vector):Number

Calculates the distance squared between this vector to another

Parameters
v:Vector

Returns
Number
distanceTo()method 
public function distanceTo(v:Vector):Number

Calculates the distance between this vector to another

Parameters
v:Vector

Returns
Number
divide()method 
public function divide(n:Number):Vector

Divides both the x and y values by the given number. Division by 0 is ignored. This is usefull for scaling the vector without altering it's direction.

Parameters
n:Number

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

Dot product.

Parameters
v:Vector

Returns
Number
getAngle()method 
public function getAngle():Number

The angle of the vector in degrees.

Returns
Number
getMagnitude()method 
public function getMagnitude():Number

Returns the magnitude, or length, of the vector.

Returns
Number
getMagnitudeSquared()method 
public function getMagnitudeSquared():Number

Returns the magnitude, or length, of the vector multiplied by itself. This is more efficient than getMagnitude, as no sqrt() operation is needed, and should be used in cases where the magnitude squared is needed.

Returns
Number
getNormal()method 
public function getNormal(cD:Number = 1):Vector

Returns the vector's right-hand normal

Parameters
cD:Number (default = 1)

Returns
Vector
minus()method 
public function minus(n:Number):Vector

Subtracts a scalar from both the x and y components.

Parameters
n:Number

Returns
Vector
normalize()method 
public function normalize(len:Number = 1):Vector

Normalizes the vector to unit length. In other words, it modifies the vector's x and y values so that the vector's magnitude is one but it's angle is unchanged.

Parameters
len:Number (default = 1) — specify this value if you would like the vector's magnitude to be a value other than one. A negative value would simply reverse the vector.

Returns
Vector
perp()method 
public function perp(v:Vector):Number

Perpendicular product. This is the same as using dot() with v's normal

Parameters
v:Vector

Returns
Number
plus()method 
public function plus(n:Number):Vector

Adds a scalar to both the x and y components

Parameters
n:Number

Returns
Vector
renderFrom()method 
public function renderFrom(rX:Number, rY:Number, g:Graphics, col:uint = 0x660066):void

Render the vector from the given position

Parameters
rX:Number — Global x starting position.
 
rY:Number — Global y starting position.
 
g:Graphics — A Graphics object to render to.
 
col:uint (default = 0x660066)
reverse()method 
public function reverse():Vector

Reverses the vector's direction. This is the same as multiplying by -1

Returns
Vector
rotate()method 
public function rotate(ang:Number):Vector

Rotates the vector by the given degree.

Parameters
ang:Number

Returns
Vector
setAngle()method 
public function setAngle(ang:Number):void

Used to set the angle of the vector (in degrees).

Parameters
ang:Number
setPos()method 
public function setPos(pX:Number, pY:Number):Vector

Quickly set the x and y values of the vector

Parameters
pX:Number
 
pY:Number

Returns
Vector
subtract()method 
public function subtract(v:Vector):Vector

Vector subtraction.

Parameters
v:Vector

Returns
Vector

See also

times()method 
public function times(n:Number):Vector

Multiplies both the x and y values by the given number. This is usefull for scaling the vector without altering it's direction.

Parameters
n:Number

Returns
Vector
toAngle()method 
public static function toAngle(dx:Number, dy:Number):Number

Returns a degree angle given its x and y components

Parameters
dx:Number
 
dy:Number

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

Returns
String
vectorBetween()method 
public static function vectorBetween(v1:Vector, v2:Vector):Vector

Returns a vector starting at v1 and pointing to v2

Parameters
v1:Vector
 
v2:Vector

Returns
Vector
vectorFromAngle()method 
public static function vectorFromAngle(angle:Number, scale:Number = 1):Vector

Creates a vector given the angle and length

Parameters
angle:Number — The angle of the desired vector in degrees.
 
scale:Number (default = 1) — the magnitude of the desired vector.

Returns
Vector
vectorTo()method 
public function vectorTo(v:Vector):Vector

Returns a vector starting at this vector and pointing to the given vector.

Parameters
v:Vector

Returns
Vector