# CGVector

``struct CGVector``
• ``` angle ```

SwifterSwift: The angle of rotation (in radians) of the vector. The range of the angle is -π to π; an angle of 0 points to the right.

https://en.wikipedia.org/wiki/Atan2

#### Declaration

Swift

``var angle: CGFloat { get }``
• ``` magnitude ```

SwifterSwift: The magnitude (or length) of the vector.

https://en.wikipedia.org/wiki/Euclidean_vector#Length

#### Declaration

Swift

``var magnitude: CGFloat { get }``
• ``` init(angle:magnitude:) ```

SwifterSwift: Creates a vector with the given magnitude and angle.

https://www.grc.nasa.gov/WWW/K-12/airplane/vectpart.html

``````let vector = CGVector(angle: .pi, magnitude: 1)
``````

#### Declaration

Swift

``init(angle: CGFloat, magnitude: CGFloat)``

#### Parameters

 ``` angle ``` The angle of rotation (in radians) counterclockwise from the positive x-axis. ``` magnitude ``` The lenth of the vector.
• ``` *(_:_:) ```

SwifterSwift: Multiplies a scalar and a vector (commutative).

``````let vector = CGVector(dx: 1, dy: 1)
let largerVector = vector * 2
``````

#### Declaration

Swift

``static func * (vector: CGVector, scalar: CGFloat) -> CGVector``

#### Parameters

 ``` vector ``` The vector to be multiplied ``` scalar ``` The scale by which the vector will be multiplied

#### Return Value

The vector with its magnitude scaled

• ``` *(_:_:) ```

SwifterSwift: Multiplies a scalar and a vector (commutative).

``````let vector = CGVector(dx: 1, dy: 1)
let largerVector = 2 * vector
``````

#### Declaration

Swift

``static func * (scalar: CGFloat, vector: CGVector) -> CGVector``

#### Parameters

 ``` scalar ``` The scalar by which the vector will be multiplied ``` vector ``` The vector to be multiplied

#### Return Value

The vector with its magnitude scaled

• ``` *=(_:_:) ```

SwifterSwift: Compound assignment operator for vector-scalr multiplication

``````var vector = CGVector(dx: 1, dy: 1)
vector *= 2
``````

#### Declaration

Swift

``static func *= (vector: inout CGVector, scalar: CGFloat)``

#### Parameters

 ``` vector ``` The vector to be multiplied ``` scalar ``` The scale by which the vector will be multiplied
• ``` -(_:) ```

SwifterSwift: Negates the vector. The direction is reversed, but magnitude remains the same.

``````let vector = CGVector(dx: 1, dy: 1)
let reversedVector = -vector
``````

#### Declaration

Swift

``prefix static func - (vector: CGVector) -> CGVector``

#### Parameters

 ``` vector ``` The vector to be negated

#### Return Value

The negated vector