Kiwi.Geom.Vector2 Class
A two dimensional vector object for storing and manipulating x and y vector components.
Constructor
Kiwi.Geom.Vector2
-
[x=0]
-
[y=0]
Parameters:
-
[x=0]
Number optionalThe x component of the vector.
-
[y=0]
Number optionalThe y component of the vector.
Returns:
Item Index
Methods
Methods
add
-
Vector2
Add each component of another Vector2 to this vectors components.
Parameters:
-
Vector2
Kiwi.Geom.Vector2to add
Returns:
A new Vector2 containing the product
addX
-
vector2
Add only the x component of another Vector2 to this vector.
Parameters:
-
vector2
Kiwi.Geom.Vector2Vector2 to add
Returns:
A new Vector2 containing the result
addY
-
vector2
Add only the y component of another Vector2 to this vector.
Parameters:
-
vector2
Kiwi.Geom.Vector2Vector2 to add
Returns:
A new Vector2 containing the result
ceil
()
Kiwi.Geom.Vector2
public
Increase each component of the Vector to the closest upper round value.
Returns:
a rounded up Vector2.
clamp
-
min
-
max
Clamp the vector between a maximum and minimum Vector2 range component-wise.
Parameters:
-
min
Kiwi.Geom.Vector2Minimum values for Vector2.
-
max
Kiwi.Geom.Vector2Maximum values for Vector2.
Returns:
a clamped Vector2.
clear
()
Kiwi.Geom.Vector2
public
Set both components to zero.
Returns:
This object.
clone
-
[output]
Get a clone of this Vector2.
Parameters:
-
[output]
Kiwi.Geom.Vector2 optionalOptional. A vector2 that will be cloned to. One will be created if none passed.
Returns:
Either a new cloned Vector2 or the output vector with cloned components.
copyFrom
-
source
Copy components from another Vector2.
Parameters:
-
source
Kiwi.Geom.Vector2A Vector2 to copy from.
Returns:
This object.
copyTo
-
target
Copy components to another Vector2.
Parameters:
-
target
Kiwi.Geom.Vector2A Vector2 to copy to.
Returns:
The supplied Vector2.
dot
-
vector2
Calculate the dot product if a Vector2 with this Vector2.
Parameters:
-
vector2
Kiwi.Geom.Vector2Vector2 to dot with this Vector2.
Returns:
Result of dot product.
equal
-
vector2
Check if two Vector2s from equal components.
Parameters:
-
vector2
Kiwi.Geom.Vector2vector2. Vector2 to check against.
Returns:
returns true if equal.
floor
()
Kiwi.Geom.Vector2
public
Reduce each component of the Vector to the closest lower round value.
Returns:
a rounded down Vector2.
fromAngle
-
angle
Generate a Vector2 from an angle
Parameters:
-
angle
NumberThe angle to generate the Vector2 from.
Returns:
A new Vector2
fromPoint
-
point
Generate a Vector2 from a point.
Parameters:
-
point
Kiwi.Geom.Pointpoint.
Returns:
A new Vector2
len
()
Number
public
Calculate the length of this Vector2 (Distance from the origin).
Returns:
The length.
lenSqr
()
Number
public
Calculate the square length of this Vector2 (Distance from the origin).
Returns:
The square length.
multiply
-
vector2
Multiply each component of another Vector2 with this vectors components.
Parameters:
-
vector2
Kiwi.Geom.Vector2Vector2 to multiply
Returns:
A new Vector2 containing the result
multiplyScalar
-
scalar
Multiply each component of this vector with a scalar number.
Parameters:
-
scalar
NumberScalar to multiply
Returns:
A new Vector2 containing the result
neg
()
Kiwi.Geom.Vector2
public
Calculate a Vector2 opposite to this Vector2.
Returns:
the opposite Vector2.
objType
()
String
public
The type of this object.
Returns:
"Vector2"
perp
()
Kiwi.Geom.Vector2
public
Calculate a Vector2 perpendicular to this Vector2.
Returns:
the perpendicular Vector2.
point
()
Kiwi.Geom.Point
public
Get a Point object with the same components as this Vector2.
Returns:
A new Point.
randomRadius
-
radius
Generate a random Vector2 within a given radius.
Parameters:
-
radius
NumberThe size of the radius to use.
Returns:
A new Vector2
round
()
Kiwi.Geom.Vector2
public
Round each component of the Vector to the closest round value.
Returns:
a rounded Vector2.
setTo
-
x
-
y
Set components on this Vector2.
Parameters:
-
x
Numberx component to set.
-
y
Numbery component to set.
Returns:
This object.
subtract
-
vector2
Subtract each component of another Vector2 from this vectors components.
Parameters:
-
vector2
Kiwi.Geom.Vector2Vector2 to subtract
Returns:
A new Vector2 containing the result
toString
()
String
Get a string representation of this object.
Returns:
This object as a string.
unit
()
Kiwi.Geom.Vector2
public
Calculate a normalised unit Vector2 from this Vector2.
Returns:
a new Unit Length Vector2.
Properties
x
Number
public
The x component of this Vector2.
y
Number
public
The y component of this Vector2.