Packagegraphics.geom
Classpublic class Vector3
InheritanceVector3 Inheritance Object
Implements Geometry
Subclasses Vertex

Represents a vector in a 3D world with the coordinates x, y and z.



Public Properties
 PropertyDefined By
  length : Number
[read-only] Indicates the length of the vector.
Vector3
  x : Number
Defines the x coordinate.
Vector3
  y : Number
Defines the y coordinate.
Vector3
  z : Number
Defined the z coordinate.
Vector3
  ZERO : Vector3
[static] Defines the Vector3 object with the x, y and z properties set to zero.
Vector3
Public Methods
 MethodDefined By
  
Vector3(x:Number = 0, y:Number = 0, z:Number = 0)
Creates a new Vector3 instance.
Vector3
  
add(v:Vector3):void
Computes the addition of two vectors.
Vector3
  
[static] Computes the addition of two Vector3.
Vector3
  
angle(v1:Vector3, v2:Vector3):Number
[static] Returns the angle in radian between the two 3D vectors.
Vector3
  
clone():*
Returns a shallow copy of this instance.
Vector3
  
Computes the cross product of two Vector3s.
Vector3
  
dot(vector:Vector3):Number
Returns the dot value of the passed-in Vector3 with the current Vector3 object.
Vector3
  
equals(o:*):Boolean
Compares the specified object with this object for equality.
Vector3
  
negate():void
Sets this Vector2 with negate coordinates.
Vector3
  
[static] Returns the new negate Vector2 of the specified Vector2 objet.
Vector3
  
normalize():Boolean
Normalize the vector.
Vector3
  
perspective(distance:Number = 300):Number
Calculates and returns the perspective ratio needed to scale an object correctly.
Vector3
  
pow(value:Number):void
Computes the power of the vector.
Vector3
  
pow(vector:Vector3, value:Number):Vector3
[static] Computes the power of the specified Vector3.
Vector3
  
project(perspective:Number):void
Performs a perspective projection on a 3d point.
Vector3
  
project(v:Vector3, perspective:Number):Vector3
[static] Performs a perspective projection on a 3d point.
Vector3
  
rotateX(angle:Number):void
Rotates the current vector object around the x-axis by a certain amount of degrees.
Vector3
  
rotateXTrig(ca:Number, sa:Number):void
Rotates the current vector object around the x-axis by the cosine and sine of an angle.
Vector3
  
rotateXY(a:Number, b:Number):void
Rotates the current vector object around the x and y axes by a certain amount of degrees.
Vector3
  
rotateXYTrig(ca:Number, sa:Number, cb:Number, sb:Number):void
Rotates the current vector object around the x and y axes by the cosine and sine of an angle.
Vector3
  
rotateXYZ(v:Vector3, a:Number, b:Number, c:Number):void
Rotates the current vector object around the x, y and z axes by a certain amount of degrees.
Vector3
  
rotateXYZTrig(ca:Number, sa:Number, cb:Number, sb:Number, cc:Number, sc:Number):void
Rotates the current vector object around the x, y and z axes by the cosine and sine of an angle.
Vector3
  
rotateY(angle:Number):void
Rotates the current vector object around the y-axis by a certain amount of degrees.
Vector3
  
rotateYTrig(ca:Number, sa:Number):void
Rotates the current vector object around the y-axis by the cosine and sine of an angle.
Vector3
  
rotateZ(angle:Number):void
Rotates the current vector object around the z-axis by a certain amount of degrees.
Vector3
  
rotateZTrig(ca:Number, sa:Number):void
Rotates the current vector object around the z-axis by the cosine and sine of an angle.
Vector3
  
scale(value:Number):void
Scales the vector object with the input value.
Vector3
  
scale(v:Vector3, value:Number):Vector3
[static] Scales a new Vector3 object with the input value.
Vector3
  
set(vector:Vector3):void
Sets the specified Vector3 object with the second Vector3 object passed in argument.
Vector3
  
squaredLength():Number
Returns the squared length of this vector.
Vector3
  
Computes the substraction of the current vector object with an other.
Vector3
  
[static] Computes the substraction of two Vector3 and creates a new Vector3.
Vector3
  
swap(vector:Vector3):void
Swap the horizontal and vertical coordinates of two Vector2 objects.
Vector3
  
toObject():Object
Returns the Object representation of this object.
Vector3
  
toSource(indent:int = 0):String
Returns the source code string representation of the object.
Vector3
  
toString():String
Returns the string representation of the object.
Vector3
Public Constants
 ConstantDefined By
  BACKWARD : Vector3
[static] Indicates the relative "backward" direction.
Vector3
  DOWN : Vector3
[static] Indicates the relative "down" direction.
Vector3
  FORWARD : Vector3
[static] Indicates the relative "forward" direction.
Vector3
  LEFT : Vector3
[static] Indicates the relative "left" direction.
Vector3
  RIGHT : Vector3
[static] Indicates the relative "right" direction.
Vector3
  UP : Vector3
[static] Indicates the relative "up" direction.
Vector3
Property Detail
lengthproperty
length:Number  [read-only]

Indicates the length of the vector.


Implementation
    public function get length():Number
xproperty 
public var x:Number

Defines the x coordinate.

yproperty 
public var y:Number

Defines the y coordinate.

zproperty 
public var z:Number

Defined the z coordinate.

ZEROproperty 
public static var ZERO:Vector3

Defines the Vector3 object with the x, y and z properties set to zero.

Constructor Detail
Vector3()Constructor
public function Vector3(x:Number = 0, y:Number = 0, z:Number = 0)

Creates a new Vector3 instance.

Parameters
x:Number (default = 0) — the x coordinate.
 
y:Number (default = 0) — the y coordinate.
 
z:Number (default = 0) — the z coordinate.
Method Detail
add()method
public function add(v:Vector3):void

Computes the addition of two vectors.

Parameters

v:Vector3 — the vector object to add.

add()method 
public static function add(v1:Vector3, v2:Vector3):Vector3

Computes the addition of two Vector3.

Parameters

v1:Vector3 — a Vector3 to concat.
 
v2:Vector3 — a Vector3 to concat.

Returns
Vector3 — the addition result of two Vector3.
angle()method 
public static function angle(v1:Vector3, v2:Vector3):Number

Returns the angle in radian between the two 3D vectors. The formula used here is very simple. It comes from the definition of the dot product between two vectors.

Parameters

v1:Vector3 — Vector3 The first Vector3.
 
v2:Vector3 — Vector3 The second Vector3.

Returns
Number — the angle in radian between the two vectors.
clone()method 
public function clone():*

Returns a shallow copy of this instance.

Returns
* — a shallow copy of this instance.
cross()method 
public function cross(vector:Vector3):Vector3

Computes the cross product of two Vector3s.

Parameters

vector:Vector3 — The Vector3 reference.

Returns
Vector3 — the Vector3 resulting of the cross product.
dot()method 
public function dot(vector:Vector3):Number

Returns the dot value of the passed-in Vector3 with the current Vector3 object.

Example :

         import graphics.geom.Vector3 ;
         
         var v1:Vector3 = new Vector3(10,20,30) ;
         var v2:Vector3 = new Vector3(40,60,70) ;
         
         trace( v1.dot( v2 ) ) ; 
         

Parameters

vector:Vector3 — the Vector2 object to calculate the dot value.

Returns
Number — the dot value.
equals()method 
public function equals(o:*):Boolean

Compares the specified object with this object for equality.

Parameters

o:*

Returns
Booleantrue if the the specified object is equal with this object.
negate()method 
public function negate():void

Sets this Vector2 with negate coordinates.

Example :

         import graphics.geom.Vector3 ;
         
         var v:Vector3 = new Vector3(10,20,30) ;
         
         trace(v) ; // [Vector3 x:10 y:20 z:30]
         
         v.negate() ;
         
         trace(v) ; // [Vector3 x:-10 y:-20 z:-30]
         
         v.negate() ;
         
         trace(v) ; // [Vector3 x:10 y:20 z:30]
         

negate()method 
public static function negate(vector:Vector3):Vector3

Returns the new negate Vector2 of the specified Vector2 objet.

Example :

         import graphics.geom.Vector3 ;
         
         var v:Vector3 = new Point(10,20,30) ;
         var n:Vector3 = Vector3.negate( v ) ;
         
         trace(n) ; // [Vector3 x:-10 y:-20 z:-30]
         

Parameters

vector:Vector3

Returns
Vector3 — The new negate Vector3 of the specified Vector2 objet.
normalize()method 
public function normalize():Boolean

Normalize the vector.

Returns
Booleantrue of the normalize method is success else false for mistake.
perspective()method 
public function perspective(distance:Number = 300):Number

Calculates and returns the perspective ratio needed to scale an object correctly.

Example :

import graphics.geom.Vector3 ; var v:Vector3 = new Vector3(50,20,40); var p:Number = v.perspective(); trace(p) ;

Parameters

distance:Number (default = 300) — The viewing distance of the projection (default value 300).

Returns
Number — the perspective ratio needed to scale an object correctly.
pow()method 
public function pow(value:Number):void

Computes the power of the vector.

Parameters

value:Number — the value of the pow..

pow()method 
public static function pow(vector:Vector3, value:Number):Vector3

Computes the power of the specified Vector3.

Parameters

vector:Vector3 — the Vector3 reference.
 
value:Number — the value of the pow..

Returns
Vector3 — A new Vector3 powered by the method.
project()method 
public function project(perspective:Number):void

Performs a perspective projection on a 3d point. It converts (x, y, z) coordinates to a 2d location (x, y) on the screen.

Example :

import graphics.geom.Vector3 ; var v:Vector3 = new Vector3(50,20,40) ; v.project(); trace(v) ;

Parameters

perspective:Number — the Vector3 reference.

project()method 
public static function project(v:Vector3, perspective:Number):Vector3

Performs a perspective projection on a 3d point. It converts (x, y, z) coordinates to a 2d location (x, y) on the screen.

Example :

         import graphics.geom.Vector3 ;
         
         var v:Vector3 = new Vector3(50,20,40) ;
         var p:Vector3 = Vector3.project(v);
         
         trace(v + " / " + p) ;
         

Parameters

v:Vector3 — The perspective ratio. If no value is specified, it is calculated automatically by calling the getPerspective() method.
 
perspective:Number

Returns
Vector3
rotateX()method 
public function rotateX(angle:Number):void

Rotates the current vector object around the x-axis by a certain amount of degrees.

Example :

         import graphics.geom.Vector3 ;
         
         var v:Vector3 = new Vector3(1,4,7) ;
         
         v.rotateX( 180 );
         trace( v ) ;
         

Parameters

angle:Number — The amount of degrees that the current vector object will be rotated by.

rotateXTrig()method 
public function rotateXTrig(ca:Number, sa:Number):void

Rotates the current vector object around the x-axis by the cosine and sine of an angle.

Example :

         import graphics.geom.Vector3 ;
         import graphics.numeric.Degrees ;
         
         var v:Vector3 = new Vector3(1,4,7);
         
         var cosAngle:Number = cosD(180);
         var sinAngle:Number = sinD(180);
         
         v.rotateXTrig( cosAngle , sinAngle ) ;
         
         trace (v);
         

Parameters

ca:Number — The cosine of the angle to rotate the current vector object by.
 
sa:Number — The sine of the angle to rotate the current vector object by.

rotateXY()method 
public function rotateXY(a:Number, b:Number):void

Rotates the current vector object around the x and y axes by a certain amount of degrees.

Example :

         import graphics.geom.Vector3 ;
         
         var v:Vector3 = new Vector3(8,0,0) ;
         
         v.rotateXY( 45 , 45 ) ;
         
         trace(v) ;
         

Parameters

a:Number — The amount of degrees that the current vector object will be rotated around the x-axis by.
 
b:Number — The amount of degrees that the current vector object will be rotated around the y-axis by.

rotateXYTrig()method 
public function rotateXYTrig(ca:Number, sa:Number, cb:Number, sb:Number):void

Rotates the current vector object around the x and y axes by the cosine and sine of an angle.

Example :

         import graphics.geom.Vector3 ;
         import graphics.numeric.Degrees ;
         
         var v:Vector3 = new Vector3(6,1,4) ;
         
         var cosAngleA:Number = cosD(45) ;
         var sinAngleA:Number = sinD(45) ;
         
         var cosAngleB:Number = cosD(90) ;
         var sinAngleB:Number = sinD(90) ;
         
         v.rotateXYTrig( cosAngleA, sinAngleA, cosAngleB, sinAngleB ) ;
         
         trace(v) ;
         

Parameters

ca:Number — The cosine of the angle to rotate the current vector object around the x-axis by.
 
sa:Number — The sine of the angle to rotate the current vector object around the x-axis by.
 
cb:Number — The cosine of the angle to rotate the current vector object around the y-axis by.
 
sb:Number — The sine of the angle to rotate the current vector object around the y-axis by.

rotateXYZ()method 
public function rotateXYZ(v:Vector3, a:Number, b:Number, c:Number):void

Rotates the current vector object around the x, y and z axes by a certain amount of degrees.

Example :

         import graphics.geom.Vector3
         
         var v:Vector3 = new Vector3(8,0,0);
         
         v.rotateXYZ(45,45,45);
         
         trace (v);
         

Parameters

v:Vector3 — The amount of degrees that the current vector object will be rotated around the x-axis by.
 
a:Number — The amount of degrees that the current vector object will be rotated around the y-axis by.
 
b:Number — The amount of degrees that the current vector object will be rotated around the z-axis by.
 
c:Number

rotateXYZTrig()method 
public function rotateXYZTrig(ca:Number, sa:Number, cb:Number, sb:Number, cc:Number, sc:Number):void

Rotates the current vector object around the x, y and z axes by the cosine and sine of an angle.

Example :

         import graphics.geom.Vector3 ;
         import graphics.numeric.Degrees ;
         
         var v:Vector3 = new Vector3(6,1,4) ;
         
         var cosAngleA:Number = cosD(45) ;
         var sinAngleA:Number = sinD(45) ;
         
         var cosAngleB:Number = cosD(90) ;
         var sinAngleB:Number = sinD(90) ;
         
         var cosAngleC:Number = cosD(135) ;
         var sinAngleC:Number = sinD(135) ;
         
         v.rotateXYZTrig( cosAngleA, sinAngleA, cosAngleB, sinAngleB, cosAngleC, sinAngleC ) ;
         
         trace(v) ;
         

Parameters

ca:Number — The cosine of the angle to rotate the current vector object around the x-axis by.
 
sa:Number — The sine of the angle to rotate the current vector object around the x-axis by.
 
cb:Number — The cosine of the angle to rotate the current vector object around the y-axis by.
 
sb:Number — The sine of the angle to rotate the current vector object around the y-axis by.
 
cc:Number — The cosine of the angle to rotate the current vector object around the z-axis by.
 
sc:Number — The sine of the angle to rotate the current vector object around the z-axis by.

rotateY()method 
public function rotateY(angle:Number):void

Rotates the current vector object around the y-axis by a certain amount of degrees.

Example :

         import graphics.geom.Vector3 ;
         
         var v:Vector3 = new Vector3(1,4,7);
         
         v.rotateY( 180 );
         trace(v);
         

Parameters

angle:Number — The amount of degrees that the current vector object will be rotated by.

rotateYTrig()method 
public function rotateYTrig(ca:Number, sa:Number):void

Rotates the current vector object around the y-axis by the cosine and sine of an angle.

Example :

         import graphics.geom.Vector3 ;
         import graphics.numeric.Degrees ;
         
         var v:Vector3       = new Vector3(3,-8,5);
         
         var cosAngle:Number = Trigo.cosD(90);
         var sinAngle:Number = Trigo.sinD(90);
         
         v.rotateYTrig( cosAngle, sinAngle ) ;
         
         trace(v) ;
         

Parameters

ca:Number — The cosine of the angle to rotate the current vector object by.
 
sa:Number — The sine of the angle to rotate the current vector object by.

rotateZ()method 
public function rotateZ(angle:Number):void

Rotates the current vector object around the z-axis by a certain amount of degrees.

Example :

         import graphics.geom.Vector3 ;
         
         var v:Vector3 = new Vector3(1,4,7) ;
         
         v.rotateZ( 180 ) ;
         trace(v);
         

Parameters

angle:Number — The amount of degrees that the current vector object will be rotated by.

rotateZTrig()method 
public function rotateZTrig(ca:Number, sa:Number):void

Rotates the current vector object around the z-axis by the cosine and sine of an angle.

Example :

         import graphics.geom.Vector3 ;
         import graphics.numeric.Degrees ;
         
         var v:Vector3 = new Vector3(6,1,4) ;
         
         var cosAngle:Number = cosD(45) ;
         var sinAngle:Number = sinD(45) ;
         
         v.rotateZTrig( cosAngle , sinAngle ) ;
         trace(v);
         

Parameters

ca:Number — The cosine of the angle to rotate the current vector object by.
 
sa:Number — The sine of the angle to rotate the current vector object by.

scale()method 
public function scale(value:Number):void

Scales 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:Vector3, value:Number):Vector3

Scales a new Vector3 object with the input value.

Parameters

v:Vector3 — the Vector3 reference to transform.
 
value:Number — a real number to scale the current Vector3.

Returns
Vector3 — A new Vector3 scaled by the value passed in in this method.
set()method 
public function set(vector:Vector3):void

Sets the specified Vector3 object with the second Vector3 object passed in argument.

Parameters

vector:Vector3 — the Vector3 to set the current Vector3.

squaredLength()method 
public function squaredLength():Number

Returns the squared length of this vector.

Returns
Number — the squared length of this vector.
substract()method 
public function substract(v:Vector3):void

Computes the substraction of the current vector object with an other.

Parameters

v:Vector3 — the vector to substract.

substract()method 
public static function substract(v1:Vector3, v2:Vector3):Vector3

Computes the substraction of two Vector3 and creates a new Vector3.

Parameters

v1:Vector3 — a Vector3 to substract.
 
v2:Vector3 — a Vector3.

Returns
Vector3 — the substraction result of two Vector3.
swap()method 
public function swap(vector:Vector3):void

Swap the horizontal and vertical coordinates of two Vector2 objects.

Example :

         import graphics.geom.Vector3 ;
         
         var v1:Vector3 = new Vector3( 10 , 20 , 30) ;
         var v2:Vector3 = new Vector3( 40 , 50 , 60) ;
         
         trace( v1 + " / " + v2 ) ; // [Vector3 x:10 y:20 z:30] / [Vector3 x:40 y:50 z:60]
         
         v1.swap( v2 ) ;
         
         trace( v1 + " / " + v2 ) ; // [Vector3 x:40 y:50 z:60] / [Vector3 x:10 y:20 z:30]
         

Parameters

vector:Vector3

toObject()method 
public function toObject():Object

Returns the Object representation of this object.

Returns
Object — the Object representation of this object.
toSource()method 
public function toSource(indent:int = 0):String

Returns the source code string representation of the object.

Parameters

indent:int (default = 0)

Returns
String — the source code string representation of the object.
toString()method 
public function toString():String

Returns the string representation of the object.

Returns
String — the string representation of the object.
Constant Detail
BACKWARDConstant
public static const BACKWARD:Vector3

Indicates the relative "backward" direction.

DOWNConstant 
public static const DOWN:Vector3

Indicates the relative "down" direction.

FORWARDConstant 
public static const FORWARD:Vector3

Indicates the relative "forward" direction.

LEFTConstant 
public static const LEFT:Vector3

Indicates the relative "left" direction.

RIGHTConstant 
public static const RIGHT:Vector3

Indicates the relative "right" direction.

UPConstant 
public static const UP:Vector3

Indicates the relative "up" direction.