| Package | graphics.geom |
| Class | public class Vector2 |
| Inheritance | Vector2 flash.geom.Point |
| Implements | Serializable |
| Property | Defined By | ||
|---|---|---|---|
| angle : Number
Indicates the angle value of the specified Vector2 object. | Vector2 | ||
| degrees : Boolean
Indicates if all calcul in this methods use angles in degrees or radians. | Vector2 | ||
| ZERO : Vector2 [static]
Defines the Vector2 object with the x and y properties set to zero. | Vector2 | ||
| Method | Defined By | ||
|---|---|---|---|
Vector2(x:Number = 0, y:Number = 0, degrees:Boolean = false)
Creates a new Vector2 instance. | Vector2 | ||
abs():void
Transforms the coordinates of the vector to used absolute value for the x and y properties. | Vector2 | ||
[static]
Returns a new Vector2 reference with the absolute value of the coordinates of the specified Vector2 object. | Vector2 | ||
[static]
Computes the addition of two Vector2. | Vector2 | ||
angleBetween(vector:Vector2):Number
Returns the angle value between this Vector2 object and the specified Vector2 passed in arguments. | Vector2 | ||
clone():Point [override]
Returns a shallow copy of this instance. | Vector2 | ||
Returns the cross value of the two Vector2. | Vector2 | ||
Returns the direction of this Vector2 object. | Vector2 | ||
[static]
Returns the distance between the 2 vectors. | Vector2 | ||
Returns the dot value of the passed-in Vector2 with the current Vector2 object. | Vector2 | ||
equals(toCompare:Point):Boolean [override]
Compares the specified object with this object for equality. | Vector2 | ||
interpolate(vector:Point, level:Number):Vector2
Determines a point between two specified points. | Vector2 | ||
invert():void
Invert the current Vector2 object. | Vector2 | ||
isPerpendicularTo(vector:Vector2):Boolean
Returns true if the Vector2 is perpendicular with the passed-in Vector2. | Vector2 | ||
Returns the new Vector2 with the maximum horizontal coordinate and the maximum vertical coordinate. | Vector2 | ||
Returns the middle Vector2 object between 2 Points. | Vector2 | ||
Returns a new Vector2 with the minimum horizontal coordinate and the minimize vertical coordinate. | Vector2 | ||
negate():void
Sets this Vector2 with negate coordinates. | Vector2 | ||
[static]
Returns the new negate Vector2 of the specified Vector2 objet. | Vector2 | ||
Returns the normal value of this Vector2. | Vector2 | ||
[static]
Converts a pair of polar coordinates to a Cartesian point coordinate. | Vector2 | ||
pow(value:Number):void
Computes the power of the vector. | Vector2 | ||
[static]
Computes the power of the specified Vector2. | Vector2 | ||
Returns the projection of a Vector2 with the specified Vector2 passed in argument. | Vector2 | ||
projectionLength(v:Vector2):Number
Returns the size of the projection of this Point with an other Point. | Vector2 | ||
Reflects the current Vector2 object with the passed-in normal Vector2 argument. | Vector2 | ||
[static]
Creates a new Vector2 object, the reflect of the specific vector. | Vector2 | ||
rotate(angle:Number):void
Rotates the Vector2 object with the specified angle passed-in argument. | Vector2 | ||
[static]
Rotates the Vector2 with the specified angle in argument and creates a new Vector2. | Vector2 | ||
scale(value:Number):void
Scales the vector object with the input value. | Vector2 | ||
[static]
Scales a new Vector2 object with the specified Vector2. | Vector2 | ||
Sets the current Vector2 with the passed-in Vector2 argument. | Vector2 | ||
setByObject(o:Object):void
Sets the current Vector2 object with the passed-in Object argument. | Vector2 | ||
setByPoint(p:Point):void
Sets the current Vector2 object with the passed-in flash.geom.Point argument. | Vector2 | ||
[static]
Returns the squared distance between 2 vectors. | Vector2 | ||
Computes the substraction of the current vector object with an other. | Vector2 | ||
[static]
Computes the substraction of two Vector2. | Vector2 | ||
Swap the horizontal and vertical coordinates of two Vector2 objects. | Vector2 | ||
toObject():Object
Returns the Object representation of this object. | Vector2 | ||
toSource(indent:int = 0):String
Returns the source code string representation of the object. | Vector2 | ||
toString():String [override]
Returns the string representation of the object. | Vector2 | ||
| Constant | Defined By | ||
|---|---|---|---|
| DOWN : Vector2 [static]
Indicates the relative "down" direction. | Vector2 | ||
| LEFT : Vector2 [static]
Indicates the relative "left" direction. | Vector2 | ||
| RIGHT : Vector2 [static]
Indicates the relative "right" direction. | Vector2 | ||
| UP : Vector2 [static]
Indicates the relative "up" direction. | Vector2 | ||
| angle | property |
angle:NumberIndicates the angle value of the specified Vector2 object.
public function get angle():Number public function set angle(value:Number):voidSee also
| degrees | property |
public var degrees:BooleanIndicates if all calcul in this methods use angles in degrees or radians.
| ZERO | property |
public static var ZERO:Vector2Defines the Vector2 object with the x and y properties set to zero.
| Vector2 | () | Constructor |
public function Vector2(x:Number = 0, y:Number = 0, degrees:Boolean = false)
Creates a new Vector2 instance.
x:Number (default = 0) — the x coordinate.
| |
y:Number (default = 0) — the y coordinate.
| |
degrees:Boolean (default = false) — Optional flag who indicates if all methods use angles in degrees or radians.
|
| abs | () | method |
public function abs():voidTransforms the coordinates of the vector to used absolute value for the x and y properties.
Example :
import graphics.geom.Vector2 ;
var v:Vector2 = new Vector2(-10, -20) ;
v.abs() ;
trace( v ) ; // [Vector2 x:10 y:20]
| abs | () | method |
public static function abs(vector:Vector2):Vector2Returns a new Vector2 reference with the absolute value of the coordinates of the specified Vector2 object.
Example :
import graphics.geom.Vector2 ;
var v1:Vector2 = new Vector2(-10, -20) ;
var v2:Vector2 = Vector2.abs( v1 ) ;
trace( v1 + " / " + v2 ) ; // [Vector2 x:-10 y:-20] / [Vector2 x:10 y:20]
Parameters
vector:Vector2 — The vector reference to create the new absolute Vector2 object.
|
Vector2 — a new Vector2 reference with the absolute value of the coordinates of the passed-in Vector2 object.
|
| add | () | method |
public static function add(v1:Point, v2:Point):Vector2Computes the addition of two Vector2.
Parameters
v1:Point — a Vector2 to concat.
| |
v2:Point — a Vector2 to concat.
|
Vector2 — the addition result of two Vector2.
|
| angleBetween | () | method |
public function angleBetween(vector:Vector2):NumberReturns the angle value between this Vector2 object and the specified Vector2 passed in arguments.
Example :
import graphics.geom.Vector2 ;
var angle:Number ;
var v1:Vector2 = new Vector2(10, 20) ;
var v2:Vector2 = new Vector2(50, 200) ;
v1.degrees = false ;
angle = v1.angleBetween(v2) ;
trace( angle ) ;
v1.degrees = true ;
angle = v1.angleBetween(v2) ;
trace( angle ) ;
Parameters
vector:Vector2 |
Number — the angle value between this Point object and the specified Point passed in arguments.
|
| clone | () | method |
override public function clone():PointReturns a shallow copy of this instance.
ReturnsPoint — a shallow copy of this instance.
|
| cross | () | method |
public function cross(vector:Vector2):NumberReturns the cross value of the two Vector2.
import graphics.geom.Vector2 ;
var v1:Vector2 = new Vector2( 10 , 20 ) ;
var v2:Vector2 = new Vector2( 40 , 60 ) ;
trace( v1.cross( v2 ) ) ; // -200
Parameters
vector:Vector2 — The Vector2 object use to calculate the cross value.
|
Number — The cross value of the current Vector2 object with the Vector2 passed in argument.
|
| direction | () | method |
public function direction():Vector2Returns the direction of this Vector2 object.
Example :
import graphics.geom.Vector2 ;
var v1 : Vector2 = new Point(10,2);
var v2 : Vector2 = p1.direction();
trace( v2 ) ;
ReturnsVector2 — the direction of this Point.
|
See also
| distance | () | method |
public static function distance(v1:Vector2, v2:Vector2):NumberReturns the distance between the 2 vectors.
Parameters
v1:Vector2 — the first vector.
| |
v2:Vector2 — the second vector.
|
Number — the distance between the 2 vectors.
|
| dot | () | method |
public function dot(vector:Vector2):NumberReturns the dot value of the passed-in Vector2 with the current Vector2 object.
Example :
import graphics.geom.Vector2 ;
var v1:Vector2 = new Vector2(10,20) ;
var v2:Vector2 = new Vector2(40,60) ;
trace( v1.dot( v2 ) ) ; // 1600
Parameters
vector:Vector2 — the Vector2 object to calculate the dot value.
|
Number — the dot value.
|
| equals | () | method |
override public function equals(toCompare:Point):BooleanCompares the specified object with this object for equality.
Parameters
toCompare:Point |
Boolean — true if the the specified object is equal with this object.
|
| interpolate | () | method |
public function interpolate(vector:Point, level:Number):Vector2Determines a point between two specified points. The parameter 'level' determines where the new interpolated point is located relative to the two end points. The closer the value of the parameter level is to 1.0, the closer the interpolated point is to the first vector (current Vector2). The closer the value of the parameter level is to 0, the closer the interpolated point is to the second vector (parameter vector).
Example :
import graphics.geom.Vector2 ;
var v1:Vector2 = new Vector2(10,10) ;
var v2:Vector2 = new Vector2(40,40) ;
var v3:Vector2 ;
v3 = v1.interpolate( v2 , 0 ) ;
trace(v3) ; // [Vector2 x:40 y:40]
v3 = v1.interpolate( v2 , 1 ) ;
trace(v3) ; // [Vector2 x:10 y:10]
v3 = v1.interpolate( v2 , 0.5 ) ;
trace(v3) ; // [Vector2 x:25 y:25]
Parameters
vector:Point — The first point.
| |
level:Number — The second Point.
|
Vector2 — The new interpolated Vector2 object.
|
| invert | () | method |
public function invert():voidInvert the current Vector2 object.
Example :
import graphics.geom.Vector2 ;
var vector:Vector2 = new Vector2(10,20) ;
vector.invert() ;
trace( vector ) ;
| isPerpendicularTo | () | method |
public function isPerpendicularTo(vector:Vector2):Boolean
Returns true if the Vector2 is perpendicular with the passed-in Vector2.
Example :
import graphics.geom.Vector2 ;
var v1:Point = new Vector2( 0 , 10 ) ;
var v2:Point = new Vector2( 10 , 10 ) ;
var v3:Point = new Vector2( 10 , 0 ) ;
trace( v1.isPerpendicularTo( v2 ) ) ; // false
trace( v1.isPerpendicularTo( v3 ) ) ; // true
Parameters
vector:Vector2 — the Point use to determinate if this Point object is perpendicular.
|
Boolean — true if the Point is perpendicular with the passed-in Point.
|
| max | () | method |
public function max(vector:Vector2):Vector2Returns the new Vector2 with the maximum horizontal coordinate and the maximum vertical coordinate.
Example :
import graphics.geom.Vector2 ;
var v1:Vector2 = new Vector2(10,100) ;
var v2:Vector2 = new Vector2(100,10) ;
var v3:Vector2 = v1.max( v2 ) ;
trace( v3 ) ; // [Vector2 x:100 y:100]
Parameters
vector:Vector2 — The Vector2 passed in this method
|
Vector2 — The new Vector2 with the maximum horizontal coordinate and the maximum vertical coordinate.
|
| middle | () | method |
public function middle(vector:Vector2):Vector2Returns the middle Vector2 object between 2 Points.
Example :
import graphics.geom.Vector2 ;
var v1:Vector2 = new Vector2(10,10) ;
var v2:Vector2 = new Vector2(20,20) ;
var middle:Vector2 = v1.middle( v2 ) ;
trace(middle) ;
Parameters
vector:Vector2 |
Vector2 — the middle Point between 2 Points.
|
| min | () | method |
public function min(vector:Vector2):Vector2Returns a new Vector2 with the minimum horizontal coordinate and the minimize vertical coordinate.
Example :
var v1:Vector2 = new Vector2( 10 , 100 ) ;
var v2:Vector2 = new Vector2( 100 , 10 ) ;
var v3:Vector2 = v1.min( v2 ) ;
trace( v3 ) ; // [Vector2 x:10 y:10]
Parameters
vector:Vector2 — The Vector2 passed in this method
|
Vector2 — The new Vector2 with the min horizontal coordinate and the minimize vertical coordinate.
|
| negate | () | method |
public function negate():voidSets this Vector2 with negate coordinates.
Example :
import graphics.geom.Vector2 ;
var v:Vector2 = new Vector2(10,20) ;
trace(v) ; // [Vector2 x:10 y:20]
v.negate() ;
trace(v) ; // [Vector2 x:-10 y:-20]
v.negate() ;
trace(v) ; // [Vector2 x:10 y:20]
| negate | () | method |
public static function negate(vector:Vector2):Vector2Returns the new negate Vector2 of the specified Vector2 objet.
Example :
import graphics.geom.Vector2 ;
var v:Vector2 = new Point(10,20) ;
var n:Vector2 = Vector2.negate( v ) ;
trace(n) ; // [Vector2 x:-10 y:-20]
Parameters
vector:Vector2 |
Vector2 — The new negate Vector2 of the specified Vector2 objet.
|
| normal | () | method |
public function normal():Vector2Returns the normal value of this Vector2.
Example :
import graphics.geom.Vector2 ;
var v:Vector2 = new Vector2( 10 , 10 ) ;
var n:Vector2 = p.normal() ;
trace(n) ; // [Vector2 x:-10 y:10]
ReturnsVector2 — the normal value of this vector.
|
| polar | () | method |
public static function polar(length:Number, angle:Number):Vector2Converts a pair of polar coordinates to a Cartesian point coordinate.
Example :
var polar:Vector2 = Vector2.polar( 5, Math.atan(3/4) ) ;
trace(polar) ; // [Vector2 x:4 y:3]
Parameters
length:Number — The length coordinate of the polar pair.
| |
angle:Number — The angle, in radians, of the polar pair.
|
Vector2 — The new Cartesian vector.
|
| pow | () | method |
public function pow(value:Number):voidComputes the power of the vector.
Parameters
value:Number — the value of the pow..
|
| pow | () | method |
public static function pow(vector:Vector2, value:Number):Vector2Computes the power of the specified Vector2.
Parameters
vector:Vector2 — the Vector2 reference.
| |
value:Number — the value of the pow..
|
Vector2 — A new Vector2 powered by the method.
|
| project | () | method |
public function project(vector:Vector2):Vector2Returns the projection of a Vector2 with the specified Vector2 passed in argument.
Parameters
vector:Vector2 — the Vector2 to project with this current Vector2.
|
Vector2 — the new project Vector2 object.
|
| projectionLength | () | method |
public function projectionLength(v:Vector2):NumberReturns the size of the projection of this Point with an other Point.
Example :
var p1:Point = new Point(10,10) ;
var p2:Point = new Point(100,200) ;
var size:Number = p1.getProjectionLength(p2) ;
trace(size) ; // 0.06
Parameters
v:Vector2 — the Point use to calculate the length of the projection.
|
Number — the size of the projection of this Point with an other Point.
|
| reflect | () | method |
public function reflect(normal:Vector2):voidReflects the current Vector2 object with the passed-in normal Vector2 argument.
Parameters
normal:Vector2 |
| reflect | () | method |
public static function reflect(vector:Vector2, normal:Vector2):Vector2Creates a new Vector2 object, the reflect of the specific vector.
Parameters
vector:Vector2 | |
normal:Vector2 |
Vector2 — A new reflect Vector2.
|
| rotate | () | method |
public function rotate(angle:Number):voidRotates the Vector2 object with the specified angle passed-in argument.
Example :
import graphics.geom.Vector2 ;
import graphics.geom.Vectors2 ;
var v:Vector2 = new Vector2(100,100) ;
Vectors2.rotate(v, Math.PI) ;
trace(v) ;
Parameters
angle:Number — the Angle to rotate the specified Vector2 object (in degrees if the "degrees" property is true else in radians).
|
See also
| rotate | () | method |
public static function rotate(vector:Vector2, angle:Number):Vector2
Rotates the Vector2 with the specified angle in argument and creates a new Vector2.
Parameters
vector:Vector2 — the Angle to rotate this Vector2.
| |
angle:Number |
Vector2 — The rotate new Vector2.
|
| scale | () | method |
public function scale(value:Number):voidScales the vector object with the input value.
Parameters
value:Number — a real number to scale the current vector object.
|
| scale | () | method |
public static function scale(v:Vector2, value:Number):Vector2Scales a new Vector2 object with the specified Vector2.
Parameters
v:Vector2 — the Vector2 reference to transform.
| |
value:Number — a real number to scale the current Vector2.
|
Vector2 — A new Vector2 scaled by the value passed in in this method.
|
| set | () | method |
public function set(vector:Vector2):voidSets the current Vector2 with the passed-in Vector2 argument.
import graphics.geom.Vector2 ;
var v1:Vector2 = new Vector2( 10 , 20 ) ;
var v2:Vector2 = new Vector2( 40 , 60 ) ;
v1.set( v2 ) ;
trace( v1 ) ;
Parameters
vector:Vector2 — The Vector2 object use to calculate the cross value.
|
| setByObject | () | method |
public function setByObject(o:Object):voidSets the current Vector2 object with the passed-in Object argument.
Parameters
o:Object — The Object to set the vector with this x and y properties.
|
| setByPoint | () | method |
public function setByPoint(p:Point):voidSets the current Vector2 object with the passed-in flash.geom.Point argument.
Parameters
p:Point — The Point to set the vector.
|
| squaredDistance | () | method |
public static function squaredDistance(v1:Vector2, v2:Vector2):NumberReturns the squared distance between 2 vectors.
Parameters
v1:Vector2 — the first vector.
| |
v2:Vector2 — the second vector.
|
Number — the squared distance between 2 vectors.
|
| substract | () | method |
public function substract(v:Vector2):voidComputes the substraction of the current vector object with an other.
Parameters
v:Vector2 — the vector to substract.
|
| substract | () | method |
public static function substract(v1:Vector2, v2:Vector2):Vector2Computes the substraction of two Vector2.
Parameters
v1:Vector2 — a Vector2 to substract.
| |
v2:Vector2 — a Vector2.
|
Vector2 — the substraction result of two Vector2.
|
| swap | () | method |
public function swap(vector:Vector2):voidSwap the horizontal and vertical coordinates of two Vector2 objects.
Example :
import graphics.geom.Vector2 ;
var v1:Vector2 = new Vector2( 10 , 20 ) ;
var v2:Vector2 = new Vector2( 30 , 40 ) ;
trace( v1 + " / " + v2 ) ; // [Vector2 x:10 y:20] / [Vector2 x:30 y:40]
v1.swap( v2 ) ;
trace( v1 + " / " + v2 ) ; // [Vector2 x:30 y:40] / [Vector2 x:10 y:20]
Parameters
vector:Vector2 |
| toObject | () | method |
public function toObject():ObjectReturns the Object representation of this object.
ReturnsObject — the Object representation of this object.
|
| toSource | () | method |
public function toSource(indent:int = 0):StringReturns the source code string representation of the object.
Parameters
indent:int (default = 0) |
String — the source code string representation of the object.
|
| toString | () | method |
override public function toString():StringReturns the string representation of the object.
ReturnsString — the string representation of the object.
|
| DOWN | Constant |
public static const DOWN:Vector2Indicates the relative "down" direction.
| LEFT | Constant |
public static const LEFT:Vector2Indicates the relative "left" direction.
| RIGHT | Constant |
public static const RIGHT:Vector2Indicates the relative "right" direction.
| UP | Constant |
public static const UP:Vector2Indicates the relative "up" direction.