Class: Vector3D

graphics.geom. Vector3D


new Vector3D( [x] [, y] [, z] [, w])

The Vector3D class represents a point or a location in the three-dimensional space using the Cartesian coordinates x, y, and z.

The Vector3D class represents a point or a location in the three-dimensional space using the Cartesian coordinates x, y, and z.

As in a two-dimensional space, the x property represents the horizontal axis and the y property represents the vertical axis. In three-dimensional space, the z property represents depth. The value of the x property increases as the object moves to the right. The value of the y property increases as the object moves down. The z property increases as the object moves farther from the point of view. Using perspective projection and scaling, the object is seen to be bigger when near and smaller when farther away from the screen. As in a right-handed three-dimensional coordinate system, the positive z-axis points away from the viewer and the value of the z property increases as the object moves away from the viewer's eye. The origin point (0,0,0) of the global space is the upper-left corner of the stage.

The Vector3D class can also represent a direction, an arrow pointing from the origin of the coordinates, such as (0,0,0), to an endpoint; or a floating-point component of an RGB (Red, Green, Blue) color model.

Quaternion notation introduces a fourth element, the w property, which provides additional orientation information. For example, the w property can define an angle of rotation of a Vector3D object. The combination of the angle of rotation and the coordinates x, y, and z can determine the display object's orientation. Here is a representation of Vector3D elements in matrix notation : [x y z w]

Parameters:
Name Type Argument Default Description
x number <optional>
0

The first element of a Vector3D object, such as the x coordinate of a point in the three-dimensional space.

y number <optional>
0

The second element of a Vector3D object, such as the y coordinate of a point in the three-dimensional space.

z number <optional>
0

The third element of a Vector3D object, such as the z coordinate of a point in three-dimensional space.

w number <optional>
0

The fourth element of a Vector3D object (in addition to the x, y, and z properties) can hold data such as the angle of rotation.

Extends

Members


<static> length :Number

The length, magnitude, of the current Vector3D object from the origin (0,0,0) to the object's x, y, and z coordinates. The w property is ignored. A unit vector has a length or magnitude of one.

Type:
  • Number

<static> lengthSquared :Number

The square of the length of the current Vector3D object, calculated using the x, y, and z properties. The w property is ignored. Use the lengthSquared() method whenever possible instead of the slower Math.sqrt() method call of the Vector3D.length property.

Type:
  • Number

<static, constant> X_AXIS

The x axis defined as a Vector3D object with coordinates (1,0,0).


<static, constant> Y_AXIS

The y axis defined as a Vector3D object with coordinates (0,1,0).


<static, constant> Z_AXIS

The z axis defined as a Vector3D object with coordinates (0,0,1).


w :Number

The fourth element of a Vector3D object (in addition to the x, y, and z properties) can hold data such as the angle of rotation.

Quaternion notation employs an angle as the fourth element in its calculation of three-dimensional rotation. The w property can be used to define the angle of rotation about the Vector3D object. The combination of the rotation angle and the coordinates (x,y,z) determines the display object's orientation.

Type:
  • Number
Default Value:
  • 0

x :Number

The horizontal coordinate of the point.

Type:
  • Number
Inherited From:
Default Value:
  • 0

y :Number

The vertical coordinate of the point.

Type:
  • Number
Inherited From:
Default Value:
  • 0

z :Number

The third element of a Vector3D object, such as the z coordinate of a point in three-dimensional space.

Type:
  • Number
Default Value:
  • 0

Methods


<static> distance(a, b)

Returns the distance between two Vector3D objects.

The distance() method is a static method. You can use it directly as a method of the Vector3D class to get the Euclidean distance between two three-dimensional points.

Parameters:
Name Type Description
a graphics.geom.Vector3D

The first Vector3D object.

b graphics.geom.Vector3D

The second Vector3D object.

Returns:

he angle between two Vector3D objects.


<static> The distance between two Vector3D objects.(v1, v2)

Returns the angle in radians between two vectors.

The angleBetween() method is a static method. You can use it directly as a method of the Vector3D class.

To convert a degree to a radian, you can use the following formula: radian = Math.PI/180 * degree

Parameters:
Name Type Description
v1 graphics.geom.Vector3D

The first Vector3D object.

v2 graphics.geom.Vector3D

The second Vector3D object.

Returns:

The angle between two Vector3D objects.


add(vector)

Adds the coordinates of another vector to the coordinates of this vector.

Parameters:
Name Type Description
vector graphics.geom.Vector3D | Object

the vector to be added. You can use an object with the properties x, y and z.


clone()

The a shallow copy of the object.

Overrides:
Returns:

a shallow copy of the object.


copyFrom(source)

Copies all of vector data from the source Vector3D object into the calling Vector3D object.

Parameters:
Name Type Description
source graphics.geom.Vector3D

The Vector3D object from which to copy the data.

Overrides:
Returns:

The current graphics.geom.Vector3D reference.


crossProduct(vector)

Returns a new Vector3D object that is perpendicular (at a right angle) to the current Vector3D and another Vector3D object.

You can use the normalized cross product of two vertices of a polygon surface with the normalized vector of the camera or eye viewpoint to get a dot product. The value of the dot product can identify whether a surface of a three-dimensional object is hidden from the viewpoint.

Parameters:
Name Type Description
vector graphics.geom.Vector3D

The second Vector3D object.

Returns:

The Vector3D resulting of the cross product.


dotProduct(vector)

If the current Vector3D object and the one specified as the parameter are unit vertices, this method returns the cosine of the angle between the two vertices. Unit vertices are vertices that point to the same direction but their length is one. They remove the length of the vector as a factor in the result. You can use the normalize() method to convert a vector to a unit vector.

Parameters:
Name Type Description
vector graphics.geom.Vector3D

The Vector3D object to calculates the dot value.

Returns:

The dot value.

Example
var v1 = new Vector3(10,20,30) ;var v2 = new Vector3(40,60,70) ;trace( v1.dot( v2 ) ) ;

equals()

Compares the passed-in object with this object for equality.

Overrides:
Returns:

true if the the specified object is equal with this object.

Type
boolean

negate()

Negating the x,y and z values in the Vector3D object.


project()

Divides the value of the x, y, and z properties of the current Vector3D object by the value of its w property.


setTo( [x] [, y] [, z])

Sets the horizontal and vertical coordinates of this object. If the x and the y parameters are NaN or null the x and y value are 0.

Parameters:
Name Type Argument Default Description
x number <optional>
0

The first element of a Vector3D object, such as the x coordinate of a point in the three-dimensional space.

y number <optional>
0

The second element of a Vector3D object, such as the y coordinate of a point in the three-dimensional space.

z number <optional>
0

The third element of a Vector3D object, such as the z coordinate of a point in three-dimensional space.

Overrides:

subtract(vector)

Subtracts the coordinates of another vector from the coordinates of this vector.

Parameters:
Name Type Description
vector graphics.geom.Vector3D

The vector to be subtracted.


toObject()

Returns the Object representation of this object.

Overrides:
Returns:

the Object representation of this object.


toString()

Returns the string representation of this instance.

Overrides:
Returns:

The string representation of this instance.

Type
string