com.robertpenner.geom.Vector | +--com.robertpenner.geom.Vector3d
The Vector3d class is designed to represent vectors and points in three-dimensional space. Vectors can be added together, scaled, rotated, and otherwise manipulated with these methods.
ActionScript 2.0; Flash Player 6
Property summary
Property | Description |
---|---|
x:Number |
The x property of the vector object. |
y:Number |
The y property of the vector object. |
z:Number |
The z property of the vector object. |
length:Number |
The length of the vector object. |
Method summary
Method | Description |
---|---|
toString() : String |
Returns a string representation of the vector object. |
reset(x:Number, y:Number, z:Number) : Void |
Reinitializes the vector object. |
getClone() : Vector3d |
Returns a new vector object containing the x, y and z values of the current vector. |
equals(v:Vector3d) : Object |
Tests the equality of two vector objects. |
plus(v:Vector3d) : Void |
Adds a vector object to the current vector. |
plusNew(v:Vector3d) : Vector3d |
Performs addition on two vector objects and returns the result of the addition as a new vector. |
minus(v:Vector3d) : Void |
Subtracts a vector object from the current vector. |
minusNew(v:Vector3d) : Vector3d |
Performs subtraction on two vector objects and returns the result of the subtraction as a new vector. |
negate() : Void |
Reverses the direction of the current vector. |
negateNew() : Vector3d |
Reverses the direction of the current vector and returns the result as a new vector. |
scale(s:Number) : Void |
Scales the length of the current vector object by a scale factor. |
scaleNew(s:Number) : Vector3d |
Scales the length of the current vector object by a scale factor and returns the result of the scale as a new vector. |
getLength() : Number |
Gets the size of the current vector. |
setLength(len:Number) : Void |
Sets the size of the current vector. |
dot(v:Vector3d) : Number |
Performs multiplication on two vector objects and returns the dot product. |
cross(v:Vector3d) : Vector3d |
Performs multiplication on two vector objects and returns a third vector object that is perpendicular to the first two vectors. |
angleBetween(v:Vector) : Number |
Returns the angle between the current vector and another vector. |
getPerspective(viewDist:Number) : Number |
Calculates and returns the perspective ratio needed to scale an object correctly. |
persProject(p: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. |
persProjectNew(p:Number) : Vector3d |
Performs a perspective projection on a 3d point and returns the result of the projection as a new vector. It converts (x, y, z) coordinates to a 2d location (x, y) on the screen. |
rotateX(ang:Number) : Void |
Rotates the current vector object around the x-axis by a certain amount of degrees. |
rotateXTrig(ca:Number, sa:Number) : Void |
Rotates the current vector object around the x-axis by the cosine and sine of an angle. |
rotateY(ang:Number) : Void |
Rotates the current vector object around the y-axis by a certain amount of degrees. |
rotateYTrig(ca:Number, sa:Number) : Void |
Rotates the current vector object around the y-axis by the cosine and sine of an angle. |
rotateZ(ang:Number) : Void |
Rotates the current vector object around the z-axis by a certain amount of degrees. |
rotateZTrig(ca:Number, sa:Number) : Void |
Rotates the current vector object around the z-axis by the cosine and sine of an angle. |
rotateXY(a:Number, b:Number) : Void |
Rotates the current vector object around the x and y axes by a certain amount of degrees. |
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. |
rotateXYZ(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. |
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. |
var v:Vector3d = new Vector3d(4,0,1);
trace (v.x);
trace (v.y);
trace (v.z);
x:Number
- The x value of the vector.
y:Number
- The y value of the vector.
z:Number
- The z value of the vector.
Creates an instance of the Vector3d class.
var position:Vector3d = new Vector3d(2,4,6.952013);
trace (position.toString());
trace (position);
Returns the string representation of the vector object.
Returns a string representation of the vector object.
var acceleration:Vector3d = new Vector3d(0,0,0);
acceleration.reset(10,20,30);
trace (acceleration);
x:Number
- The x value of the vector.
y:Number
- The y value of the vector.
z:Number
- The z value of the vector.
Nothing.
Reinitializes the vector object.
var force:Vector3d = new Vector3d(2,4,6);
var forceCopy:Vector3d = force.getClone();
trace (forceCopy);
trace (forceCopy == force);
Returns a copy of the current vector object.
Returns a new vector object containing the x, y and z values of the current vector.
var force:Vector3d = new Vector3d(2,4,6);
var forceCopy:Vector3d = force.getClone();
trace (forceCopy.equals(force));
v:Vector3d
- The vector object to compare with the current vector.
Returns true if the values of the two x properties, the two y properties and the two z properties are the same.
Tests the equality of two vector objects.
var position:Vector3d = new Vector3d(1,1,1);
var velocity:Vector3d = new Vector3d(2,1,3);
position.plus(velocity);
trace (position);
v:Vector3d
- The vector object to add to the current vector.
Nothing.
Adds a vector object to the current vector.
var position:Vector3d = new Vector3d(1,1,1);
var velocity:Vector3d = new Vector3d(2,1,3);
var newPosition:Vector3d = position.plusNew(velocity);
trace (newPosition);
v:Vector3d
- The vector object to add to the current vector.
Returns the result of the addition as a new vector.
Performs addition on two vector objects and returns the result of the addition as a new vector.
var farPoint:Vector3d = new Vector3d(10,-6,5);
var nearPoint:Vector3d = new Vector3d(6,-2,0);
farPoint.minus(nearPoint);
trace (farPoint);
v:Vector3d
- The vector object to subtract from the current vector.
Nothing.
Subtracts a vector object from the current vector.
var farPoint:Vector3d = new Vector3d(10,-6,5);
var nearPoint:Vector3d = new Vector3d(6,-2,0);
var displacement:Vector3d = farPoint.minusNew(nearPoint);
trace (displacement);
v:Vector3d
- The vector object to subtract from the current vector.
Returns the result of the subtraction as a new vector.
Performs subtraction on two vector objects and returns the result of the subtraction as a new vector.
var direction:Vector3d = new Vector3d(3,-6,-9);
direction.negate();
trace (direction);
Nothing.
Reverses the direction of the current vector.
var towards:Vector3d = new Vector3d(0,0,-20);
var away:Vector3d = towards.negateNew();
trace (away);
Returns the reversed vector object as a new vector.
Reverses the direction of the current vector and returns the result as a new vector.
var tensionForce:Vector3d = new Vector3d(3,-1,0);
tensionForce.scale(2);
trace (tensionForce);
s:Number
- The scale factor to multiply the current vector by.
Nothing.
Scales the length of the current vector object by a scale factor.
var tensionForce:Vector3d = new Vector3d(3,-1,0);
var strongerForce:Vector3d = tensionForce.scaleNew(2);
trace (strongerForce);
s:Number
- The scale factor to multiply the current vector by.
Returns the scaled vector object as a new vector.
Scales the length of the current vector object by a scale factor and returns the result of the scale as a new vector.
var velocity:Vector3d = new Vector3d(3,4,0);
var speed:Number = velocity.getLength();
trace (speed);
Returns the size of the current vector.
Gets the size of the current vector.
var velocity:Vector3d = new Vector3d(3,4,0);
var newSpeed:Number = 10;
velocity.setLength(newSpeed);
trace (velocity);
trace (velocity.getLength());
len:Number
- The length that the current vector will be set.
Nothing.
Sets the size of the current vector.
var v:Vector3d = new Vector3d(2,0,1);
var w:Vector3d = new Vector3d(3,5,4);
trace (v.dot(w));
v:Vector3d
- The vector object to multiply the current vector by.
Returns the dot product.
Performs multiplication on two vector objects and returns the dot product.
var a:Vector3d = new Vector3d(2,0,0);
var b:Vector3d = new Vector3d(0,2,0);
var c:Vector3d = a.cross(b);
trace (c);
var d:Vector3d = b.cross(a);
trace (d);
v:Vector3d
- The vector object to multiply the current vector by.
Returns a normal vector to the other two vector objects.
Performs multiplication on two vector objects and returns a third vector object that is perpendicular to the first two vectors.
var pullForce:Vector3d = new Vector3d(4,0,0);
var frictionForce:Vector3d = new Vector3d(-1,0,1);
var theta:Number = pullForce.angleBetween(frictionForce);
trace (theta);
v:Vector
- The vector object to check the angle between.
Returns the angle between the current vector and another vector.
Returns the angle between the current vector and another vector.
var pointA:Vector3d = new Vector3d(50,20,40);
var pers:Number = pointA.getPerspective();
trace (pers);
viewDist:Number
- The viewing distance of the projection.
Large values produce an image in which there is little size difference between close and distant objects.
Small values produce more of a "fisheye" effect, distorting the image like a peephole.
If no value is specified, a default value of 300 is chosen, which gives a natural-looking perspective.
Returns the perspective ratio needed to scale an object correctly.
Calculates and returns the perspective ratio needed to scale an object correctly.
var pointA:Vector3d = new Vector3d(50,20,40);
pointA.persProject();
trace (pointA);
p:Number
- The perspective ratio. If no value is specified, it is calculated automatically by calling the getPerspective() method.
Nothing.
Performs a perspective projection on a 3d point. It converts (x, y, z) coordinates to a 2d location (x, y) on the screen.
var pointA:Vector3d = new Vector3d(50,20,40);
pointA.persProject();
trace (pointA);
p:Number
- The perspective ratio. If no value is specified, it is calculated automatically by calling the getPerspective() method.
Returns the result of the projection as a new vector.
Performs a perspective projection on a 3d point and returns the result of the projection as a new vector. It converts (x, y, z) coordinates to a 2d location (x, y) on the screen.
var p:Vector3d = new Vector3d(1,4,7);
p.rotateX(180);
trace (p);
ang:Number
- The amount of degrees that the current vector object will be rotated by.
Nothing.
Rotates the current vector object around the x-axis by a certain amount of degrees.
var p:Vector3d = new Vector3d(1,4,7);
var cosAngle:Number = Degree.cosD(180);
var sinAngle:Number = Degree.sinD(180);
p.rotateXTrig(cosAngle, sinAngle);
trace (p);
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.
Nothing.
Rotates the current vector object around the x-axis by the cosine and sine of an angle.
var p:Vector3d = new Vector3d(1,4,7);
p.rotateY(180);
trace (p);
ang:Number
- The amount of degrees that the current vector object will be rotated by.
Nothing.
Rotates the current vector object around the y-axis by a certain amount of degrees.
var p:Vector3d = new Vector3d(3,-8,5);
var cosAngle:Number = Degree.cosD(90);
var sinAngle:Number = Degree.sinD(90);
p.rotateYTrig(cosAngle, sinAngle);
trace (p);
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.
Nothing.
Rotates the current vector object around the y-axis by the cosine and sine of an angle.
var p:Vector3d = new Vector3d(1,4,7);
p.rotateZ(180);
trace (p);
ang:Number
- The amount of degrees that the current vector object will be rotated by.
Nothing.
Rotates the current vector object around the z-axis by a certain amount of degrees.
var p:Vector3d = new Vector3d(6,1,4);
var cosAngle:Number = Degree.cosD(45);
var sinAngle:Number = Degree.sinD(45);
p.rotateZTrig(cosAngle, sinAngle);
trace (p);
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.
Nothing.
Rotates the current vector object around the z-axis by the cosine and sine of an angle.
var p:Vector3d = new Vector3d(8,0,0);
p.rotateXY(45,45);
trace (p);
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.
Nothing.
Rotates the current vector object around the x and y axes by a certain amount of degrees.
var p:Vector3d = new Vector3d(6,1,4);
var cosAngleA:Number = Degree.cosD(45);
var sinAngleA:Number = Degree.sinD(45);
var cosAngleB:Number = Degree.cosD(90);
var sinAngleB:Number = Degree.sinD(90);
p.rotateXYTrig(cosAngleA, sinAngleA, cosAngleB, sinAngleB);
trace (p);
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.
Nothing.
Rotates the current vector object around the x and y axes by the cosine and sine of an angle.
var p:Vector3d = new Vector3d(8,0,0);
p.rotateXYZ(45,45,45);
trace (p);
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.
c:Number
- The amount of degrees that the current vector object will be rotated around the z-axis by.
Nothing.
Rotates the current vector object around the x, y and z axes by a certain amount of degrees.
var p:Vector3d = new Vector3d(6,1,4);
var cosAngleA:Number = Degree.cosD(45);
var sinAngleA:Number = Degree.sinD(45);
var cosAngleB:Number = Degree.cosD(90);
var sinAngleB:Number = Degree.sinD(90);
var cosAngleC:Number = Degree.cosD(135);
var sinAngleC:Number = Degree.sinD(135);
p.rotateXYZTrig(cosAngleA, sinAngleA, cosAngleB, sinAngleB, cosAngleC, sinAngleC);
trace (p);
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.
Nothing.
Rotates the current vector object around the x, y and z axes by the cosine and sine of an angle.
v.x = -4;
The x property of the vector object.
v.y = 0;
The y property of the vector object.
v.z = -1;
The z property of the vector object.
var velocity:Vector3d = new Vector3d(3,4,0);
var newSpeed:Number = 10;
velocity.length = newSpeed;
trace (velocity);
trace (velocity.length);
The length of the vector object.