 # Vector2

### Related Docs: object Vector2 | package maths

#### final case class Vector2(_x: Float, _y: Float) extends Product with Serializable

Immutable 2D Vector.

There are two ways to create vectors: `Vector2(x, y)` will create a vector with components x and y and `Vector2(a)` will create a unit vector rotated by an angle of `a` radians. (In the JavaScript version, create vectors using `Game.vector2(x, y)`.) Addition, subtraction, multiplication and division work as expected:

```>> 2 * Vector2(0.5, 0) + Vector2(0, 10) / 10 - Vector2(10, 0)
res0: Vector2 = Vector2(-9, 1)```

If you are using Java, you can use the methods `plus`, `times` and `minus` in place of the symbolic operators.

_x

The x coordinate.

_y

The y coordinate.

Annotations
()
Linear Supertypes
Serializable, Serializable, Product, Equals, AnyRef, Any
Ordering
1. Alphabetic
2. By Inheritance
Inherited
1. Vector2
2. Serializable
3. Serializable
4. Product
5. Equals
6. AnyRef
7. Any
1. Hide All
2. Show All
Visibility
1. Public
2. All

### Instance Constructors

2. #### new Vector2(_x: Float, _y: Float)

_x

The x coordinate.

_y

The y coordinate.

### Value Members

1. #### final def !=(arg0: Any): Boolean

Definition Classes
AnyRef → Any
2. #### final def ##(): Int

Definition Classes
AnyRef → Any
3. #### def *(rhs: Int): Vector2

Returns the scalar product of the vector with `rhs`

Returns the scalar product of the vector with `rhs`

Annotations
()
4. #### def *(rhs: Float): Vector2

Returns the scalar product of the vector with `rhs`

Returns the scalar product of the vector with `rhs`

Annotations
()
5. #### def *(rhs: Double): Vector2

Returns the scalar product of the vector with `rhs`

Returns the scalar product of the vector with `rhs`

Annotations
()
6. #### def +(rhs: Vector2): Vector2

Returns the sum of the vector and `rhs`.

Returns the sum of the vector and `rhs`.

Annotations
()
7. #### def -(rhs: Vector2): Vector2

Returns the difference of the vector and `rhs`.

Returns the difference of the vector and `rhs`.

Annotations
()
8. #### def /(rhs: Double): Vector2

Returns the vector divided by the scalar `rhs`

Returns the vector divided by the scalar `rhs`

Annotations
()
9. #### final def ==(arg0: Any): Boolean

Definition Classes
AnyRef → Any
10. #### val _x: Float

The x coordinate.

11. #### val _y: Float

The y coordinate.

12. #### final def asInstanceOf[T0]: T0

Definition Classes
Any
13. #### def clone(): AnyRef

Attributes
protected[java.lang]
Definition Classes
AnyRef
Annotations
@throws( ... )
14. #### def dot(rhs: Vector2): Double

Returns the dot product of the vector with `rhs`.

Returns the dot product of the vector with `rhs`.

Annotations
()
15. #### final def eq(arg0: AnyRef): Boolean

Definition Classes
AnyRef
16. #### def finalize(): Unit

Attributes
protected[java.lang]
Definition Classes
AnyRef
Annotations
@throws( classOf[java.lang.Throwable] )
17. #### final def getClass(): Class[_]

Definition Classes
AnyRef → Any
18. #### final def isInstanceOf[T0]: Boolean

Definition Classes
Any
19. #### def isValid: Boolean

Returns true if none of the components of the vectors are +-infinity or NaN, otherwise false.

Returns true if none of the components of the vectors are +-infinity or NaN, otherwise false.

Annotations
()
20. #### def length: Double

Returns the magnitude of the vector

Returns the magnitude of the vector

Annotations
()
21. #### def lengthSquared: Float

Returns the square of the magnitude of the vector

Returns the square of the magnitude of the vector

Annotations
()
22. #### def minus(rhs: Vector2): Vector2

Returns the sum of this vector and `rhs`.

Returns the sum of this vector and `rhs`.

Annotations
()
23. #### final def ne(arg0: AnyRef): Boolean

Definition Classes
AnyRef
24. #### def normalized: Vector2

Returns a new vector with the same direction and whose magnitude is equal to 1

Returns a new vector with the same direction and whose magnitude is equal to 1

Annotations
()
25. #### final def notify(): Unit

Definition Classes
AnyRef
26. #### final def notifyAll(): Unit

Definition Classes
AnyRef
27. #### def orientation: Float

Returns the angle in radians of the vector and the x-axis.

Returns the angle in radians of the vector and the x-axis. This value is always between 0 and 2 * Pi.

Annotations
()
28. #### def plus(rhs: Vector2): Vector2

Returns the sum of this vector and `rhs`.

Returns the sum of this vector and `rhs`.

Annotations
()
29. #### def rotated(angle: Double): Vector2

Returns the vector rotated by an angle of `angle` radians.

Returns the vector rotated by an angle of `angle` radians.

Annotations
()
30. #### final def synchronized[T0](arg0: ⇒ T0): T0

Definition Classes
AnyRef
31. #### def times(rhs: Double): Vector2

Returns the scalar product of the vector with `rhs`

Returns the scalar product of the vector with `rhs`

Annotations
()
32. #### def unary_-: Vector2

Returns the additive inverse of the vector.

Returns the additive inverse of the vector.

Annotations
()
33. #### final def wait(): Unit

Definition Classes
AnyRef
Annotations
@throws( ... )
34. #### final def wait(arg0: Long, arg1: Int): Unit

Definition Classes
AnyRef
Annotations
@throws( ... )
35. #### final def wait(arg0: Long): Unit

Definition Classes
AnyRef
Annotations
@throws( ... )
36. #### def x: Float

Returns the x-coordinate

Returns the x-coordinate

Annotations
() @inline()
37. #### def y: Float

Returns the y-coordinate

Returns the y-coordinate

Annotations
() @inline()