Realsoft 3D defines two separate vector classes for managing three and four dimensional vectors. Vector classes are built-in classes for sake of speed.Three dimensional vector class defines three attributes: x, y, z: Four dimensional vector defines attributes x, y, z and w.
r3Vect - constructor for 3d vector
v = new r3Vect()
x, y, z, w - floating point numbers
v - new vector object
Creates a new vector object. If you don't pass any parameters to the constructor, a null vector is created i.e. all the vector attributes are initialized to zero.
v = new r3Vect(); v = new r3Vect(0.1, 0,2, 0.3);
add - addition
v2 = v.add(v1);
v1 - vector
v2 = result vector
This adds the given vector to the object in question and returns the result as a new vector. The operation doesn't change the attributes of the object.
v1 = new r3Vect(0.1, 0, 0); v2 = new r3Vect(0.2, 0, 0); v3 = v1.add(v2);
fadd - vector addition
v.fadd(v2);
v2 - vector to be added
-
Vector operation v = v+v2.
v = new r3Vect(1, 0, 0); v2 = new r3Vect(0.1, 0, 0); v.fadd(v2);
set - set value
v.set(x, y, z); // r3Vect
x, y, z, w - floating point numbers
-
Set new value to the vector
v = new r3Vect(); v.set(0.1, 0.2, 1.0);
sub - vector subtraction
v3 = v.sub(v2);
v2 - vector to be subracted from the given object
vector - the result of the subtraction
Returns a new vector containing the result of vector operation 'v - v2'.
v1 = new r3Vect(1, 1, 1); v2 = new r3Vect(0.5, 0.5, 0.5); v3 = v2.sub(v1);
fsub - vector subtraction
v.fsub(v2);
v2 - vector to be subracted from the given object
-
Subtracts given vector 'v2' from the vector in question.
v = new r3Vect(1, 1, 1); v2 = new r3Vect(1, 1, 1); v.fsub(v2); // 0, 0, 0
dot - dot product
f = v.dot(v2);
v2 - vector
f - floating point number
Performs dot product between 'v' and given parameter 'v2' and returns the result. The operation has no impact to the object itself
v1 = new r3Vect(1, 0, 0); v2 = new r3Vect(1, 1, 0); f = v1.dot(v2);
cross - cross product
v3 = v.cross(v2);
v2 - vector
v3 - result vector
Computes cross product 'v x v2' and returns the resulting vector. The operation doesn't impact the object itself
v1 = new r3Vect(1, 0, 0); v2 = new r3Vect(0, 1, 0); v3 = v1.cross(v2);
len - lenght of vector
length = v.len()
-
lenght - floating point number
Compute and return the lenght of the vector.
v = new r3Vect(0, 2, 0); l = v.len(); // l = 2;
norm - normalize vector
len = v.norm();
-
len - original lenght of the vector
Normalizes the vector and returns the original lenght.
v = new r3Vect(0.5, 0, 0); v.norm();
orth - orthogonal projection
v3 = v.orth(v2);
v2 - vector
v3 - result vector
Orthogonal projection. The resulting 'v3' vector is perpendicular to 'v' and on the same plane as both 'v' and 'v2'.
v1 = new r3Vect(1, 0, 0); v2 = new r3Vect(1, 1, 1); v3 = v1.orth(v2);
proj - projection
v3 = v.proj(v2);
v2 - vector to be projected on 'v'
v3 - vector
Returns vectors 'v2' projection on 'v'.
v1 = new r3Vect(1, 0, 0); v2 = new r3Vect(1, 1, 1); v3 = v1.proj(v2);
neg - negate
v2 = v.neg();
-
v2 - vector
Returns a vector pointing to opposite direction than the object in question.
v = new r3Vect(1, 0, 0); nv = v.neg();
fneg - negative
v.neg();
-
-
Makes the vector negative vector i.e. inverts the direction of the vector
v = new r3Vect(1, 0, 0); v.fneg(); v.print(); // -1, 0, 0
mul - scalar multiplication
v2 = v.mul(f);
f - scalar for multiplying the vector
v2 - result
Multiplies the vector with the given scalar value and returns the resulting new vector.
v = new r3Vect(1, 2, 3); v2 = v.mul(10); // v2 = 10, 20, 30
fmul - scalar multiplication
v.fmul(f);
f - floating point number
-
Multiplies the vector by given scalar.
v = new r3Vect(1, 2, 3); v.fmul(10); v.print(); // v = 10, 20, 30
div - division by scalar
v2 = v.div(f);
f - floating point number
v2 - vector
Divides the vector by given scalar and returns a new vector holding the result.
v = new r3Vect(1, 0, 0); v2 = v.div(2.0);
fdiv - division by scalar
v.fdiv(f);
f - floating point number
-
Divides the vector by given scalar.
v = new r3Vect(1, 0, 0); v.fdiv(2.0); v.print(); // 0.5, 0, 0
cmul
v3 = v.cmul(v2);
v2 - vector
v3 - vector
Component wise multiplication. Multiplies each component in 'v' by corresponding component of 'v2' and returns the result as a new vector.
v1 = new r3Vect(1, 2, 3); v2 = new r3Vect(1, 2, 3); v3 = v1.cmul(v2); // v3 == 1, 4, 9
fcmul - vector multiplication
v.fcmul(v2);
v2 - vector
-
Multiplies the 'v' by given vector 'v2'.
v = new r3Vect(1, 2, 3); v2 = new r3Vect(1, 2, 3); v.fcmul(v2); v.print(); // 1, 4, 9
cmp - compare
b = v.cmp(v2, tolerance);
v2 - vector
tolerance - tolerance
b - boolean, true if vectors are identical within the given tolerance
Compare the given vector 'v2' agains the vector in question and return true if the vectors are identical. Otherwise returns false.
v1 = new r3Vect(1, 1, 1); v2 = new r3Vect(1.1, 1, 1); v1.cmp(v2, 0.001);
print - print vector
v.print()
-
-
Print out the current value of the vector.
v.set(1, 2, 3); v.print();
angle - angle to given vector
angle = v.angle(v2);
v2 - vector
angle - angle in radians
Compute the angle between the vector in question and the given parameter 'v2'.
![]() |
Note |
|---|---|
| This method is not supported by 4d vector. |
v = new r3Vect(1, 0, 0); v2 = new r3Vect(0, 1, 0); angle = v.angle(v2);
dist - distance to given point
dist = v.dist(v2);
v2 - vector
dist - distance
Measure the distance between two points specified by 'v' and 'v2'
v = new r3Vect(1, 0, 0); v2 = new r3Vect(2, 0, 0); distance = v.dist(v2); // distance == 1.0