Difference between revisions of "IC Python API:RLPy RVector3"

From Reallusion Wiki!
Jump to: navigation, search
(Created page with "{{TOC}} {{Parent|IC_Python_API:RL_Python_Modules|Modules}} == Detailed Description == This class represent the 3D vector. == Member Functions == === AlmostTheSame === <sy...")
 
m
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{TOC}}
 
{{TOC}}
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
 +
{{last_modified}}
  
== Detailed Description ==
+
== Description ==
  
This class represent the 3D vector.
+
This class represent the 3D vector (x, y, z). This class provides access to RLPy's internal 3D vector math library allowing 3D vectors to be handled easily, in a manner compatible with internal RLPy data structures. It also supports operators and provides some constants for your convenience:
  
== Member Functions ==
+
{|class = "wikitable"
 +
!Constant
 +
!Description
 +
|-
 +
|RVector3.ZERO
 +
|3D zero vector: (0, 0, 0)
 +
|-
 +
|RVector3.UNIT_X
 +
|3D x unit vector: (1, 0, 0)
 +
|-
 +
|RVector3.UNIT_Y
 +
|3D y unit vector: (0, 1, 0)
 +
|-
 +
|RVector3.UNIT_Z
 +
|3D z unit vector: (0, 0, 1)
 +
|-
 +
|RVector3.UNIT_XY
 +
|3D vector: (1, 1, 0)
 +
|-
 +
|RVector3.UNIT_YZ
 +
|3D vector: (0, 1, 1)
 +
|-
 +
|RVector3.UNIT_XZ
 +
|3D vector: (1, 0, 1)
 +
|-
 +
|RVector3.UNIT_XYZ
 +
|3D vector: (1, 1, 1)
 +
|}
  
=== AlmostTheSame ===
+
== Constructor & Destructor ==
  
<syntaxhighlight lang="Python">
+
=== __init__ ( self ) ===
RLPy.RVector3.AlmostTheSame ( self, vV )
+
 
 +
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3()
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Determine the two vectors are the same with tolerance.
+
=== __init__ ( self, x, y, z ) ===
  
==== Returns ====
+
==== Parameters ====
 +
:'''x''' [IN] A numerical value for x coordinate - float or int
 +
:'''y''' [IN] A numerical value for y coordinate - float or int
 +
:'''z''' [IN] A numerical value for z coordinate - float or int
  
true if the vector is almost the same - bool
+
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(1, 2, 3)
 +
</syntaxhighlight>
  
=== AlmostZero ===
+
=== __init__ ( self, args ) ===
  
<syntaxhighlight lang="Python">
+
The constructor. Initialize a new [[IC_Python_API:RLPy_RVector3|RVector3]]object with another [[IC_Python_API:RLPy_RVector3|RVector3]]object: args. This new [[IC_Python_API:RLPy_RVector3|RVector3]]object has the same value as args.
RLPy.RVector3.AlmostZero ( self)
+
 
 +
==== Parameters ====
 +
:'''args''' [IN] a [[IC_Python_API:RLPy_RVector3|RVector3]]object - [[IC_Python_API:RLPy_RVector3|RVector3]]
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(1, 2, 3)
 +
b = RLPy.RVector3(a)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Determine the vector is zero vector.
+
== Operators ==
  
==== Returns ====
+
=== == ===
 +
 
 +
The "equal to" operator.
  
true if the vector is zero vector - bool
+
See Also: [[#!=|!=]]
  
=== Cross ===
+
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(1, 2, 3)
 +
b = a
  
<syntaxhighlight lang="Python">
+
print(a == b) #True
RLPy.RVector3.Cross ( self, vV )
+
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Calculate cross production of the two vectors.
+
=== != ===
  
==== Parameters ====
+
The "not equal to" operator.
  
vV[IN] The vector - RLPy.RVector3
+
See Also: [[#==|==]]
  
==== Returns ====
+
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3()
 +
b = RLPy.RVector3(1, 2, 3)
  
New vector which is the cross product of the two vectors - RLPy.RVector3
+
print(a != b) #True
 +
</syntaxhighlight>
  
=== Distance ===
+
=== < ===
  
<syntaxhighlight lang="Python">
+
The "less than" operator. Similar to string comparison: Returns '''True''' upon the first match that is less than and '''False''' if it is greater than.  If the current comparison is equal, continue onto the next element.  If all elements are equal then return '''False'''.
RLPy.RVector3.Distance ( self, vV )
+
 
 +
See Also: [[#<=|<=]]
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(0, 1, 5)
 +
b = RLPy.RVector3(0, 2, 0)
 +
c = RLPy.RVector3(1, 0, 1)
 +
d = RLPy.RVector3(0, 1, 5)
 +
 
 +
print(a < b) #True
 +
print(b < c) #True
 +
print(a < d) #False
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Distance of the two vectors.
+
=== > ===
  
==== Parameters ====
+
The "greater than" operator. Similar to string comparison: Returns '''True''' upon the first match that is greater than and '''False''' if it is less than.  If the current comparison is equal, continue onto the next element.  If all elements are equal then return '''False'''.
  
vV[IN] The vector - RLPy.RVector3
+
See Also: [[#>=|>=]]
  
==== Returns ====
+
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(0, 1, 5)
 +
b = RLPy.RVector3(0, 1, 7)
 +
c = RLPy.RVector3(1, 0, 1)
 +
d = RLPy.RVector3(0, 1, 5)
 +
 
 +
print(b > a) #True
 +
print(c > b) #True
 +
print(d > a) #False
 +
</syntaxhighlight>
 +
 
 +
=== <= ===
 +
 
 +
The "less than or equal" operator. Similar to string comparison: Returns '''True''' upon the first match that is less than and '''False''' if it is greater than.  If the current comparison is equal, continue onto the next element.  If all elements are equal then return '''True'''.
  
the distance - float
+
See Also: [[#<|<]]
  
=== Dot ===
+
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(0, 1, 5)
 +
b = RLPy.RVector3(0, 2, 0)
 +
c = RLPy.RVector3(1, 0, 1)
 +
d = RLPy.RVector3(0, 1, 5)
  
<syntaxhighlight lang="Python">
+
print(a<= b) #True
RLPy.RVector3.Dot ( self, vV )
+
print(b<= c) #True
 +
print(a<= d) #True
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Calculate dot production of the two vectors.
+
=== >= ===
  
==== Parameters ====
+
The "greater than or equal" operator. Similar to string comparison: Returns '''True''' upon the first match that is greater than and '''False''' if it is less than.  If the current comparison is equal, continue onto the next element.  If all elements are equal then return '''True'''.
  
vV[IN] The vector - RLPy.RVector3
+
See Also: [[#>|>]]
  
==== Returns ====
+
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(0, 1, 5)
 +
b = RLPy.RVector3(0, 1, 7)
 +
c = RLPy.RVector3(1, 0, 1)
 +
d = RLPy.RVector3(0, 1, 5)
  
the value of the dot production - float
+
print(b >= a) #True
 +
print(c >= b) #True
 +
print(d >= a) #True
 +
</syntaxhighlight>
  
=== Interpolate ===
+
=== + ===
  
<syntaxhighlight lang="Python">
+
The "addition" operator. Perform 3D vector addition.
RLPy.RVector3.Interpolate ( self, vRatio, vV )
+
 
 +
See Also: [[#+=|+=]]
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(0, 1, 2)
 +
b = RLPy.RVector3(1, 2, 3)
 +
c = a + b
 +
 
 +
print(str(c.x) + ', ' + str(c.y) + ', ' + str(c.z)) #1.0, 3.0, 5.0
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Interpolate of the two vectors.
+
=== - ===
  
==== Parameters ====
+
The "subtraction" operator. Perform 3D vector subtraction.
  
vRatio[IN] ratio value - float
+
See Also: [[#-=|-=]]
vV[IN] The vector - RLPy.RVector3
+
  
==== Returns ====
+
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(0, 1, 2)
 +
b = RLPy.RVector3(3, 2, 1)
 +
c = b - a
  
New vector which is the cross product of the two vectors - RLPy.RVector3
+
print(str(c.x) + ', ' + str(c.y) + ', ' + str(c.z)) #3.0, 1.0, -1.0
 +
</syntaxhighlight>
  
=== Inverse ===
+
=== * ===
  
<syntaxhighlight lang="Python">
+
The "multiplication" operator. Perform a scalar multiplication when the second operand is an integer or float. If the second operand is another 3D vector, then the respective x, y, z elements are multiplied.
RLPy.RVector3.Inverse ( self)
+
 
 +
See Also: [[#*=|*=]]
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(1, 2, 3)
 +
b = a * 2
 +
c = a * a
 +
 
 +
print(str(b.x) + ', ' + str(b.y) + ', ' + str(b.z)) #2.0, 4.0, 6.0
 +
print(str(c.x) + ', ' + str(c.y) + ', ' + str(c.z)) #1.0, 4.0, 9.0
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Inverse this vector.
+
=== / ===
  
==== Returns ====
+
The "division" operator. Perform a scalar division when the second operand is an integer or float. If the second operand is another 3D vector, then the respective x, y, z elements are divided.
  
the inversed vector - RLPy.RVector3
+
See Also: [[#/=|/=]]
  
=== Length ===
+
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(1, 2, 3)
 +
b = a / 2
 +
c = RLPy.RVector3(2, 2, 10)
 +
d = a / c
  
<syntaxhighlight lang="Python">
+
print(str(b.x) + ', ' + str(b.y) + ', ' + str(b.z)) #0.5, 1.0, 1.5
RLPy.RVector3.Length ( self)
+
print(str(d.x) + ', ' + str(d.y) + ', ' + str(d.z)) #0.5, 1.0, 0.3
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Length of the vector.
+
=== - ===
  
==== Returns ====
+
The "unary minus" operator. Inverse the sign of each element.
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(1, 2, 3)
 +
b = -a
 +
 
 +
print(str(b.x) + ', ' + str(b.y) + ', ' + str(b.z)) #-1.0, -2.0, -3.0
 +
</syntaxhighlight>
 +
 
 +
=== += ===
 +
 
 +
The "addition assignment" operator.
  
the length of this vector - float
+
See Also: [[#+|+]]
  
=== Normalize ===
+
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(0, 1, 2)
 +
b = RLPy.RVector3(1, 2, 3)
 +
a += b
  
<syntaxhighlight lang="Python">
+
print(str(a.x) + ', ' + str(a.y)+ ', ' + str(a.z)) #1.0, 3.0, 5.0
RLPy.RVector3.Normalize ( self)
+
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Normalizes this vector.
+
=== -= ===
  
==== Returns ====
+
The "subtraction assignment" operator.
  
the normalized vector - float
+
See Also: [[#-|-]]
  
=== SetX ===
+
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(0, 1, 4)
 +
b = RLPy.RVector3(1, 2, 3)
 +
a -= b
  
<syntaxhighlight lang="Python">
+
print(str(a.x) + ', ' + str(a.y) + ', ' + str(a.z)) #-1.0, -1.0, 1.0
RLPy.RVector3.SetX ( self, tX )
+
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Set the value of the x-axis.
+
=== *= ===
  
==== Parameters ====
+
The "multiplication assignment" operator. For calculation method, refer to the '''*''' operator.
  
tX[IN] the value of the x-axis - float
+
See Also: [[#*|*]]
  
=== SetXYZ ===
+
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(1, 2, 3)
 +
a *= 2
 +
b = RLPy.RVector3(1, 2, 3)
 +
c = RLPy.RVector3(2, 3, 4)
 +
b *= c
  
<syntaxhighlight lang="Python">
+
print(str(a.x) + ', ' + str(a.y) + ', ' + str(a.z)) #2.0, 4.0, 6.0
RLPy.RVector3.SetXYZ ( self, tX, tY, tZ )
+
print(str(b.x) + ', ' + str(b.y) + ', ' + str(b.z)) #2.0, 6.0, 12.0
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Set the value of the all axes.
+
=== /= ===
 +
 
 +
The "division assignment" operator. For calculation method, refer to the '''/''' operator.
 +
 
 +
See Also: [[#/|/]]
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(1, 2, 3)
 +
a /= 2
 +
b = RLPy.RVector3(1, 2, 3)
 +
c = RLPy.RVector3(2, 4, 2)
 +
b /= c
 +
 
 +
print(str(a.x) + ', ' + str(a.y) + ', ' + str(a.z)) #0.5, 1.0, 1.5
 +
print(str(b.x) + ', ' + str(b.y) + ', ' + str(b.z)) #0.5, 0.5, 1.5
 +
</syntaxhighlight>
 +
 
 +
== Member Functions ==
 +
 
 +
=== AlmostTheSame ( self, vV ) ===
 +
 
 +
Determine if this and another 3D vector is the equivalent withing a tolerance.
 +
 
 +
==== Returns ====
 +
:'''True''' if the 3D vectors are almost the same, else '''False''' - bool
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(1, 2, 3)
 +
b = RLPy.RVector3(1, 2, 3.000000001)
 +
c = RLPy.RVector3(1, 2, 3.00001)
 +
 
 +
if a.AlmostTheSame(b):  #True
 +
    print("a ≈ b")
 +
if a.AlmostTheSame(c):  #False
 +
    print("a ≈ c")
 +
</syntaxhighlight>
 +
 
 +
=== AlmostZero ( self ) ===
 +
 
 +
Determine if this 3D vector is a zeroed 3D vector.
 +
 
 +
==== Returns ====
 +
:'''True''' if this 3D vector is a zeroed 3D vector, else '''False''' - bool
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(0.00000001, 0, 0.00000003)
 +
b = RLPy.RVector3(0.00001, 0, 0)
 +
 
 +
if a.AlmostZero():                #True
 +
    print("a is ZERO vector.")
 +
if b.AlmostZero():                #False
 +
    print("a is ZERO vector.")
 +
</syntaxhighlight>
 +
 
 +
=== Cross ( self, vV ) ===
 +
 
 +
Calculate the cross production of this and another 3D vector.
  
 
==== Parameters ====
 
==== Parameters ====
 +
:'''vV''' [IN] The vector - [[IC_Python_API:RLPy_RVector3|RVector3]]
  
tX[IN] the value of the x-axis - float
+
==== Returns ====
tY[IN] the value of the y-axis - float
+
:New 3D vector which is the cross product of this and another 3D vector - [[IC_Python_API:RLPy_RVector3|RVector3]]
tZ[IN] the value of the z-axis - float
+
  
=== SetY ===
+
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(1, 0, 0)
 +
b = RLPy.RVector3(0, 1, 0)
 +
c = a.Cross(b)
  
<syntaxhighlight lang="Python">
+
print(str(c.x) + ', ' + str(c.y) + ', ' + str(c.z))  # 0.0, 0.0, 1.0
RLPy.RVector3.SetY ( self, tY )
+
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Set the value of the y-axis.
+
=== Distance ( self, vV ) ===
 +
 
 +
Calculate the distance between this and another 3D vector.
  
 
==== Parameters ====
 
==== Parameters ====
 +
:'''vV''' [IN] The vector - [[IC_Python_API:RLPy_RVector3|RVector3]]
  
tX[IN] the value of the y-axis.
+
==== Returns ====
 +
:The distance between this and another 3D vector - float
  
=== SetZ ===
+
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(3, 0, 0)
 +
b = RLPy.RVector3(0, 4, 0)
  
<syntaxhighlight lang="Python">
+
print(a.Distance(b))    # 5.0
RLPy.RVector3.SetZ ( self, tZ )
+
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Set the value of the z-axis.
+
=== Dot (self, vV) ===
 +
 
 +
Calculate the dot production of this and another 3D vector.
  
 
==== Parameters ====
 
==== Parameters ====
 +
:'''vV''' [IN] The 3D vector with which to compute the dot product - [[IC_Python_API:RLPy_RVector3|RVector3]]
  
tX[IN] the value of the z-axis.
+
==== Returns ====
 +
:The value of the dot product - float
  
=== SquaredDistance ===
+
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(1, 2, 3)
 +
b = RLPy.RVector3(1, 2, 3)
  
<syntaxhighlight lang="Python">
+
print(a.Dot(b)) # 14.0
RLPy.RVector3.SquaredDistance ( self, vV )
+
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Squared distance of the two vectors.
+
=== Interpolate ( self, vRatio, vV ) ===
 +
 
 +
Calculate the interpolate of this and another 3D vector.
  
 
==== Parameters ====
 
==== Parameters ====
 +
:'''vRatio''' [IN] ratio value - float
 +
:'''vV''' [IN] Another 3D vector - [[IC_Python_API:RLPy_RVector3|RVector3]]
  
vV[IN] The vector - RLPy.RVector3
+
==== Returns ====
 +
:New vector which is the cross product this and another vector - [[IC_Python_API:RLPy_RVector3|RVector3]]
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(10, 20, 30)
 +
b = RLPy.RVector3(1, 2, 3)
 +
c = a.Interpolate(0.1, b)
 +
 
 +
print(str(c.x) + ', ' + str(c.y) + ', ' + str(c.z))  # 9.100000381469727, 18.200000762939453, 27.299999237060547
 +
</syntaxhighlight>
 +
 
 +
=== Inverse ( self ) ===
 +
 
 +
Invert all the elements of this 3D vector.
  
 
==== Returns ====
 
==== Returns ====
 +
:The inverse of this 3D vector - [[IC_Python_API:RLPy_RVector3|RVector3]]
  
the Squared distance - float
+
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(1, 2, 3)
 +
b = a.Inverse()
 +
print(str(b.x) + ', ' + str(b.y) + ', ' + str(b.z))  # 1.0, 0.5, 0.3333333432674408
 +
</syntaxhighlight>
  
=== SquaredLength ===
+
=== Length ( self )===
  
<syntaxhighlight lang="Python">
+
Length of the vector.
RLPy.RVector3.SquaredLength ( self)
+
 
 +
==== Returns ====
 +
:Length of this vector - float
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(1, 1, 1)
 +
 
 +
print(a.Length())  # 1.7320507764816284
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Squared length of the vector.
+
=== Normalize ( self ) ===
 +
 
 +
Normalize this 3D vector.
  
 
==== Returns ====
 
==== Returns ====
 +
:The normalized 3D vector - float
  
the squared length of this vector - float
+
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(1, 1, 1)
  
=== X ===
+
print(a.Normalize())    #1.7320507764816284
 +
print(str(a.x) + ', ' + str(a.y) + ', ' + str(a.z))  # 0.5773502588272095, 0.5773502588272095, 0.5773502588272095
 +
</syntaxhighlight>
 +
 
 +
=== SetX ( self, tX ) ===
 +
 
 +
Set the value of the x-axis for this 3D vector.
 +
 
 +
==== Parameters ====
 +
:'''tX''' [IN] The value of the x-axis - float
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(1, 1, 1)
 +
a.SetX(10)
  
<syntaxhighlight lang="Python">
+
print(str(a.x) + ', ' + str(a.y) + ', ' + str(a.z))  # 10.0, 1.0, 1.0
RLPy.RVector3.X ( self, args )
+
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Get the value of the x-axis.
+
=== SetXYZ ( self, tX, tY, tZ ) ===
  
==== Returns ====
+
Set the value of the all axes for this 3D vector.
  
the value of the x-axis - float
+
==== Parameters ====
 +
:'''tX''' [IN] The value of the x-axis - float
 +
:'''tY''' [IN] The value of the y-axis - float
 +
:'''tZ''' [IN] The value of the z-axis - float
  
=== XY ===
+
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(1, 1, 1)
 +
a.SetXYZ(10, 20, 30)
  
<syntaxhighlight lang="Python">
+
print(str(a.x) + ', ' + str(a.y) + ', ' + str(a.z)) # 10.0, 20.0, 30.0
RLPy.RVector3.XY ( self)
+
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Get the element of the 2D vector.
+
=== SetY ( self, tY ) ===
  
==== Returns ====
+
Set the value of the y-axis for this 3D vector.
  
Return the 2D vector - RLPy.RVector2
+
==== Parameters ====
 +
:'''tX''' [IN] the value of the y-axis.
  
=== Y ===
+
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(1, 1, 1)
 +
a.SetY(10)
  
<syntaxhighlight lang="Python">
+
print(str(a.x) + ', ' + str(a.y) + ', ' + str(a.z))  # 1.0, 10.0, 1.0
RLPy.RVector3.Y ( self, args )
+
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Get the value of the y-axis.
+
=== SetZ ( self, tZ ) ===
 +
 
 +
Set the value of the z-axis for this 3D vector.
 +
 
 +
==== Parameters ====
 +
:tX[IN] The value for the z-axis.
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(1, 1, 1)
 +
a.SetZ(10)
 +
 
 +
print(str(a.x) + ', ' + str(a.y) + ', ' + str(a.z))  # 1.0, 1.0, 10.0
 +
</syntaxhighlight>
 +
 
 +
=== SquaredDistance ( self, vV ) ===
 +
 
 +
Get the squared distance between this and another 3D vector.
 +
 
 +
==== Parameters ====
 +
:'''vV''' [IN] The vector - [[IC_Python_API:RLPy_RVector3|RVector3]]
  
 
==== Returns ====
 
==== Returns ====
 +
:The squared distance of this and another 3D vector - float
  
the value of the y-axis - float
+
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(1, 1, 1)
  
=== Z ===
+
print(a.SquaredLength())        # 3.0
 +
</syntaxhighlight>
 +
 
 +
=== SquaredLength ( self ) ===
 +
 
 +
Get the squared length of this 3D vector.
 +
 
 +
==== Returns ====
 +
:The squared length of this vector - float
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(1, 1, 1)
  
<syntaxhighlight lang="Python">
+
print(a.SquaredLength())    # 3.0
RLPy.RVector3.Z ( self, args )
+
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Get the value of the z-axis.
+
=== XY ( self ) ===
 +
 
 +
Get the x and y elements of this 3D vector.
  
 
==== Returns ====
 
==== Returns ====
 +
:A 2D vector composed of this 3D vector's x and y elements - [[IC_Python_API:RLPy_RVector2|RVector2]]
  
the value of the z-axis - float
+
<syntaxhighlight lang="python" line='line'>
 +
a = RLPy.RVector3(1, 2, 3)
 +
b = a.XY()
 +
 
 +
print(str(b.x) + ', ' + str(b.y))  # 1.0, 2.0
 +
</syntaxhighlight>

Latest revision as of 18:55, 13 April 2020

Main article: Modules.
Last modified: 04/13/2020

Description

This class represent the 3D vector (x, y, z). This class provides access to RLPy's internal 3D vector math library allowing 3D vectors to be handled easily, in a manner compatible with internal RLPy data structures. It also supports operators and provides some constants for your convenience:

Constant Description
RVector3.ZERO 3D zero vector: (0, 0, 0)
RVector3.UNIT_X 3D x unit vector: (1, 0, 0)
RVector3.UNIT_Y 3D y unit vector: (0, 1, 0)
RVector3.UNIT_Z 3D z unit vector: (0, 0, 1)
RVector3.UNIT_XY 3D vector: (1, 1, 0)
RVector3.UNIT_YZ 3D vector: (0, 1, 1)
RVector3.UNIT_XZ 3D vector: (1, 0, 1)
RVector3.UNIT_XYZ 3D vector: (1, 1, 1)

Constructor & Destructor

__init__ ( self )

1 a = RLPy.RVector3()

__init__ ( self, x, y, z )

Parameters

x [IN] A numerical value for x coordinate - float or int
y [IN] A numerical value for y coordinate - float or int
z [IN] A numerical value for z coordinate - float or int
1 a = RLPy.RVector3(1, 2, 3)

__init__ ( self, args )

The constructor. Initialize a new RVector3object with another RVector3object: args. This new RVector3object has the same value as args.

Parameters

args [IN] a RVector3object - RVector3
1 a = RLPy.RVector3(1, 2, 3)
2 b = RLPy.RVector3(a)

Operators

==

The "equal to" operator.

See Also: !=

1 a = RLPy.RVector3(1, 2, 3)
2 b = a
3 
4 print(a == b) #True

!=

The "not equal to" operator.

See Also: ==

1 a = RLPy.RVector3()
2 b = RLPy.RVector3(1, 2, 3)
3 
4 print(a != b) #True

<

The "less than" operator. Similar to string comparison: Returns True upon the first match that is less than and False if it is greater than. If the current comparison is equal, continue onto the next element. If all elements are equal then return False.

See Also: <=

1 a = RLPy.RVector3(0, 1, 5)
2 b = RLPy.RVector3(0, 2, 0)
3 c = RLPy.RVector3(1, 0, 1)
4 d = RLPy.RVector3(0, 1, 5)
5 
6 print(a < b) #True
7 print(b < c) #True
8 print(a < d) #False

>

The "greater than" operator. Similar to string comparison: Returns True upon the first match that is greater than and False if it is less than. If the current comparison is equal, continue onto the next element. If all elements are equal then return False.

See Also: >=

1 a = RLPy.RVector3(0, 1, 5)
2 b = RLPy.RVector3(0, 1, 7)
3 c = RLPy.RVector3(1, 0, 1)
4 d = RLPy.RVector3(0, 1, 5)
5 
6 print(b > a) #True
7 print(c > b) #True
8 print(d > a) #False

<=

The "less than or equal" operator. Similar to string comparison: Returns True upon the first match that is less than and False if it is greater than. If the current comparison is equal, continue onto the next element. If all elements are equal then return True.

See Also: <

1 a = RLPy.RVector3(0, 1, 5)
2 b = RLPy.RVector3(0, 2, 0)
3 c = RLPy.RVector3(1, 0, 1)
4 d = RLPy.RVector3(0, 1, 5)
5 
6 print(a<= b) #True
7 print(b<= c) #True
8 print(a<= d) #True

>=

The "greater than or equal" operator. Similar to string comparison: Returns True upon the first match that is greater than and False if it is less than. If the current comparison is equal, continue onto the next element. If all elements are equal then return True.

See Also: >

1 a = RLPy.RVector3(0, 1, 5)
2 b = RLPy.RVector3(0, 1, 7)
3 c = RLPy.RVector3(1, 0, 1)
4 d = RLPy.RVector3(0, 1, 5)
5 
6 print(b >= a) #True
7 print(c >= b) #True
8 print(d >= a) #True

+

The "addition" operator. Perform 3D vector addition.

See Also: +=

1 a = RLPy.RVector3(0, 1, 2)
2 b = RLPy.RVector3(1, 2, 3)
3 c = a + b
4 
5 print(str(c.x) + ', ' + str(c.y) + ', ' + str(c.z)) #1.0, 3.0, 5.0

-

The "subtraction" operator. Perform 3D vector subtraction.

See Also: -=

1 a = RLPy.RVector3(0, 1, 2)
2 b = RLPy.RVector3(3, 2, 1)
3 c = b - a
4 
5 print(str(c.x) + ', ' + str(c.y) + ', ' + str(c.z)) #3.0, 1.0, -1.0

*

The "multiplication" operator. Perform a scalar multiplication when the second operand is an integer or float. If the second operand is another 3D vector, then the respective x, y, z elements are multiplied.

See Also: *=

1 a = RLPy.RVector3(1, 2, 3)
2 b = a * 2
3 c = a * a
4 
5 print(str(b.x) + ', ' + str(b.y) + ', ' + str(b.z)) #2.0, 4.0, 6.0
6 print(str(c.x) + ', ' + str(c.y) + ', ' + str(c.z)) #1.0, 4.0, 9.0

/

The "division" operator. Perform a scalar division when the second operand is an integer or float. If the second operand is another 3D vector, then the respective x, y, z elements are divided.

See Also: /=

1 a = RLPy.RVector3(1, 2, 3)
2 b = a / 2
3 c = RLPy.RVector3(2, 2, 10)
4 d = a / c
5 
6 print(str(b.x) + ', ' + str(b.y) + ', ' + str(b.z)) #0.5, 1.0, 1.5
7 print(str(d.x) + ', ' + str(d.y) + ', ' + str(d.z)) #0.5, 1.0, 0.3

-

The "unary minus" operator. Inverse the sign of each element.

1 a = RLPy.RVector3(1, 2, 3)
2 b = -a
3 
4 print(str(b.x) + ', ' + str(b.y) + ', ' + str(b.z)) #-1.0, -2.0, -3.0

+=

The "addition assignment" operator.

See Also: +

1 a = RLPy.RVector3(0, 1, 2)
2 b = RLPy.RVector3(1, 2, 3)
3 a += b
4 
5 print(str(a.x) + ', ' + str(a.y)+ ', ' + str(a.z)) #1.0, 3.0, 5.0

-=

The "subtraction assignment" operator.

See Also: -

1 a = RLPy.RVector3(0, 1, 4)
2 b = RLPy.RVector3(1, 2, 3)
3 a -= b
4 
5 print(str(a.x) + ', ' + str(a.y) + ', ' + str(a.z)) #-1.0, -1.0, 1.0

*=

The "multiplication assignment" operator. For calculation method, refer to the * operator.

See Also: *

1 a = RLPy.RVector3(1, 2, 3)
2 a *= 2
3 b = RLPy.RVector3(1, 2, 3)
4 c = RLPy.RVector3(2, 3, 4)
5 b *= c
6 
7 print(str(a.x) + ', ' + str(a.y) + ', ' + str(a.z)) #2.0, 4.0, 6.0
8 print(str(b.x) + ', ' + str(b.y) + ', ' + str(b.z)) #2.0, 6.0, 12.0

/=

The "division assignment" operator. For calculation method, refer to the / operator.

See Also: /

1 a = RLPy.RVector3(1, 2, 3)
2 a /= 2
3 b = RLPy.RVector3(1, 2, 3)
4 c = RLPy.RVector3(2, 4, 2)
5 b /= c
6 
7 print(str(a.x) + ', ' + str(a.y) + ', ' + str(a.z)) #0.5, 1.0, 1.5
8 print(str(b.x) + ', ' + str(b.y) + ', ' + str(b.z)) #0.5, 0.5, 1.5

Member Functions

AlmostTheSame ( self, vV )

Determine if this and another 3D vector is the equivalent withing a tolerance.

Returns

True if the 3D vectors are almost the same, else False - bool
1 a = RLPy.RVector3(1, 2, 3)
2 b = RLPy.RVector3(1, 2, 3.000000001)
3 c = RLPy.RVector3(1, 2, 3.00001)
4 
5 if a.AlmostTheSame(b):  #True
6     print("a ≈ b")
7 if a.AlmostTheSame(c):  #False
8     print("a ≈ c")

AlmostZero ( self )

Determine if this 3D vector is a zeroed 3D vector.

Returns

True if this 3D vector is a zeroed 3D vector, else False - bool
1 a = RLPy.RVector3(0.00000001, 0, 0.00000003)
2 b = RLPy.RVector3(0.00001, 0, 0)
3 
4 if a.AlmostZero():                 #True
5     print("a is ZERO vector.")
6 if b.AlmostZero():                 #False
7     print("a is ZERO vector.")

Cross ( self, vV )

Calculate the cross production of this and another 3D vector.

Parameters

vV [IN] The vector - RVector3

Returns

New 3D vector which is the cross product of this and another 3D vector - RVector3
1 a = RLPy.RVector3(1, 0, 0)
2 b = RLPy.RVector3(0, 1, 0)
3 c = a.Cross(b)
4 
5 print(str(c.x) + ', ' + str(c.y) + ', ' + str(c.z))   # 0.0, 0.0, 1.0

Distance ( self, vV )

Calculate the distance between this and another 3D vector.

Parameters

vV [IN] The vector - RVector3

Returns

The distance between this and another 3D vector - float
1 a = RLPy.RVector3(3, 0, 0)
2 b = RLPy.RVector3(0, 4, 0)
3 
4 print(a.Distance(b))    # 5.0

Dot (self, vV)

Calculate the dot production of this and another 3D vector.

Parameters

vV [IN] The 3D vector with which to compute the dot product - RVector3

Returns

The value of the dot product - float
1 a = RLPy.RVector3(1, 2, 3)
2 b = RLPy.RVector3(1, 2, 3)
3 
4 print(a.Dot(b)) # 14.0

Interpolate ( self, vRatio, vV )

Calculate the interpolate of this and another 3D vector.

Parameters

vRatio [IN] ratio value - float
vV [IN] Another 3D vector - RVector3

Returns

New vector which is the cross product this and another vector - RVector3
1 a = RLPy.RVector3(10, 20, 30)
2 b = RLPy.RVector3(1, 2, 3)
3 c = a.Interpolate(0.1, b)
4 
5 print(str(c.x) + ', ' + str(c.y) + ', ' + str(c.z))   # 9.100000381469727, 18.200000762939453, 27.299999237060547

Inverse ( self )

Invert all the elements of this 3D vector.

Returns

The inverse of this 3D vector - RVector3
1 a = RLPy.RVector3(1, 2, 3)
2 b = a.Inverse()
3 print(str(b.x) + ', ' + str(b.y) + ', ' + str(b.z))  # 1.0, 0.5, 0.3333333432674408

Length ( self )

Length of the vector.

Returns

Length of this vector - float
1 a = RLPy.RVector3(1, 1, 1)
2 
3 print(a.Length())   # 1.7320507764816284

Normalize ( self )

Normalize this 3D vector.

Returns

The normalized 3D vector - float
1 a = RLPy.RVector3(1, 1, 1)
2 
3 print(a.Normalize())    #1.7320507764816284
4 print(str(a.x) + ', ' + str(a.y) + ', ' + str(a.z))   # 0.5773502588272095, 0.5773502588272095, 0.5773502588272095

SetX ( self, tX )

Set the value of the x-axis for this 3D vector.

Parameters

tX [IN] The value of the x-axis - float
1 a = RLPy.RVector3(1, 1, 1)
2 a.SetX(10)
3 
4 print(str(a.x) + ', ' + str(a.y) + ', ' + str(a.z))  # 10.0, 1.0, 1.0

SetXYZ ( self, tX, tY, tZ )

Set the value of the all axes for this 3D vector.

Parameters

tX [IN] The value of the x-axis - float
tY [IN] The value of the y-axis - float
tZ [IN] The value of the z-axis - float
1 a = RLPy.RVector3(1, 1, 1)
2 a.SetXYZ(10, 20, 30)
3 
4 print(str(a.x) + ', ' + str(a.y) + ', ' + str(a.z)) # 10.0, 20.0, 30.0

SetY ( self, tY )

Set the value of the y-axis for this 3D vector.

Parameters

tX [IN] the value of the y-axis.
1 a = RLPy.RVector3(1, 1, 1)
2 a.SetY(10)
3 
4 print(str(a.x) + ', ' + str(a.y) + ', ' + str(a.z))  # 1.0, 10.0, 1.0

SetZ ( self, tZ )

Set the value of the z-axis for this 3D vector.

Parameters

tX[IN] The value for the z-axis.
1 a = RLPy.RVector3(1, 1, 1)
2 a.SetZ(10)
3 
4 print(str(a.x) + ', ' + str(a.y) + ', ' + str(a.z))  # 1.0, 1.0, 10.0

SquaredDistance ( self, vV )

Get the squared distance between this and another 3D vector.

Parameters

vV [IN] The vector - RVector3

Returns

The squared distance of this and another 3D vector - float
1 a = RLPy.RVector3(1, 1, 1)
2 
3 print(a.SquaredLength())        # 3.0

SquaredLength ( self )

Get the squared length of this 3D vector.

Returns

The squared length of this vector - float
1 a = RLPy.RVector3(1, 1, 1)
2 
3 print(a.SquaredLength())    # 3.0

XY ( self )

Get the x and y elements of this 3D vector.

Returns

A 2D vector composed of this 3D vector's x and y elements - RVector2
1 a = RLPy.RVector3(1, 2, 3)
2 b = a.XY()
3 
4 print(str(b.x) + ', ' + str(b.y))   # 1.0, 2.0