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

From Reallusion Wiki!
Jump to: navigation, search
m (Description)
m
Line 5: Line 5:
 
== 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 easily, in a manner compatible with internal RLPy data structures. It also supports operators and provides some constants for your convenience:
+
This class represents a 2D vector (x, y). This class provides access to RLPy's internal 2D vector math library allowing 2D 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:
  
 
{|class = "wikitable"
 
{|class = "wikitable"
Line 28: Line 28:
 
=== __init__ ===
 
=== __init__ ===
  
Initialize a new RVector2 object as a 2D zero vector2: (0, 0).
+
Initialize a new [[IC_Python_API:RLPy_RVector2|RVector2]]object as a zeroed 2D vector: (0, 0).
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector2()
 
a = RLPy.RVector2()
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 36: Line 36:
 
=== __init__( self, x, y ) ===
 
=== __init__( self, x, y ) ===
  
Initialize a new RVector2 object as a 2D vector2: (x, y).
+
Initialize a new [[IC_Python_API:RLPy_RVector2|RVector2]]object as a 2D vector: (x, y).
  
 
==== Parameters ====
 
==== Parameters ====
:'''x''' [IN] a numerical value for x coordinate - float or int
+
:'''x''' [IN] a numerical value for x coordinate - float / int
:'''y''' [IN] a numerical value for y coordinate - float or int
+
:'''y''' [IN] a numerical value for y coordinate - float / int
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector2(1, 2)
 
a = RLPy.RVector2(1, 2)
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 48: Line 48:
 
=== __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 [[IC_Python_API:RLPy_RVector2|RVector2]]object with another [[IC_Python_API:RLPy_RVector2|RVector2]]object: args. This new [[IC_Python_API:RLPy_RVector2|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)
Line 61: Line 61:
 
The "equal to" operator.
 
The "equal to" operator.
  
<syntaxhighlight lang="Python">
+
See Also: [[#!=|!=]]
 +
 
 +
<syntaxhighlight lang="python">
 
a = RLPy.RVector2(1, 2)
 
a = RLPy.RVector2(1, 2)
 
b = a
 
b = a
Line 72: Line 74:
 
The "not equal to" operator.
 
The "not equal to" operator.
  
<syntaxhighlight lang="Python">
+
See Also: [[#==|==]]
 +
 
 +
<syntaxhighlight lang="python">
 
a = RLPy.RVector2()
 
a = RLPy.RVector2()
 
b = RLPy.RVector2(1, 2)
 
b = RLPy.RVector2(1, 2)
Line 81: Line 85:
 
=== < ===
 
=== < ===
  
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: 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'''.
  
<syntaxhighlight lang="Python">
+
See Also: [[#<=|<=]]
 +
 
 +
<syntaxhighlight lang="python">
 
a = RLPy.RVector2(0, 0)
 
a = RLPy.RVector2(0, 0)
 
b = RLPy.RVector2(0, 1)
 
b = RLPy.RVector2(0, 1)
Line 96: Line 102:
 
=== > ===
 
=== > ===
  
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: 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: [[#>=|>=]]
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector2(0, 0)
 
a = RLPy.RVector2(0, 0)
 
b = RLPy.RVector2(0, 1)
 
b = RLPy.RVector2(0, 1)
Line 111: Line 119:
 
=== <= ===
 
=== <= ===
  
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" 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'''.
  
<syntaxhighlight lang="Python">
+
See Also: [[#<|<]]
 +
 
 +
<syntaxhighlight lang="python">
 
a = RLPy.RVector2(0, 0)
 
a = RLPy.RVector2(0, 0)
 
b = RLPy.RVector2(0, 1)
 
b = RLPy.RVector2(0, 1)
Line 126: Line 136:
 
=== >= ===
 
=== >= ===
  
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" 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'''.
  
<syntaxhighlight lang="Python">
+
See Also: [[#>|>]]
 +
 
 +
<syntaxhighlight lang="python">
 
a = RLPy.RVector2(0, 0)
 
a = RLPy.RVector2(0, 0)
 
b = RLPy.RVector2(0, 1)
 
b = RLPy.RVector2(0, 1)
Line 141: Line 153:
 
=== + ===
 
=== + ===
  
The "addition" operator. Perform 2D vector2 addition.
+
The "addition" operator. Perform 2D vector addition.
 +
 
 +
See Also: [[#+=|+=]]
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector2(0, 1)
 
a = RLPy.RVector2(0, 1)
 
b = RLPy.RVector2(1, 2)
 
b = RLPy.RVector2(1, 2)
 
c = a + b
 
c = a + b
  
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 vector2 subtraction.
+
The "subtraction" operator. Perform 2D vector subtraction.
  
<syntaxhighlight lang="Python">
+
See Also: [[#-=|-=]]
 +
 
 +
<syntaxhighlight lang="python">
 
a = RLPy.RVector2(0, 1)
 
a = RLPy.RVector2(0, 1)
 
b = RLPy.RVector2(1, 3)
 
b = RLPy.RVector2(1, 3)
 
c = b - a
 
c = b - a
  
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 operand is an integer or float. If the second operand is another 2D vector, then the corresponding elements are multiplied.
 +
 
 +
See Also: [[#*=|*=]]
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector2(1, 2)
 
a = RLPy.RVector2(1, 2)
 
b = a * 2
 
b = a * 2
Line 173: Line 191:
 
d = a * c
 
d = a * c
  
print(str(b.x) + ', ' + str(b.y)) #2.0, 4.0
+
print(str(b.x) + ', ' + str(b.y)) # 2.0, 4.0
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 2D vector, then the corresponding elements are divided.
  
<syntaxhighlight lang="Python">
+
See Also: [[#/=|/=]]
 +
 
 +
<syntaxhighlight lang="python">
 
a = RLPy.RVector2(1, 2)
 
a = RLPy.RVector2(1, 2)
 
b = a / 2
 
b = a / 2
Line 187: Line 207:
 
d = a / c
 
d = a / c
  
print(str(b.x) + ', ' + str(b.y)) #0.5, 1.0
+
print(str(b.x) + ', ' + str(b.y)) # 0.5, 1.0
print(str(d.x) + ', ' + str(d.y)) #0.5, 0.6666666865348816
+
print(str(d.x) + ', ' + str(d.y)) # 0.5, 0.6666666865348816
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 195: Line 215:
 
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)
 
b = -a
 
b = -a
  
print(str(b.x) + ', ' + str(b.y)) #-1.0, -2.0
+
print(str(b.x) + ', ' + str(b.y)) # -1.0, -2.0
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 206: Line 226:
 
The "addition assignment" operator.
 
The "addition assignment" operator.
  
<syntaxhighlight lang="Python">
+
See Also: [[#+|+]]
 +
 
 +
<syntaxhighlight lang="python">
 
a = RLPy.RVector2(0, 1)
 
a = RLPy.RVector2(0, 1)
 
b = RLPy.RVector2(1, 2)
 
b = RLPy.RVector2(1, 2)
 
a += b
 
a += b
  
print(str(a.x) + ', ' + str(a.y)) #1.0, 3.0
+
print(str(a.x) + ', ' + str(a.y)) # 1.0, 3.0
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 218: Line 240:
 
The "subtraction assignment" operator.
 
The "subtraction assignment" operator.
  
<syntaxhighlight lang="Python">
+
See Also: [[#-|-]]
 +
 
 +
<syntaxhighlight lang="python">
 
a = RLPy.RVector2(0, 1)
 
a = RLPy.RVector2(0, 1)
 
b = RLPy.RVector2(1, 2)
 
b = RLPy.RVector2(1, 2)
 
a -= b
 
a -= b
  
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. For the calculation method, refer to the '''*''' operator.
  
<syntaxhighlight lang="Python">
+
See Also: [[#*|*]]
 +
 
 +
<syntaxhighlight lang="python">
 
a = RLPy.RVector2(1, 2)
 
a = RLPy.RVector2(1, 2)
 
a *= 2
 
a *= 2
Line 237: Line 263:
 
b *= c
 
b *= c
  
print(str(a.x) + ', ' + str(a.y)) #2.0, 4.0
+
print(str(a.x) + ', ' + str(a.y)) # 2.0, 4.0
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. For the calculation method, refer to the '''/''' operator.
 +
 
 +
See Also: [[#/|/]]
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector2(1, 2)
 
a = RLPy.RVector2(1, 2)
 
a /= 2
 
a /= 2
Line 252: Line 280:
 
b /= c
 
b /= c
  
print(str(a.x) + ', ' + str(a.y)) #0.5, 1.0
+
print(str(a.x) + ', ' + str(a.y)) # 0.5, 1.0
print(str(b.x) + ', ' + str(b.y)) #0.5, 0.6666666865348816
+
print(str(b.x) + ', ' + str(b.y)) # 0.5, 0.6666666865348816
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 260: Line 288:
 
=== AddWithWeight ===
 
=== AddWithWeight ===
  
Add a vector2 with weight.
+
Add a 2D vector with weight.
  
 
==== Parameters ====
 
==== Parameters ====
:'''vSrc''' [IN] The vector2 to add - RLPy.RVector2
+
:'''vSrc''' [IN] The 2D vector to add - [[IC_Python_API:RLPy_RVector2|RVector2]]
 
:'''fWeight''' [IN] The value of weight - float
 
:'''fWeight''' [IN] The value of weight - float
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector2(0, 1)
 
a = RLPy.RVector2(0, 1)
 
b = RLPy.RVector2(1, 2)
 
b = RLPy.RVector2(1, 2)
 
a.AddWithWeight(b, 2)
 
a.AddWithWeight(b, 2)
  
print(str(a.x) + ', ' + str(a.y)) #2.0, 5.0
+
print(str(a.x) + ', ' + str(a.y)) # 2.0, 5.0
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 279: Line 307:
  
 
==== Parameters ====
 
==== Parameters ====
:'''vV''' [IN] The vector2 to compute dot product - RLPy.RVector2
+
:'''vV''' [IN] The 2D vector to compute dot product - [[IC_Python_API:RLPy_RVector2|RVector2]]
  
 
==== Returns ====
 
==== Returns ====
 
:The value of the dot product - float
 
:The value of the dot product - float
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector2(1, 2)
 
a = RLPy.RVector2(1, 2)
 
dot = a.Dot( RLPy.RVector2(3, 5) )
 
dot = a.Dot( RLPy.RVector2(3, 5) )
Line 293: Line 321:
 
=== Inverse ===
 
=== Inverse ===
  
Return the inverse of a given vector2 by inverting the x, y elements.
+
Return the inverse of a given 2D vector by inverting the x, y elements.
  
 
==== Returns ====
 
==== Returns ====
:The inversed vector2 - RLPy.RVector2
+
:The inversed 2D vector - [[IC_Python_API:RLPy_RVector2|RVector2]]
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector2(0.5, 4)
 
a = RLPy.RVector2(0.5, 4)
 
b = a.Inverse()
 
b = a.Inverse()
  
print(str(b.x) + ', ' + str(b.y)) #2.0, 0.25
+
print(str(b.x) + ', ' + str(b.y)) # 2.0, 0.25
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
=== Length ===
 
=== Length ===
  
Length of the vector2.
+
Length of the 2D vector.
  
 
==== Returns ====
 
==== Returns ====
:The length of this vector2 - float
+
:The length of this 2D vector - float
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector2(3, 4)
 
a = RLPy.RVector2(3, 4)
  
print( str(a.Length()) ) #5.0
+
print( str(a.Length()) ) # 5.0
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
=== Normalize ===
 
=== Normalize ===
  
Normalize a given vector2.
+
Normalize a given 2D vector.
  
 
==== Returns ====
 
==== Returns ====
:Returns the length of the vector2 before normalization - float
+
:Returns the length of the 2D vector before normalization - float
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector2(1, 1)
 
a = RLPy.RVector2(1, 1)
 
b = a.Normalize()
 
b = a.Normalize()
  
print(str(a.x) + ', ' + str(a.y)) #0.7071067690849304, 0.7071067690849304
+
print(str(a.x) + ', ' + str(a.y)) # 0.7071067690849304, 0.7071067690849304
print(b) #1.4142135381698608
+
print(b) # 1.4142135381698608
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 340: Line 368:
 
:'''tX''' [IN] the value of the x-axis - float
 
:'''tX''' [IN] the value of the x-axis - float
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector2(1, 1)
 
a = RLPy.RVector2(1, 1)
 
a.SetX(10)
 
a.SetX(10)
  
print(str(a.x) + ', ' + str(a.y)) #10.0, 1.0
+
print(str(a.x) + ', ' + str(a.y)) # 10.0, 1.0
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 354: Line 382:
 
:'''tX''' [IN] the value of the y-axis.
 
:'''tX''' [IN] the value of the y-axis.
  
<syntaxhighlight lang="Python">
+
<syntaxhighlight lang="python">
 
a = RLPy.RVector2(1, 1)
 
a = RLPy.RVector2(1, 1)
 
a.SetY(10)
 
a.SetY(10)
  
print(str(a.x) + ', ' + str(a.y)) #1.0, 10.0
+
print(str(a.x) + ', ' + str(a.y)) # 1.0, 10.0
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
=== SquaredLength ===
 
=== SquaredLength ===
  
Squared length of the vector2.
+
Squared length of the 2D vector.
  
 
==== Returns ====
 
==== Returns ====
:The squared length of this vector2 - float
+
:The squared length of this 2D vector - float
  
<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>

Revision as of 22:09, 7 April 2020

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

Description

This class represents a 2D vector (x, y). This class provides access to RLPy's internal 2D vector math library allowing 2D 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
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 RVector2object as a zeroed 2D vector: (0, 0).

a = RLPy.RVector2()

__init__( self, x, y )

Initialize a new RVector2object as a 2D vector: (x, y).

Parameters

x [IN] a numerical value for x coordinate - float / int
y [IN] a numerical value for y coordinate - float / int
a = RLPy.RVector2(1, 2)

__init__( self, args )

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

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

Operators

==

The "equal to" operator.

See Also: !=

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

print(a == b) #True

!=

The "not equal to" operator.

See Also: ==

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

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: <=

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: 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: >=

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" 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: <

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" 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: >

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 vector addition.

See Also: +=

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 vector subtraction.

See Also: -=

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 operand is an integer or float. If the second operand is another 2D vector, then the corresponding elements are multiplied.

See Also: *=

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 2D vector, then the corresponding elements are divided.

See Also: /=

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.

See Also: +

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.

See Also: -

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. For the calculation method, refer to the * operator.

See Also: *

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. For the calculation method, refer to the / operator.

See Also: /

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 2D vector with weight.

Parameters

vSrc [IN] The 2D vector to add - RVector2
fWeight [IN] The value of weight - float
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

Dot

Calculate dot production of the two vectors.

Parameters

vV [IN] The 2D vector to compute dot product - RVector2

Returns

The value of the dot product - float
a = RLPy.RVector2(1, 2)
dot = a.Dot( RLPy.RVector2(3, 5) )

print(dot) #13.0

Inverse

Return the inverse of a given 2D vector by inverting the x, y elements.

Returns

The inversed 2D vector - RVector2
a = RLPy.RVector2(0.5, 4)
b = a.Inverse()

print(str(b.x) + ', ' + str(b.y)) # 2.0, 0.25

Length

Length of the 2D vector.

Returns

The length of this 2D vector - float
a = RLPy.RVector2(3, 4)

print( str(a.Length()) ) # 5.0

Normalize

Normalize a given 2D vector.

Returns

Returns the length of the 2D vector before normalization - float
a = RLPy.RVector2(1, 1)
b = a.Normalize()

print(str(a.x) + ', ' + str(a.y)) # 0.7071067690849304, 0.7071067690849304
print(b) # 1.4142135381698608

SetX

Set the value of the x-axis.

Parameters

tX [IN] the value of the x-axis - float
a = RLPy.RVector2(1, 1)
a.SetX(10)

print(str(a.x) + ', ' + str(a.y)) # 10.0, 1.0

SetY

Set the value of the y-axis.

Parameters

tX [IN] 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

SquaredLength

Squared length of the 2D vector.

Returns

The squared length of this 2D vector - float
a = RLPy.RVector2(1, 1)

print(a.SquaredLength()) # 2.0