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

From Reallusion Wiki!
Jump to: navigation, search
m (AddWithWeight)
m
Line 2: Line 2:
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
 
==Description==
 
==Description==
 
+
2D vector2 math class for float values. This class provides access to RLPy's internal vector2 math library allowing vectors to be handled effortlessly, and in a manner compatible with internal RLPy data structures.  It also supports operators and vector2 related functions.
2D Vector math class for float values. This class provides access to RLPy's internal vector math library allowing vectors to be handled effortlessly, and in a manner compatible with internal RLPy data structures.  It also supports operators and vector related functions.
+
 
+
 
RVector2 also provides some constants for your convenience:
 
RVector2 also provides some constants for your convenience:
 
 
{|class = "wikitable"
 
{|class = "wikitable"
 
!Constant
 
!Constant
Line 12: Line 9:
 
|-
 
|-
 
|RVector2.ZERO
 
|RVector2.ZERO
|2D zero vector: (0, 0)
+
|2D zero vector2: (0, 0)
 
|-
 
|-
 
|RVector2.UNIT_X
 
|RVector2.UNIT_X
|2D x unit vector: (1, 0)
+
|2D x unit vector2: (1, 0)
 
|-
 
|-
 
|RVector2.UNIT_Y
 
|RVector2.UNIT_Y
|2D y unit vector: (0, 1)
+
|2D y unit vector2: (0, 1)
 
|-
 
|-
 
|RVector2.UNIT_XY
 
|RVector2.UNIT_XY
|2D unit vector: (1, 1)
+
|2D unit vector2: (1, 1)
 
|}
 
|}
 
 
==Constructors & Destructors==
 
==Constructors & Destructors==
 
 
===__init__===
 
===__init__===
 
+
Initialize a new RVector2 object as a 2D zero vector2: (0, 0).
Initialize a new RVector2 object as a 2D zero vector: (0, 0).
+
 
+
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
a = RLPy.RVector2()
 
a = RLPy.RVector2()
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
----
 
----
 
 
===__init__( self, x, y )===
 
===__init__( self, x, y )===
 
+
Initialize a new RVector2 object as a 2D vector2: (x, y).
Initialize a new RVector2 object as a 2D vector: (x, y).
+
 
+
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
a = RLPy.RVector2(1, 2)
 
a = RLPy.RVector2(1, 2)
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
====Parameters====
 
====Parameters====
 
 
x  [IN]    a numerical value for x coordinate - float or int<br/>
 
x  [IN]    a numerical value for x coordinate - float or int<br/>
 
y  [IN]    a numerical value for y coordinate - float or int<br/>
 
y  [IN]    a numerical value for y coordinate - float or int<br/>
 
 
----
 
----
 
 
===__init__( self, args )===
 
===__init__( self, args )===
 
 
Initialize a new RVector2 object with another RVector2 object: args. This new RVector2 object has the same value as args.
 
Initialize a new RVector2 object with another RVector2 object: args. This new RVector2 object has the same value as args.
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
 
a = RLPy.RVector2(1, 2)
 
a = RLPy.RVector2(1, 2)
 
b = RLPy.RVector2(a)
 
b = RLPy.RVector2(a)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
==Operators==
 
==Operators==
 
=== == ===
 
=== == ===
The “equal to” operator.
+
The "equal to" operator.
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
a = RLPy.RVector2(1, 2)
 
a = RLPy.RVector2(1, 2)
Line 70: Line 50:
 
print(a == b)                        #True
 
print(a == b)                        #True
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
----
 
----
 
=== != ===
 
=== != ===
The “not equal to” operator.
+
The "not equal to" operator.
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
a = RLPy.RVector2()
 
a = RLPy.RVector2()
Line 79: Line 58:
 
print(a != b)                        #True
 
print(a != b)                        #True
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
----
 
----
 
=== < ===
 
=== < ===
 
+
The "less than" operator. Similar to string comparison: If first element (x) less than, return '''True''', if greater than, return '''False''', if equal then compare the second element (y).  When (y) is greater than or equal return '''False''' else return '''True'''.
The “less than” operator. Similar to string comparison: If first element (x) less than, return '''True''', if greater than, return '''False''', if equal then compare the second element (y).  When (y) is greater than or equal return '''False''' else return '''True'''.
+
 
+
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
a = RLPy.RVector2(0, 0)
 
a = RLPy.RVector2(0, 0)
Line 90: Line 66:
 
c = RLPy.RVector2(1, 0)
 
c = RLPy.RVector2(1, 0)
 
d = RLPy.RVector2(0, 0)
 
d = RLPy.RVector2(0, 0)
 
 
print(a < b)                      #True
 
print(a < b)                      #True
 
print(b < c)                      #True
 
print(b < c)                      #True
 
print(a < d)                      #False
 
print(a < d)                      #False
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
----
 
----
 
 
=== > ===
 
=== > ===
The “greater than” operator.  Similar to string comparison: If element (x) is greater than, return '''True''', if less than, return '''False''', if equal then compare the second element (y). If (y) is greater than or equal, return '''False''', else return '''True'''.  
+
The "greater than" operator.  Similar to string comparison: If element (x) is greater than, return '''True''', if less than, return '''False''', if equal then compare the second element (y). If (y) is greater than or equal, return '''False''', else return '''True'''.  
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
a = RLPy.RVector2(0, 0)
 
a = RLPy.RVector2(0, 0)
Line 105: Line 78:
 
c = RLPy.RVector2(1, 0)
 
c = RLPy.RVector2(1, 0)
 
d = RLPy.RVector2(0, 0)
 
d = RLPy.RVector2(0, 0)
 
 
print(b > a)                      #True
 
print(b > a)                      #True
 
print(c > b)                      #True
 
print(c > b)                      #True
 
print(d > a)                      #False
 
print(d > a)                      #False
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
----
 
----
 
 
=== <= ===
 
=== <= ===
 
+
The "less than or equal to" operator. Similar to string comparison: If element (x) is less than, return '''True''', if greater than, return '''False''', if equal then compare the second element (y). If (y) is greater than, return '''False''', else return '''True'''.
The “less than or equal to” operator. Similar to string comparison: If element (x) is less than, return '''True''', if greater than, return '''False''', if equal then compare the second element (y). If (y) is greater than, return '''False''', else return '''True'''.
+
 
+
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
a = RLPy.RVector2(0, 0)
 
a = RLPy.RVector2(0, 0)
Line 122: Line 90:
 
c = RLPy.RVector2(1, 0)
 
c = RLPy.RVector2(1, 0)
 
d = RLPy.RVector2(0, 0)
 
d = RLPy.RVector2(0, 0)
 
 
print(a <= b)                      #True
 
print(a <= b)                      #True
 
print(b <= c)                      #True
 
print(b <= c)                      #True
 
print(a <= d)                      #True
 
print(a <= d)                      #True
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
----
 
----
 
 
=== >= ===
 
=== >= ===
 
 
The "greater than or equal to" operator. Similar to string comparison: If element (x) is greater than, return '''True''', if less than, return '''False''', if equal then compare the second element (y). If (y) is less than, return '''False''', else return '''True'''.  
 
The "greater than or equal to" operator. Similar to string comparison: If element (x) is greater than, return '''True''', if less than, return '''False''', if equal then compare the second element (y). If (y) is less than, return '''False''', else return '''True'''.  
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
a = RLPy.RVector2(0, 0)
 
a = RLPy.RVector2(0, 0)
Line 139: Line 102:
 
c = RLPy.RVector2(1, 0)
 
c = RLPy.RVector2(1, 0)
 
d = RLPy.RVector2(0, 0)
 
d = RLPy.RVector2(0, 0)
 
 
print(b >= a)                      #True
 
print(b >= a)                      #True
 
print(c >= b)                      #True
 
print(c >= b)                      #True
 
print(d >= a)                      #True
 
print(d >= a)                      #True
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
----
 
----
 
 
=== + ===
 
=== + ===
The “addition” operator. Perform 2D vector addition.
+
The "addition" operator. Perform 2D vector2 addition.
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
a = RLPy.RVector2(0, 1)
 
a = RLPy.RVector2(0, 1)
Line 155: Line 115:
 
print(str(c.x) + ', ' + str(c.y))      #1.0, 3.0
 
print(str(c.x) + ', ' + str(c.y))      #1.0, 3.0
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
----  
 
----  
 
=== - ===
 
=== - ===
The “subtraction” operator. Perform 2D vector subtraction.
+
The "subtraction" operator. Perform 2D vector2 subtraction.
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
a = RLPy.RVector2(0, 1)
 
a = RLPy.RVector2(0, 1)
Line 165: Line 124:
 
print(str(c.x) + ', ' + str(c.y))      #1.0, 2.0
 
print(str(c.x) + ', ' + str(c.y))      #1.0, 2.0
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
----  
 
----  
 
=== * ===
 
=== * ===
The “multiplication” operator. Perform a scalar multiplication when the second element is an integer or float.  If the second operand is another vector2, then the respective x, y elements are multiplied.
+
The "multiplication" operator. Perform a scalar multiplication when the second element is an integer or float.  If the second operand is another vector2, then the respective x, y elements are multiplied.
 
+
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
a = RLPy.RVector2(1, 2)
 
a = RLPy.RVector2(1, 2)
Line 178: Line 135:
 
print(str(d.x) + ', ' + str(d.y))      #2.0, 6.0
 
print(str(d.x) + ', ' + str(d.y))      #2.0, 6.0
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
----
 
----
 
 
=== / ===
 
=== / ===
 
 
The "division" operator. Perform a scalar division when the second operand is an integer or float.  If the second operand is another vector2, then the respective x,y elements are divided.  
 
The "division" operator. Perform a scalar division when the second operand is an integer or float.  If the second operand is another vector2, then the respective x,y elements are divided.  
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
a = RLPy.RVector2(1, 2)
 
a = RLPy.RVector2(1, 2)
Line 193: Line 146:
 
print(str(d.x) + ', ' + str(d.y))  #0.5, 0.6666666865348816
 
print(str(d.x) + ', ' + str(d.y))  #0.5, 0.6666666865348816
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
----
 
----
 
 
=== - ===
 
=== - ===
The “unary minus” operator. Inverse the sign of each element.
+
The "unary minus" operator. Inverse the sign of each element.
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
a = RLPy.RVector2(1, 2)
 
a = RLPy.RVector2(1, 2)
Line 203: Line 154:
 
print(str(b.x) + ', ' + str(b.y))      #-1.0, -2.0
 
print(str(b.x) + ', ' + str(b.y))      #-1.0, -2.0
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
----  
 
----  
 
=== += ===
 
=== += ===
The “addition assignment” operator.
+
The "addition assignment" operator.
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
a = RLPy.RVector2(0, 1)
 
a = RLPy.RVector2(0, 1)
Line 213: Line 163:
 
print(str(a.x) + ', ' + str(a.y))      #1.0, 3.0
 
print(str(a.x) + ', ' + str(a.y))      #1.0, 3.0
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
----   
 
----   
 
=== -= ===
 
=== -= ===
The “subtraction assignment” operator.
+
The "subtraction assignment" operator.
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
a = RLPy.RVector2(0, 1)
 
a = RLPy.RVector2(0, 1)
Line 223: Line 172:
 
print(str(a.x) + ', ' + str(a.y))      #-1.0, -1.0
 
print(str(a.x) + ', ' + str(a.y))      #-1.0, -1.0
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
----
 
----
 
 
=== *= ===
 
=== *= ===
The “multiplication assignment” operator. Please refer to '''*''' operator for calculation method.  
+
The "multiplication assignment" operator. Please refer to '''*''' operator for calculation method.  
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
a = RLPy.RVector2(1, 2)
 
a = RLPy.RVector2(1, 2)
Line 237: Line 184:
 
print(str(b.x) + ', ' + str(b.y))    #2.0, 6.0
 
print(str(b.x) + ', ' + str(b.y))    #2.0, 6.0
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
----
 
----
 
 
=== /= ===
 
=== /= ===
The “division assignment” operator. Please refer to '''/''' operator for calculation method.
+
The "division assignment" operator. Please refer to '''/''' operator for calculation method.
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
a = RLPy.RVector2(1, 2)
 
a = RLPy.RVector2(1, 2)
Line 251: Line 196:
 
print(str(b.x) + ', ' + str(b.y))    #0.5, 0.6666666865348816
 
print(str(b.x) + ', ' + str(b.y))    #0.5, 0.6666666865348816
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
==Member Functions==
 
==Member Functions==
 
===AddWithWeight===
 
===AddWithWeight===
 
+
Add a vector2 with weight.
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
a = RLPy.RVector2(0, 1)
 
a = RLPy.RVector2(0, 1)
Line 261: Line 205:
 
print(str(a.x) + ', ' + str(a.y))      #2.0, 5.0
 
print(str(a.x) + ', ' + str(a.y))      #2.0, 5.0
 
</syntaxhighlight>
 
</syntaxhighlight>
 
Add a vector with weight.
 
 
 
====Parameters====
 
====Parameters====
 
 
<div style="margin-left: 2em;">
 
<div style="margin-left: 2em;">
'''vSrc''' [IN] The vector to add - RLPy.RVector2
+
'''vSrc''' [IN] The vector2 to add - RLPy.RVector2
 
'''fWeight''' [IN] The value of weight - float
 
'''fWeight''' [IN] The value of weight - float
 
</div>
 
</div>
 
-----
 
-----
 
 
===Dot===
 
===Dot===
 +
Calculate dot production of the two vectors.
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RVector2.Dot ( self, vV )
+
a = RLPy.RVector2(1, 2)
 +
dot = a.Dot( RLPy.RVector2(3, 5) )
 +
print(dot)                      #13.0
 
</syntaxhighlight>
 
</syntaxhighlight>
Calculate dot production of the two vectors.
 
 
====Parameters====
 
====Parameters====
 
<div style="margin-left: 2em;">
 
<div style="margin-left: 2em;">
 
+
'''vV''' [IN] The vector2 to compute dot product - RLPy.RVector2
'''vV''' [IN] The vector - RLPy.RVector2
+
 
</div>
 
</div>
 
====Returns====
 
====Returns====
<div style="margin-left: 2em;">The value of the dot production - float
+
<div style="margin-left: 2em;">
 +
The value of the dot product - float
 
</div>
 
</div>
 
-----
 
-----
 
===Inverse===
 
===Inverse===
 +
Return the inverse of a given vector2 by inverting the x, y elements.
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RVector2.Inverse ( self )
+
a = RLPy.RVector2(0.5, 4)
 +
b = a.Inverse()
 +
print(str(b.x) + ', ' + str(b.y))        #2.0, 0.25
 
</syntaxhighlight>
 
</syntaxhighlight>
Inverse this vector.
 
 
====Returns====
 
====Returns====
<div style="margin-left: 2em;">The inversed vector - RLPy.RVector2
+
<div style="margin-left: 2em;">
 +
The inversed vector2 - RLPy.RVector2
 
</div>
 
</div>
 
-----
 
-----
 
===Length===
 
===Length===
 +
Length of the vector2.
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RVector2.Length ( self )
+
a = RLPy.RVector2(3, 4)
 +
print( str(a.Length()) )            #5.0
 
</syntaxhighlight>
 
</syntaxhighlight>
Length of the vector.
 
 
====Returns====
 
====Returns====
<div style="margin-left: 2em;">The length of this vector - float
+
<div style="margin-left: 2em;">
 +
The length of this vector2 - float
 
</div>
 
</div>
 
-----
 
-----
 
===Normalize===
 
===Normalize===
 +
Normalize a given vector2.
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RVector2.Normalize ( self )
+
a = RLPy.RVector2(1, 1)
 +
b = a.Normalize()
 +
print(str(a.x) + ', ' + str(a.y))
 +
                        #0.7071067690849304, 0.7071067690849304
 +
print(b)                #1.4142135381698608
 
</syntaxhighlight>
 
</syntaxhighlight>
Normalizes this vector.
 
 
====Returns====
 
====Returns====
<div style="margin-left: 2em;">The normalized vector - float
+
<div style="margin-left: 2em;">
 +
Returns the length of the vector2 before normalization - float
 
</div>
 
</div>
 
-----
 
-----
 
===SetX===
 
===SetX===
 +
Set the value of the x-axis.
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RVector2.SetX ( self, tX )
+
a = RLPy.RVector2(1, 1)
 +
a.SetX(10)
 +
print(str(a.x) + ', ' + str(a.y))  #10.0, 1.0
 
</syntaxhighlight>
 
</syntaxhighlight>
Set the value of the x-axis.
 
 
====Parameters====
 
====Parameters====
 
<div style="margin-left: 2em;">
 
<div style="margin-left: 2em;">
 
 
'''tX''' [IN] the value of the x-axis - float
 
'''tX''' [IN] the value of the x-axis - float
 
</div>
 
</div>
 
-----
 
-----
 
===SetY===
 
===SetY===
 
+
Set the value of the y-axis.
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
a = RLPy.RVector2(1, 1)
 
a = RLPy.RVector2(1, 1)
Line 331: Line 283:
 
print(str(a.x) + ', ' + str(a.y))  #1.0, 10.0
 
print(str(a.x) + ', ' + str(a.y))  #1.0, 10.0
 
</syntaxhighlight>
 
</syntaxhighlight>
 
Set the value of the y-axis.
 
 
 
====Parameters====
 
====Parameters====
 
 
<div style="margin-left: 2em;">
 
<div style="margin-left: 2em;">
 
'''tX''' [IN] the value of the y-axis.
 
'''tX''' [IN] the value of the y-axis.
 
</div>
 
</div>
 
-----
 
-----
 
 
===SquaredLength===
 
===SquaredLength===
 
+
Squared length of the vector2.
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
 
a = RLPy.RVector2(1, 1)
 
a = RLPy.RVector2(1, 1)
 
print(a.SquaredLength())          #2.0
 
print(a.SquaredLength())          #2.0
 
</syntaxhighlight>
 
</syntaxhighlight>
 
Squared length of the vector.
 
 
 
====Returns====
 
====Returns====
 
 
<div style="margin-left: 2em;">
 
<div style="margin-left: 2em;">
The squared length of this vector - float
+
The squared length of this vector2 - float
 
</div>
 
</div>
 
-----
 
-----
 
===X===
 
<syntaxhighlight lang="Python">
 
RLPy.RVector2.X ( self, args )
 
</syntaxhighlight>
 
Get the value of the x-axis.
 
====Returns====
 
<div style="margin-left: 2em;">The value of the x-axis - float
 
</div>
 
-----
 
===Y===
 
<syntaxhighlight lang="Python">
 
RLPy.RVector2.Y ( self, args )
 
</syntaxhighlight>
 
Get the value of the y-axis.
 
====Returns====
 
<div style="margin-left: 2em;">The value of the y-axis - float
 
</div>
 

Revision as of 22:02, 20 February 2020

Main article: Modules.

Description

2D vector2 math class for float values. This class provides access to RLPy's internal vector2 math library allowing vectors to be handled effortlessly, and in a manner compatible with internal RLPy data structures. It also supports operators and vector2 related functions. RVector2 also provides some constants for your convenience:

Constant Description
RVector2.ZERO 2D zero vector2: (0, 0)
RVector2.UNIT_X 2D x unit vector2: (1, 0)
RVector2.UNIT_Y 2D y unit vector2: (0, 1)
RVector2.UNIT_XY 2D unit vector2: (1, 1)

Constructors & Destructors

__init__

Initialize a new RVector2 object as a 2D zero vector2: (0, 0).

a = RLPy.RVector2()

__init__( self, x, y )

Initialize a new RVector2 object as a 2D vector2: (x, y).

a = RLPy.RVector2(1, 2)

Parameters

x [IN] a numerical value for x coordinate - float or int
y [IN] a numerical value for y coordinate - float or int


__init__( self, args )

Initialize a new RVector2 object with another RVector2 object: args. This new RVector2 object has the same value as args.

a = RLPy.RVector2(1, 2)
b = RLPy.RVector2(a)

Operators

==

The "equal to" operator.

a = RLPy.RVector2(1, 2)
b = a
print(a == b)                         #True

!=

The "not equal to" operator.

a = RLPy.RVector2()
b = RLPy.RVector2(1, 2)
print(a != b)                         #True

<

The "less than" operator. Similar to string comparison: If first element (x) less than, return True, if greater than, return False, if equal then compare the second element (y). When (y) is greater than or equal return False else return True.

a = RLPy.RVector2(0, 0)
b = RLPy.RVector2(0, 1)
c = RLPy.RVector2(1, 0)
d = RLPy.RVector2(0, 0)
print(a < b)                       #True
print(b < c)                       #True
print(a < d)                       #False

>

The "greater than" operator. Similar to string comparison: If element (x) is greater than, return True, if less than, return False, if equal then compare the second element (y). If (y) is greater than or equal, return False, else return True.

a = RLPy.RVector2(0, 0)
b = RLPy.RVector2(0, 1)
c = RLPy.RVector2(1, 0)
d = RLPy.RVector2(0, 0)
print(b > a)                       #True
print(c > b)                       #True
print(d > a)                       #False

<=

The "less than or equal to" operator. Similar to string comparison: If element (x) is less than, return True, if greater than, return False, if equal then compare the second element (y). If (y) is greater than, return False, else return True.

a = RLPy.RVector2(0, 0)
b = RLPy.RVector2(0, 1)
c = RLPy.RVector2(1, 0)
d = RLPy.RVector2(0, 0)
print(a <= b)                      #True
print(b <= c)                      #True
print(a <= d)                      #True

>=

The "greater than or equal to" operator. Similar to string comparison: If element (x) is greater than, return True, if less than, return False, if equal then compare the second element (y). If (y) is less than, return False, else return True.

a = RLPy.RVector2(0, 0)
b = RLPy.RVector2(0, 1)
c = RLPy.RVector2(1, 0)
d = RLPy.RVector2(0, 0)
print(b >= a)                       #True
print(c >= b)                       #True
print(d >= a)                       #True

+

The "addition" operator. Perform 2D vector2 addition.

a = RLPy.RVector2(0, 1)
b = RLPy.RVector2(1, 2)
c = a + b
print(str(c.x) + ', ' + str(c.y))       #1.0, 3.0

-

The "subtraction" operator. Perform 2D vector2 subtraction.

a = RLPy.RVector2(0, 1)
b = RLPy.RVector2(1, 3)
c = b - a 
print(str(c.x) + ', ' + str(c.y))       #1.0, 2.0

*

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

a = RLPy.RVector2(1, 2)
b = a * 2
c = RLPy.RVector2(2, 3)
d = a * c
print(str(b.x) + ', ' + str(b.y))      #2.0, 4.0
print(str(d.x) + ', ' + str(d.y))      #2.0, 6.0

/

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

a = RLPy.RVector2(1, 2)
b = a / 2
c = RLPy.RVector2(2, 3)
d = a / c
print(str(b.x) + ', ' + str(b.y))   #0.5, 1.0
print(str(d.x) + ', ' + str(d.y))   #0.5, 0.6666666865348816

-

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

a = RLPy.RVector2(1, 2)
b = -a
print(str(b.x) + ', ' + str(b.y))      #-1.0, -2.0

+=

The "addition assignment" operator.

a = RLPy.RVector2(0, 1)
b = RLPy.RVector2(1, 2)
a += b
print(str(a.x) + ', ' + str(a.y))      #1.0, 3.0

-=

The "subtraction assignment" operator.

a = RLPy.RVector2(0, 1)
b = RLPy.RVector2(1, 2)
a -= b
print(str(a.x) + ', ' + str(a.y))      #-1.0, -1.0

*=

The "multiplication assignment" operator. Please refer to * operator for calculation method.

a = RLPy.RVector2(1, 2)
a *= 2
b = RLPy.RVector2(1, 2)
c = RLPy.RVector2(2, 3)
b *= c
print(str(a.x) + ', ' + str(a.y))     #2.0, 4.0
print(str(b.x) + ', ' + str(b.y))     #2.0, 6.0

/=

The "division assignment" operator. Please refer to / operator for calculation method.

a = RLPy.RVector2(1, 2)
a /= 2
b = RLPy.RVector2(1, 2)
c = RLPy.RVector2(2, 3)
b /= c
print(str(a.x) + ', ' + str(a.y))     #0.5, 1.0
print(str(b.x) + ', ' + str(b.y))     #0.5, 0.6666666865348816

Member Functions

AddWithWeight

Add a vector2 with weight.

a = RLPy.RVector2(0, 1)
b = RLPy.RVector2(1, 2)
a.AddWithWeight(b, 2)
print(str(a.x) + ', ' + str(a.y))      #2.0, 5.0

Parameters

vSrc [IN] The vector2 to add - RLPy.RVector2 fWeight [IN] The value of weight - float


Dot

Calculate dot production of the two vectors.

a = RLPy.RVector2(1, 2)
dot = a.Dot( RLPy.RVector2(3, 5) )
print(dot)                       #13.0

Parameters

vV [IN] The vector2 to compute dot product - RLPy.RVector2

Returns

The value of the dot product - float


Inverse

Return the inverse of a given vector2 by inverting the x, y elements.

a = RLPy.RVector2(0.5, 4)
b = a.Inverse()
print(str(b.x) + ', ' + str(b.y))        #2.0, 0.25

Returns

The inversed vector2 - RLPy.RVector2


Length

Length of the vector2.

a = RLPy.RVector2(3, 4)
print( str(a.Length()) )             #5.0

Returns

The length of this vector2 - float


Normalize

Normalize a given vector2.

a = RLPy.RVector2(1, 1)
b = a.Normalize()
print(str(a.x) + ', ' + str(a.y))
                        #0.7071067690849304, 0.7071067690849304
print(b)                #1.4142135381698608

Returns

Returns the length of the vector2 before normalization - float


SetX

Set the value of the x-axis.

a = RLPy.RVector2(1, 1)
a.SetX(10)
print(str(a.x) + ', ' + str(a.y))   #10.0, 1.0

Parameters

tX [IN] the value of the x-axis - float


SetY

Set the value of the y-axis.

a = RLPy.RVector2(1, 1)
a.SetY(10)
print(str(a.x) + ', ' + str(a.y))   #1.0, 10.0

Parameters

tX [IN] the value of the y-axis.


SquaredLength

Squared length of the vector2.

a = RLPy.RVector2(1, 1)
print(a.SquaredLength())          #2.0

Returns

The squared length of this vector2 - float