pebxcvi's picture
update
ee7329c
Raw
History Blame Contribute Delete
38.7 kB
1.93 Vectorl .824
1.93.1 Vector4.Abs .824
1.93.2 Voctor4.Acd .825
1.93.3 Vector4.Calculate2dLinelntersection .826
1.93.4 Vector4.Copy .826
1.93.5 Vector4.Create .827
1.93.6 Vector4.CreateBroadcast .828
1.93.7 Vector4.Cross .828
1.93.8 Vector4.Dist2Sqr .829
1.93.9 Vector4.Dist3Sqr .830
1.93.10 Vector4.Dist4Sqr .830
1.93.11 Vector4.Divide .831
1.93.12 Vector4.Dot2 .832
1.93.13 Vector4.Dot3 .832
1.93.14 Vector4.Dot4 .833
1.93.15 Vectors HorizAdd3 .834
1.93.16 Vector4.HorizAdd4 .834
1.93.17 Vector4.Length2 .835
1.93.18 Vector4.Length2Sqr.836
1.93.19 Vector4.Length3 .836
1.93.20 Vector4.Length3Sqr.837
1.93.21 Vector4.Length4 .838
1.93.22 Vector4.Length4Sqr.839
1.93.23 Vector4.Max .839
1.93.24 Vector4.Min .840
1.93.25 Vector4.Multiply .841
1.93.26 Vector4.MultiplyAdd .842
1.93.27 Vector4.Negate .842
1.93.28 Vector4.Normal2 .843
1.93.29 Vector4.Normal3 .844
1.93.30 Vector4.Normal4 .844
1.93.31 Vector4.Normalize2 .845
1.93.32 Vector4.Normalizes .846
1.93.33 Vector4.Normalize4 .847
1.93.34 Vector4.Recip .847
1.93.35 Vector4.RecipSqrt .848
1.93.36 Vector4.Rotate.849
1.93.37 Vector4.SetBroadcast .849
1.93.38 Vccto'4.Se:W .850
1.93.39 VcctoM.So-.X .850
1.93.40 Vector4.SetXyzw .851
1.93.41 Vector4.SetY .852
1.93.42 Vector4.SetZ .852
1.93.43 Vector4.Sign .853
1.93.44 Vector4.Signum .853
1.93.45 Vector4.Sqrt.854
1.93.46 Vector4.Subtract .855
1.93.47 Vector4.Transform .855
1.93.48 Vector4.TransformPoint.856
1.93.49 Vector4.Transform Vector .857
1.93.50 Vecto'4.W .858
1.93.51 VectoM.X .859
1.93.52 VcctO'4.Y .859
1.93.53 Vector4.Z .860
Vector4
Vector4.Abs
Brief
Compute the component-wise absolute value of a vector.
Definition
! Vector4.Abs(Vector4 dest, Vector4 v)
Arguments
dest - destination vector to store result.v - vector to negate.
Return Values
None.
Description
Sets dest to [math.abs(v:XQ), math.abs(v:Y()), math.abs(v:Z()), math.abs(v:W())].
Examples
� local v = Vector4.Create(-1, 2 , -3)
i v:Abs(v)
; print (v) � [1, 2 , 3]
See Also
None
Vector4.Add
Brief
Adds one vector or number to another and stores the result in the destination.
Definition
! Vector4.Add( Vector4 destination, Vector4|number sourcel, Vector4|number source2 )
Arguments
destination - Vector to store the result of the addition.sourcel - Vector or number to be added to source2.source2 - Vector or number to be added
to sourcel.
Return Values
None.
Description
Adds one vector or number to another and stores the result in the destination.
Descriptive notation:
destination.x = sourcel .x[source1 + source2.x|source2
destination.y = sourcel ,y|source1 + source2.y|source2
destination.z = sourcel .z|source1 + source2.z|source2
destination, w = sourcel .w|source1 + source2.w|source2
Examples
result = Vector4.Create()
vl = Vector4.Create(
1, 2, 3, 4 )
v2 = Vector4.Create(
4 , 3, 2, 1 )
Vector4.Add( result,
vl, v2 )
Vector4.Add( result.
3, v2 )
See Also
� Vector4.Create
Vector4.Calculate2dLinelntersection
Brief
Calculates a 2-dimensional line intersection.
Definition
boolean Vector4.Calculate2dLineIntersection( Vector4 intersectionPoint, Vector4 pO, Vector4 pi,
Vector4 qO, Vector4 ql, boolean infinitelntersection = false )
Arguments
intersectionPoint - The result of the line intersection.pO - First endpoint of first line.pi - Second endpoint of first line.qO - First endpoint of second
line.ql - Second endpoint of second line.infinitelntersection - true if the supplied lines are to be treated as infinite rays, false otherwise
Return Values
Returns true if lines intersect, false otherwise.
Description
Calculates a 2-dimensional line intersection with the line p, defined by points pO and pi, with the line q, defined by points qO and ql. If the
infinitelntersection is true it returns false if p and q are parallel. If infinitelntersection is false it returns false if the lines are parallel or the
intersection does not lie on both p and q.
Examples
pO = Vector4.Create( 1, 0 )
pi = Vector4.Create( 0, 0 )
qO = Vector4.Create( 0, 0.5 )
ql = Vector4.Create( 1, 0.5 )
ip = Vector4.Create()
if Vector4.Calculate2dLineIntersection( ip, pO, pi, qO, ql ) then
print ( "The lines intersect!" )
end
See Also
� Vector4.Create
Vector4.Copy
Brief
Copies the values of one vector into another.
Definition
Vector4.Copy( Vector4 destination, Vector4 source )
Arguments
destination - The vector to copy to.source - The vector to be copied.
Return Values
None.
Description
Copies the values of the source vector and stores them in the destination. This is used to copy the values as opposed to pointing to the same
vector as an assignment would do. Use copy as vec2 = vecl does not copy values but instead makes vec2 point to vecl.
Examples
vecl = Vector4.Create( 4, 3, 2, 1 )
vec2 = Vector4.Create()
Vector4.Copy( vec2, vecl )
See Also
� Vector4.Create
Vector4.Create
Brief
Creates a new Vector4 object using the specified values.
Definition
Vector4 Vector4.Create( Vector4 source )
Vector4 Vector4.Create( number x = 0.0, number y = 0.0, number z = 0.0, number w = 0.0 )
Arguments
source - Vector whose values are used to initialize newly created vector.x - Number to be written into the first element of the vector (defaults to
0).y - Number to be written into the second element of the vector (defaults to 0).z - Number to be written into the third element of the vector
(defaults to 0).w - Number to be written into the fourth element of the vector (defaults to 0).
Return Values
A new Vector4 instance.
Description
Creates a new Vector4 object using the specified values.
Examples
� Create a default zero (0, 0, 0, 0) vector
vecl = Vector4.Create ()
� Create a vector with supplied values
vec2 = Vector4.Create ( 1, 2, 3, 4 )
� Create a vector using the values of another
vec3 = Vector4.Create( vec2 )
See Also
� Vector4.CreateBroadcast
Vector4.CreateBroadcast
Brief
Creates a new Vector4 and sets all its elements to the specified value.
Definition
Vector4 Vector4.CreateBroadcast( number value )
Arguments
value - The value to broadcast to all the elements of the new vector.
Return Values
A new Vector4 instance.
Description
Creates a new Vector4 and sets all its elements to the specified value.
Examples
vecHalf = Vector4.CreateBroadcast( 0.5 )
vec = Vector4.Create( 1, 2 , 3 )
Vector4.Multiply( vec, vec, vecHalf )
See Also
� Vector4. Create
Vector4.Cross
Brief
Performs a cross product between two 3-dimensional vectors.
Definition
Vector4.Cross( Vector4 destination, Vector4 srcl, Vector4 src2 )
Arguments
destination - Vector to store the result of the cross product.srcl - First vector to take part in the cross product.src2 - Second vector to take part in
the cross product.
Return Values
None.
Description
Performs a 3-dimensional cross product between srcl and src2 storing the result in destination. The vector generated will be perpendicular to
both srcl and src2.
Vector algebra notation:
srcl X src2
Descriptive notation:
destination.x = ( srcl .y * src2.z ) - ( srcl .z * src2.y )
destination.y = ( srcl .z * src2.x ) - ( srcl .x * src2.z )
destination.z = ( srcl .x * src2.y ) - ( srcl .y * src2.x )
Examples
xAxis = Vector4.Create( 1, 0, 0 )
yAxis = Vector4.Create( 0, 1, 0 )
result = Vector4.Create()
Vector4.Cross( result, xAxis, yAxis )
See Also
� Vector4.Create
Vector4.Dist2Sqr
Brief
Computes the squared Euclidean distance between two points in 2D space.
Definition
number Vector4.Dist2Sqr( Vector4 pi, Vector4 p2 )
Arguments
pi - A point in 2D space.p2 - A second point in 2D space.
Return Values
The squared Euclidean distance between the two points.
Description
Computes the squared Euclidean distance between two points in 2D space.
Vector algebra notation:
((p2-p1) dot (p2-p1))
Examples
vl = Vector4.Create (1, 2)
v2 = Vector4.Create (2, 3)
print("Distance between", vl, "and", v2, "is:", math.sqrt(Vector4.Dist2Sqr(vl, v2)))
See Also
� Vector4.Dist3Sqr
� Vector4.Dist4Sqr
Vector4.Dist3Sqr
Brief
Computes the squared Euclidean distance between two points in 3D space.
Definition
number Vector4.Dist3Sqr( Vector4 pi, Vector4 p2 )
Arguments
pi - A point in 3D space.p2 - A second point in 3D space.
Return Values
The squared Euclidean distance between the two points.
Description
Computes the squared Euclidean distance between two points in 3D space.
Vector algebra notation:
(( P 2-p1) dot ( P 2-p1))
Examples
j vl = Vector4.Create(1, 2, 3)
I v2 = Vector4.Create(2, 3, 4)
j print("Distance between", vl, "and", v2, "is:", math.sqrt(Vector4.Dist3Sqr(vl, v2)))
See Also
� Vector4.Dist2Sqr
� Vector4.Dist4Sqr
Vector4.Dist4Sqr
Brief
Computes the squared Euclidean distance between two points in 4D space.
Definition
number Vector4.Dist4Sqr( Vector4 pi, Vector4 p2 )
Arguments
pi - A point in 4D space.p2 - A second point in 4D space.
Return Values
The squared Euclidean distance between the two points.
Description
Computes the squared Euclidean distance between two points in 4D space.
Vector algebra notation:
((p2-p1) dot (p2-p1))
Examples
vl = Vector4.Create ( 1, 2, 3, 4 )
v2 = Vector4.Create ( 2 , 3, 4, 5 )
print("Distance between", vl, "and", v2, "is:", math.sqrt(Vector4.Dist4Sqr(vl, v2)))
See Also
� Vector4.Dist2Sqr
� Vector4.Dist3Sqr
Vector4. Divide
Brief
Divides one vector or scalar by the other vector or scalar.
Definition
Vector4.Divide( Vector4 destination, Vector4|number sourcel, Vector4|number source2 )
Arguments
destination - Vector to store the result of the division.sourcel - The dividend of the vector division.source2 - The divisor of the vector division.
Return Values
None.
Description
Divides sourcel by source2 storing the result in destination.
Descriptive notation:
destination.x = sourcel .x|source1 / source2.x]source2
destination.y = sourcel .y|source1 / source2.y|source2
destination, z = sourcel ,z|source1 / source2.z|source2
destination.w = sourcel .w|source1 / source2.w|source2
Examples
result = Vector4.Create()
vl = Vector4.Create( 1, 2, 3, 4 )
v2 = Vector4.Create( 4, 3 , 2 , 1 )
Vector4.Divide( result, vl, v2 )
Vector4.Divide( result, 1.0, v2 )
See Also
� Vector4.Create
Vector4.Dot2
Brief
Performs a dot product between two 2-dimensional vectors.
Definition
number Vector4.Dot2( Vector4 srcl, Vector4 src2 )
Arguments
srcl - First vector to take part in the dot product.src2 - Second vector to take part in the dot product.
Return Values
The number representing the dot product of the two supplied 2-dimensional vectors.
Description
Performs a 2-dimensional dot product with srcl and src2 returning the result.
Vector algebra notation:
srcl . src2
Descriptive notation:
returnvalue = ( srcl .x * src2.x ) + ( srcl .y * src2.y )
Examples
vl = Vector4.Create ( 1, 2 )
v2 = Vector4.Create ( 4, 3 )
result = Vector4.Dot2( vl, v2 )
See Also
� Vector4.Create
� Vector4.Dot3
� Vector4.Dot4
Vector4.Dot3
Brief
Performs a dot product between two 3-dimensional vectors.
Definition
number Vector4.Dot3( Vector4 srcl, Vector4 src2 )
Arguments
srcl - First vector to take part in the dot product.src2 - Second vector to take part in the dot product.
Return Values
The number representing the dot product of the two supplied 3-dimensional vectors.
Description
Performs a 3-dimensional dot product with srcl and src2 returning the result.
Vector algebra notation:
srcl . src2
Descriptive notation:
returnvalue = ( srcl .x * src2.x ) + ( srcl .y * src2.y ) + ( srcl .z * src2.z )
Examples
j vl = Vector4.Create( 1, 2, 3 )
! v2 = Vector4.Create( 4, 3, 2 )
j result = Vector4.Dot3( vl, v2 )
See Also
� Vector4.Create
� Vector4.Dot2
� Vector4.Dot4
Vector4.Dot4
Brief
Performs a dot product between two 4-dimensional vectors.
Definition
1 number Vector4.Dot4( Vector4 srcl, Vector4 src2 )
Arguments
srcl - First vector to take part in the dot product.src2 - Second vector to take part in the dot product.
Return Values
The number representing the dot product of the two supplied 4-dimensional vectors.
Description
Performs a 4-dimensional dot product with srcl and src2 returning the result.
Vector algebra notation:
srcl . src2
Descriptive notation:
returnvalue = ( srcl .x * src2.x ) + ( srcl .y * src2.y ) + ( srcl .z * src2.z ) + ( srcl .w * src2.w )
Examples
vl = Vector4.Create ( 1, 2, 3, 4 )
v2 = Vector4.Create ( 4, 3, 2, 1 )
result = Vector4.Dot4( vl, v2 )
See Also
� Vector4.Create
� Vector4.Dot2
� Vector4.Dot3
Vector4.HorizAdd3
Brief
Compute the horizontal sum of a 3D vector.
Definition
number Vector4.HorizAdd3(Vector4 v)
Arguments
v - input vector.
Return Values
The sum of the X, Y and Z components of the input vector.
Description
Returns v:X() + v:Y() + v:Z(). W is ignored.
Examples
! local v = Vector4.Create(1, 2, 3)
I print(v:HorizAdd3()) � 6
See Also
� Vector4.HorizAdd4
Vector4.HorizAdd4
Brief
Compute the horizontal sum of a 4D vector.
Definition
number Vector4.HorizAdd4(Vector4 v)
Arguments
v - input vector.
Return Values
The sum of the X, Y, Z and W components of the input vector.
Description
Returns v:X() + v:Y() + v:Z() + v:W().
Examples
local v = Vector4.Create (1, 2, 3 , 4)
print(v:HorizAdd4()) � 10
See Also
� Vector4.HorizAdd3
Vector4.Length2
Brief
Calculates the length of a 2-dimensional vector.
Definition
number Vector4.Length2( Vector4 vector )
Arguments
vector - Source vector for the calculation.
Return Values
A number holding the magnitude of the specified 2-dimensional vector.
Description
Calculates the length of the specified 2-dimensional vector.
Vector algebra notation:
vector
or sqrt( vector dot vector)
Descriptive notation:
returnvalue = sqrt( ( vector.x * vector.x ) + ( vector.y * vector.y ))
Examples
vl = Vector4.Create( 1, 2 )
print( "Vector magnitude is: " .. Vector4.Length2( vl ) )
See Also
� Vector4.Create
� Vector4.Length3
� Vector4.Length4
Vector4.Length2Sqr
Brief
Calculates the squared length of a 2-dimensional vector.
Definition
! number Vector4.Length2Sqr( Vector4 vector )
Arguments
vector - Source vector for the calculation.
Return Values
A number holding the squared magnitude of the specified 2-dimensional vector.
Description
Calculates the squared length of the specified 2-dimensional vector.
Vector algebra notation:
( vector dot vector)
Descriptive notation:
returnvalue = ( vector.x * vector.x ) + ( vector.y * vector.y )
Examples
! vl = Vector4.Create( 1, 2 )
j print( "Vector squared magnitude is: " .. Vector4.Length2Sqr( vl ) )
See Also
� Vector4. Create
� Vector4.Length3Sqr
� Vector4.Length4Sqr
� Vector4.Length2
Vector4.Length3
Brief
Calculates the length of a 3-dimensional vector.
Definition
number Vector4.Length3( Vector4 vector )
Arguments
vector - Source vector for the calculation.
Return Values
A number holding the magnitude of the specified 3-dimensional vector.
Description
Calculates the length of the specified 3-dimensional vector.
Vector algebra notation:
vector
or sqrt( vector dot vector)
Descriptive notation:
returnvalue = sqrt( ( vector.x * vector.x ) + ( vector.y * vector.y ) + ( vector.z * vector.z ))
Examples
vl = Vector4.Create ( 1, 2, 3 )
print( "Vector magnitude is: " .. Vector4.Length3( vl ) )
See Also
� Vector4.Create
� Vector4.Length2
� Vector4.Length4
Vector4.Length3Sqr
Brief
Calculates the squared length of a 3-dimensional vector.
Definition
! number Vector4.Length3Sqr( Vector4 vector )
Arguments
vector - Source vector for the calculation.
Return Values
A number holding the squared magnitude of the specified 3-dimensional vector.
Description
Calculates the squared length of the specified 3-dimensional vector.
Vector algebra notation:
( vector dot vector)
Descriptive notation:
retumvalue = ( vector.x * vector.x ) + ( vector.y * vector.y ) + ( vector.z * vector.z )
Examples
vl = Vector4.Create( 1 , 2, 3 )
print( "Vector squared magnitude is: " .. Vector4.Length34Sqr( vl ) )
See Also
� Vector4.Create
� Vector4.Length2Sqr
� Vector4.Length4Sqr
� Vector4.Length3
Vector4.Length4
Brief
Calculates the length of a 4-dimensional vector.
Definition
! number Vector4.Length4( Vector4 vector )
Arguments
vector - Source vector for the calculation.
Return Values
A number holding the magnitude of the specified 4-dimensional vector.
Description
Calculates the length of the specified 4-dimensional vector.
Vector algebra notation:
vector
or sqrt( vector dot vector)
Descriptive notation:
returnvalue = sqrt( ( vector.x * vector.x ) + ( vector.y * vector.y ) + ( vector.z * vector.z ) + ( vector.w * vector.w ))
Examples
vl = Vector4.Create( 1, 2, 3, 4 )
print( "Vector magnitude is: " .. Vector4.Length4( vl ) )
See Also
� Vector4.Create
� Vector4.Length2
� Vector4.Length3
Vector4.Length4Sqr
Brief
Calculates the squared length of a 4-dimensional vector.
Definition
! number Vector4.Length4Sqr( Vector4 vector )
Arguments
vector - Source vector for the calculation.
Return Values
A number holding the squared magnitude of the specified 4-dimensional vector.
Description
Calculates the squared length of the specified 4-dimensional vector.
Vector algebra notation:
( vector dot vector)
Descriptive notation:
returnvalue = ( vector.x * vector.x ) + ( vector.y * vector.y ) + ( vector.z * vector.z ) + ( vector.w * vector.w )
Examples
j vl = Vector4.Create( 1, 2 , 3 , 4 )
I print( "Vector squared magnitude is: " .. Vector4.Length4Sqr( vl ) )
See Also
� Vector4. Create
� Vector4.Length2Sqr
� Vector4.Length3Sqr
� Vector4.Length4
Vector4.Max
Brief
Compute the maximum element values of two vectors.
Definition
! Vector4.Max(Vector4 dest, Vector4 sourcel, Vector4 source2)
Arguments
dest - Vector to hold result. May be the same vector as either of source vectors if desired.sourcel - First source vector.source2 - Second source
vector.
Return Values
None.
Description
Compares each element in sourcel with equivalent element in source2 and stores the greater value in the equivalent element of dest. That is:
dest =
Unknown macro: { max(source1 .x, source2.x), max(source1 .y, source2.y), max(source1 .z, source2.z), max(source1 .w, source2.w)}
Examples
� assuming verts is an array of Vector4 values
local min = Vector4.Create(Const.MaxNum, Const.MaxNum, Const.MaxNum)
local max = Vector4.Create(-Const.MaxNum, -Const.MaxNum, -Const.MaxNum)
for i = 1, numVerts do
Vector4.Min(min, min, verts[i])
Vector4.Max(max, max, verts[i])
end
� min and max now store bounds of vert list
See Also
� Vector4.Min
� StreamOps.BoundsVec4
Vector4.Min
Brief
Compute the minimum element values of two vectors.
Definition
Vector4.Min(Vector4 dest, Vector4 sourcel, Vector4 source2)
Arguments
dest - Vector to hold result. May be the same vector as either of source vectors if desired.sourcel - First source vector.source2 - Second source
vector.
Return Values
None.
Description
Compares each element in sourcel with equivalent element in source2 and stores the lower value in the equivalent element of dest. That is:
dest =
Unknown macro: { min(source1.x, source2.x), min(source1 .y, source2.y), min(source1 .z, source2.z), minfsourcel .w, source2.w)}
Examples
� assuming verts is an array of Vector4 values
local min = Vector4.Create(Const.MaxNum, Const.MaxNum, Const.MaxNum)
local max = Vector4.Create(-Const.MaxNum, -Const.MaxNum, -Const.MaxNum)
for i = 1, numVerts do
Vector4.Min(min, min, verts[i])
Vector4.Max(max, max, verts[i])
end
� min and max now store bounds of vert list
See Also
� Vector4.Max
� StreamOps.BoundsVec4
Vector4.Multiply
Brief
Multiplies two vectors or scalars together storing the result as a vector.
Definition
Vector4.Multiply( Vector4 destination, Vector4|number sourcel, Vector4|number source2 )
Arguments
destination - Vector to store the result of the multiplication.sourcel - The first argument for the multiplication, can be a Vector4 or a scalar.source2
- The second argument for the multiplication, can be a Vector4 or a scalar.
Return Values
None.
Description
Multiplies sourcel and source2 together storing the result in the destination vector.
Descriptive notation:
destination.x = sourcel .x|source1 * source2.x|source2
destination.y = sourcel ,y|source1 * source2.y|source2
destination.z = sourcel ,z|source1 * source2.z|source2
destination.w = sourcel.w|source1 * source2.w|source2
Examples
result = Vector4.Create()
vl = Vector4.Create( 1, 2, 3, 4 )
v2 = Vector4.Create( 4, 3, 2, 1 )
Vector4.Multiply( result, vl, v2 )
Vector4.Multiply( result, vl, 4.0 )
Vector4.Multiply( result, -3.0, v2 )
Vector4.Multiply( result, -3.0, 4 )
See Also
Vector4. Create
Vector4.MultiplyAdd
Brief
Multiplies two vectors together and then adds the third vector.
Definition
Vector4.MultiplyAdd( Vector4 destination, Vector4|number sourcel, Vector4|number source2,
Vector4|number source3 )
Arguments
destination - Vector to store the result of the multiplication.sourcel - The first vector argument for the multiplication.source2 - The second vector
argument for the multiplication.source3 - The third vector argument for the addition.
Return Values
None.
Description
Multiplies sourcel and source2 together and then adds the third vector, storing the result in destination.
Descriptive notation:
destination.x = ( sourcel.x|source1 * source2.x|source2 ) + source3.x|source3
destination.y = ( sourcel.y|source1 * source2.y|source2 ) + source3.y|source3
destination.z = ( sourcel.z|source1 * source2.z|source2 ) + source3.z|source3
destination.w = ( sourcel .w]source1 * source2.w|source2 ) + source3.w|source3
Examples
result = Vector4.Create()
vl = Vector4.Create( 1, 2, 3, 4 )
v2 = Vector4.Create( 4, 3, 2, 1 )
v3 = Vector4.Create( 1, 0, 0, 1 )
Vector4.MultiplyAdd( result, vl, v2, v3 )
Vector4.MultiplyAdd( result, 1, 2, 6 )
See Also
� Vector4.Create
Vector4.Negate
Brief
Negate a vector in-place.
Definition
Vector4.Negate(Vector4 v)
Arguments
v - vector to negate.
Return Values
None.
Description
Sets v to -v.
Examples
! local v = Vector4.Create(1, 2, 3)
! v:Negate()
| print(v) � [-1, - 2 , -3]
See Also
None
Vector4.Normal2
Brief
Returns the normalization of a 2-dimensional vector.
Definition
Vector4 Vector4.Normal2( Vector4 vector )
Arguments
vector - The vector to normalize.
Return Values
A new Vector4 instance containing a normalized copy of the source vector.
Description
Returns the normalization of the specified 2-dimensional vector (i.e. a new vector of unit length). The source vector is not modified.
Descriptive notation:
length = sqrt( src.x * src.x + src.y * src.y )
returnvec.x = src.x / length
returnvec.y = src.y / length
retumvec.z = 0
returnvec.w = 0
Examples
| vec = Vector4.Create( 1, 2 )
; result = Vector4.Normal2( vec )
j print( result )
See Also
Vector4.Create
� Vector4.Normal3
� Vector4.Normal4
Vector4.Normal3
Brief
Returns the normalization of a 3-dimensional vector.
Definition
! Vector4 Vector4.Normal3( Vector4 src )
Arguments
src - The vector to use as a source to normalize.
Return Values
A new Vector4 instance containing a normalized copy of the source vector.
Description
Returns the normalization of the specified 3-dimensional vector (i.e. a new vector of unit length). The source vector is not modified.
Descriptive notation:
length = sqrt( src.x*src.x + src.y*src.y + src.z*src.z )
returnvec.x = src.x / length
returnvec.y = src.y / length
retumvec.z = src.z / length
retumvec.w = 0
Examples
j vec = Vector4.Create( 1, 2, 3 )
; result = Vector4.Normal3( vec )
j print( result )
See Also
� Vector4.Create
� Vector4.Normal2
� Vector4.Normal4
Vector4.Normal4
Brief
Returns the normalization of a 4-dimensional vector.
Definition
Vector4 Vector4.Normal4( Vector4 src )
Arguments
src - The vector to use as a source to normalize.
Return Values
A new Vector4 instance containing a normalized copy of the source vector.
Description
Returns the normalization of the specified 4-dimensional vector (i.e. a new vector of unit length). The source vector is not modified.
Descriptive notation:
length = sqrt( src.x*src.x + src.y*src.y + src.z*src.z + src.w*src.w )
returnvec.x = src.x / length
returnvec.y = src.y / length
returnvec.z = src.z / length
returnvec.w = src.z / length
Examples
j vec = Vector4.Create( 1, 2 , 3, 4 )
; result = Vector4.Normal4( vec )
| print( result )
See Also
� Vector4. Create
� Vector4.Normal2
� Vector4.Normal3
Vector4.Normalize2
Brief
Normalizes a vector using Length2 of that vector.
Definition
! Vector4.Normalize2( Vector4 vector )
Arguments
vector - The vector to normalize.
Return Values
None.
Description
Normalizes the specified vector using Length2 of the vector.
Descriptive notation:
length = sqrt( vector.x*vector.x + vector.y'vector.y )
vector.x = vector.x / length
vector.y = vector.y / length
vector.z = 0
vector.w = 0
Examples
! vector = Vector4.Create( 1, 3 , 2 , 4 )
! Vector4.Normalize2( vector )
| print( vector )
See Also
� Vector4.Create
� Vector4.Normalize3
� Vector4.Normalize4
Vector4.Normalizes
Brief
Normalizes a vector using Length3 of that vector.
Definition
! Vector4.Normalize3( Vector4 vector )
Arguments
vector - The vector to normalize.
Return Values
None.
Description
Normalizes the specified vector using Length3 of the vector.
Descriptive notation:
length = sqrt( vector.x*vector.x + vector.y'vector.y + vector.z*vector.z )
vector.x = vector.x / length
vector.y = vector.y / length
vector.z = vector.z / length
vector.w = 0
Examples
vector = Vector4.Create ( 1 , 3 , 2 , 4 )
Vector4.Normalize3( vector )
print ( vector )
See Also
� Vector4.Create
� Vector4.Normalize2
� Vector4.Normalize4
Vector4.Normalize4
Brief
Normalizes a vector using Length4 of that vector.
Definition
Vector4.Normalize4( Vector4 vector )
Arguments
vector - The vector to normalize.
Return Values
None.
Description
Normalizes the specified vector using Length4 of the vector.
Descriptive notation:
length = sqrt( vector.x*vector.x + vector.y'vector.y + vector.z*vector.z + vector.w'vector.w )
vector.x = vector.x / length
vector.y = vector.y / length
vector.z = vector.z / length
vector.w = vector.w / length
Examples
j vector = Vector4.Create( 1 , 3 , 2 , 4 )
I Vector4.Normalize4( vector )
| print( vector )
See Also
� Vector4. Create
� Vector4.Normalize2
� Vector4. Normalizes
Vector4.Recip
Brief
Compute the component-wise reciprocal of a vector.
Definition
Vector4.Recip(Vector4 dest, Vector4 v)
Arguments
dest - destination vector to store result.v - input vector.
Return Values
None.
Description
Sets dest to [1 / v:X(), 1 / v:Y(), 1 / v:Z(), 1 / v:W()]. If any elements of v are 0 the result is undefined. Note that due to floating point arithmetic
precision, Recip(Recip^) is not necessarily x.
Examples
j local v = Vector4.Create (-1, 2, -3)
I v:Recip(v)
| print(v) � [-1, 0.5, -0.333333]
See Also
� Vector4.RecipSqrt
Vector4.RecipSqrt
Brief
Compute the component-wise reciprocal square root of a vector.
Definition
Vector4.RecipSqrt(Vector4 dest, Vector4 v)
Arguments
dest - destination vector to store result.v - input vector.
Return Values
None.
Description
Sets dest to [1 / math.sqrt(v:X()), 1 / math.sqrt(v:Y()), 1 / math.sqrt(v:Z()), 1 / math.sqrt(v:W()]. If any elements of v are <= 0 the result is
undefined. This operation is faster than the equivalent combination of Sqrt and Recip.
Examples
local v = Vector4.Create(1, 4, 9)
v:RecipSqrt(v)
print(v) � [1, 0.5, 0.333333]
See Also
� Vector4.Recip
� Vector4.Sqrt
Vector4. Rotate
Brief
Rotate a vector about and axis.
Definition
Vector4.Rotate( Vector4 destination, Vector4 source, Vector4 axis, number angle )
Arguments
destination - Vector to store the result of the rotation.source - Vector to be rotated.axis - Axis to rotate about.angle - Angle (in degrees) to rotate
by.
Return Values
Description
Rotate a vector about and axis.
Examples
src = Vector4.Create( 12, 2, -3 )
axis = Vector4.Create( 0, 0.707, -0.707 )
dst = Vector4.Create()
Vector4.Rotate( dst, src, axis, 45 )
See Also
� Vector4. Create
Vector4.SetBroadcast
Brief
Sets the all of the vector's elements to the specified value.
Definition
Vector4 Vector4.SetBroadcast( Vector4 vector, number value )
Arguments
vector - Vector to be set.value - The value to broadcast to all the elements of the vector.
Return Values
None.
Description
Sets the all of the vector's elements to the specified value.
Examples
vecHalf = Vector4.Create()
Vector4.SetBroadcast( vecHalf, 0.5 )
vec = Vector4.Create( 1, 2, 3 )
Vector4.Multiply( vec, vec, vecHalf )
See Also
� Vector4.Create
� Vector4.CreateBroadcast
Vector4.SetW
Brief
Sets the w value of the vector.
Definition
Vector4.SetW( Vector4 vector, number value )
Arguments
vector - Vector to be set.value - A numerical value that is copied into the w component of the vector.
Return Values
None.
Description
Sets the w value of the vector.
Examples
j vec = Vector4.Create( 1, 2, 3, 4 )
! Vector4.SetW( vec, 6 )
See Also
� Vector4. Create
� Vector4.SetX
� Vector4.SetY
Vector4.SetZ
Vector4.SetX
Brief
Sets the x value of the vector.
Definition
Vector4.SetX( Vector4 vector, number value )
Arguments
vector - Vector to be set.value - A numerical value that is copied into the x component of the vector.
Return Values
None.
Description
Sets the x value of the vector.
Examples
j vec = Vector4.Create( 1, 2, 3, 4 )
i Vector4.SetX( vec, 6 )
See Also
� Vector4.Create
� Vector4.SetY
� Vector4.SetZ
� Vector4.SetW
Vector4.SetXyzw
Brief
Sets a Vector4 object with the specified values.
Definition
! Vector4.SetXyzw( Vector4 vector, number x = 0, number y = 0, number z = 0, number w = 0 )
Arguments
vector - Vector to be set.x - Number to be written into the first element of the vector (defaults to 0).y - Number to be written into the second
element of the vector (defaults to 0).z - Number to be written into the third element of the vector (defaults to 0).w - Number to be written into the
fourth element of the vector (defaults to 0).
Return Values
None.
Description
Sets a Vector4 object with the specified values.
Examples
vec = Vector4.Create()
Vector4.SetXyzw( vec, 1, 2, 3, 4 )
See Also
� Vector4.Create
Vector4.SetY
Brief
Sets the y value of the vector.
Definition
1 Vector4.SetY( Vector4 vector, number value )
Arguments
vector - Vector to be set.value - A numerical value that is copied into the y component of the vector.
Return Values
None.
Description
Sets the y value of the vector.
Examples
vec = Vector4.Create( 1, 2, 3, 4 )
Vector4.SetY( vec, 6 )
See Also
� Vector4.Create
� Vector4.SetX
� Vector4.SetZ
� Vector4.SetW
Vector4.SetZ
Brief
Sets the z value of the vector.
Definition
Vector4.SetZ( Vector4 vector, number value )
Arguments
vector - Vector to be set.value - A numerical value that is copied into the z component of the vector.
Return Values
None.
Description
Sets the z value of the vector.
Examples
j vec = Vector4.Create( 1, 2, 3, 4 )
: Vector4.SetZ( vec, 6 )
See Also
� Vector4.Create
� Vector4.SetX
� Vector4.SetY
� Vector4.SetW
Vector4.Sign
Brief
Compute the sign (-1 or 1) of all elements in a vector.
Definition
! Vector4.Sign(Vector4 dest, Vector4 v)
Arguments
dest - destination vector to store result.v - input vector.
Return Values
None.
Description
Each element of dest is set to the sign (-1 or 1) of the equivalent element of v. 0 is considered positive and thus becomes 1, if a separate 0 value
is required use the Signum function.
Examples
j local v = Vector4.Create (-3.1, 0, -0.4, 1.2)
i v:Sign(v)
j print (v) � [-1, 1, -1, 1]
See Also
Vector4.Signum
Vector4.Signum
Brief
Compute the sign (-1,0 or 1) of all elements in a vector.
Definition
! Vector4.Signum(Vector4 dest, Vector4 v)
Arguments
dest - destination vector to store result.v - input vector.
Return Values
None.
Description
Each element of dest is set to the sign (-1,0 or 1) of the equivalent element of v. If a separate 0 value is not required, use the Sign function.
Examples
! local v = Vector4.Create(-3.1, 0, -0.4, 1.2)
i v:Signum(v)
| print (v) � [-1, 0, -1, 1]
See Also
� Vector4.Sign
Vector4.Sqrt
Brief
Compute the component-wise square root of a vector.
Definition
j Vector4.Sqrt(Vector4 dest, Vector4 v)
Arguments
dest - destination vector to store result.v - input vector.
Return Values
None.
Description
Sets dest to [math.sqrt(v:XQ), math.sqrt(v:Y()), math.sqrt(v:Z()), math.sqrt(v:W())]. If any elements of v are < 0 the result is undefined.
Examples
local v = Vector4.Create(1, 4, 9)
v: Sqrt (v)
print (v) � [1, 2, 3]
See Also
� Vector4.RecipSqrt
Vector4.Subtract
Brief
Subtracts one vector from another.
Definition
Vector4.Subtract( Vector4 destination, Vector4|number sourcel, Vector4|number source2 )
Arguments
destination - Vector to store the result of the subtraction.sourcel - The minuend for the subtraction.source2 - The subtrahend for the subtraction.
Return Values
None.
Description
Subtracts source2 from sourcel storing the result in destination.
Descriptive notation:
destination.x = sourcel .x|source1 - source2.x|source2
destination.y = sourcel ,y|source1 - source2.y|source2
destination.z = sourcel .z|source1 - source2.z|source2
destination.w = sourcel.w|source1 - source2.w|source2
Examples
result = Vector4.Create()
vl = Vector4.Create( 1, 2 , 3, 4 )
v2 = Vector4.Create( 4 , 3, 2 , 1 )
Vector4.Subtract( result, vl, v2 )
Vector4.Subtract( result, vl, 3 )
See Also
� Vector4.Create
Vector4.T ransform
Brief
Transforms a vector by a matrix.
Definition
Vector4.Transform( Vector4 destination, Matrix44 matrix, Vector4 source )
Vector4.Transform( table destination, Matrix44 matrix, table source )
Arguments
destination - Vector or table of vectors to store the result of the multiplication.matrix - Matrix to transform the source vector or table of
vectors.source - Vector or table of vectors to be transformed.
Return Values
Description
Transforms the specified source vector by a matrix and stores the resultant vector in the destination. It is equivalent to:
destination = matrix * source
It is also possible to transform a table of vectors by the specified matrix. The result is stored in a destination table with the same number of
vectors as the source table. This can be considerably faster than transforming vectors individually.
Examples
� Create the matrix for the example code below
matrix = Matrix44.Create()
Matrix44.SetRotationXyz( matrix, 45, 12, 7 )
� Example 1: Transform a single vector by a matrix
src = Vector4.Create ( 12, 2, -3, 1 )
dst = Vector4.Create ()
Vector4.Transform( dst, matrix, src )
� Example 2: Transform a table of vectors by a matrix
source = {}
destination = {}
for v = 1, 10 do
source[v] = Vector4.Create(v, v, v, v)
destination[v] = Vector4.Create ()
end
Vector4.Transform( destination, matrix, source )
See Also
� Matrix44. Create
� Vector4. Create
Vector4.TransformPoint
Brief
Transforms a point by a matrix.
Definition
Vector4.TransformPoint( Vector4 destination, Matrix44 matrix, Vector4 source )
Vector4.TransformPoint( table destination, Matrix44 matrix, table source )
Arguments
destination - Point or table of points to store the result of the multiplication.matrix - Matrix to transform the source vector or table of vectors.source
- Point or table of points to be transformed.
Return Values
Description
Transforms the specified source point by a matrix and stores the resultant point in the destination. It is equivalent to:
destination = matrix * source (where source.w is substituted with 1.0)
It is also possible to transform a table of points by the specified matrix. The result is stored in a destination table with the same number of points
as the source table. This can be considerably faster than transforming points individually.
Examples
� Create the matrix for the example code below
matrix = Matrix44.Create()
Matrix44.SetRotationXyz( matrix, 45, 12, 7 )
� Example 1: Transform a single point by a matrix
src = Vector4.Create ( 12, 2, -3 )
dst = Vector4.Create ()
Vector4.TransformPoint( dst, matrix, src )
� Example 2: Transform a table of points by a matrix
source = {}
destination = {}
for v = 1, 10 do
source[v] = Vector4.Create(v, v, v)
destination[v] = Vector4.Create ()
end
Vector4.TransformPoint( destination, matrix, source )
See Also
� Matrix44.Create
� Vector4.Create
Vector4.T ransform Vector
Brief
Transforms a vector by a matrix.
Definition
Vector4.TransformVector( Vector4 destination, Matrix44 matrix, Vector4 source )
Vector4.TransformVector( table destination, Matrix44 matrix, table source )
Arguments
destination - Vector or table of vectors to store the result of the multiplication.matrix - Matrix to transform the source vector or table of
vectors.source - Vector or table of vectors to be transformed.
Return Values
Description
Transforms the specified source vector by a matrix and stores the resultant vector in the destination. It is equivalent to:
destination = matrix * source (where source.w is substituted with 0.0)
It is also possible to transform a table of vectors by the specified matrix. The result is stored in a destination table with the same number of
vectors as the source table. This can be considerably faster than transforming vectors individually.
Examples
� Create the matrix for the example code below
matrix = Matrix44.Create()
Matrix44.SetRotationXyz( matrix, 45, 12, 7 )
� Example 1: Transform a single vector by a matrix
src = Vector4.Create ( 12, 2, -3 )
dst = Vector4.Create ()
Vector4.TransformVector( dst, matrix, src )
� Example 2: Transform a table of vectors by a matrix
source = {}
destination = {}
for v = 1, 10 do
source[v] = Vector4.Create(v, v, v)
destination[v] = Vector4.Create ()
end
Vector4.TransformVector( destination, matrix, source )
See Also
� Matrix44.Create
� Vector4.Create
Vector4.W
Brief
Returns the w value of the vector.
Definition
! number Vector4.W( Vector4 vector )
Arguments
vector - Vector to be queried.
Return Values
Returns the fourth element of the vector, the w component.
Description
Returns the w value of the vector.
Examples
j vec = Vector4.Create( 1, 2, 3, 4 )
j print( "Value of W is: " .. Vector4.W( vec ) )
See Also
� Vector4.Create
� Vector4.X
� Vector4.Y
� Vector4.Z
Vector4.X
Brief
Returns the x value of the vector.
Definition
! number Vector4.X( Vector4 vector )
Arguments
vector - Vector to be queried.
Return Values
The first element of the vector, the x component.
Description
Returns the x value of the vector.
Examples
j vec = Vector4.Create( 10 )
i print( "Value of X is: " .. Vector4.X( vec ) )
See Also
� Vector4.Create
� Vector4.Y
� Vector4.Z
� Vector4.W
Vector4.Y
Brief
Returns the y value of the vector.
Definition
! number Vector4.Y( Vector4 vector )
Arguments
vector - Vector to be queried.
Return Values
Returns the second element of the vector, the y component.
Description
Returns the y value of the vector.
Examples
vec = Vector4.Create( 1, 2 )
print( "Value of Y is: " .. Vector4.Y( vec ) )
See Also
� Vector4.Create
� Vector4.X
� Vector4.Z
� Vector4.W
Vector4.Z
Brief
Returns the z value of the vector.
Definition
! number Vector4.Z( Vector4 vector )
Arguments
vector - Vector to be queried.
Return Values
Returns the third element of the vector, the z component.
Description
Returns the z value of the vector.
Examples
vec = Vector4.Create( 1, 2, 3 )
print( "Value of Z is: " .. Vector4.Z( vec ) )
See Also
� Vector4.Create
� Vector4.X
� Vector4.Y
� Vector4.W