<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Vision",
  "identifier" : "/documentation/Vision/VNVector",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Vision"
    ],
    "preciseIdentifier" : "c:objc(cs)VNVector"
  },
  "title" : "VNVector"
}
-->

# VNVector

An immutable 2D vector represented by its x-axis and y-axis projections.

```
class VNVector
```

## Topics

### Creating a Vector

[`init(byAdding:to:)`](/documentation/Vision/VNVector/init(byAdding:to:))

Creates a new vector by adding the specified vectors.

[`init(byAddingVector:toVector:)`](/documentation/Vision/VNVector/init(byAddingVector:toVector:))

[`init(bySubtracting:from:)`](/documentation/Vision/VNVector/init(bySubtracting:from:))

Creates a new vector by subtracting the first vector from the second vector.

[`init(bySubtractingVector:fromVector:)`](/documentation/Vision/VNVector/init(bySubtractingVector:fromVector:))

[`init(byMultiplying:byScalar:)`](/documentation/Vision/VNVector/init(byMultiplying:byScalar:))

Creates a new vector by multiplying the specified vector’s x-axis and y-axis projections by the scalar value.

[`init(byMultiplyingVector:byScalar:)`](/documentation/Vision/VNVector/init(byMultiplyingVector:byScalar:))

[`init(r:theta:)`](/documentation/Vision/VNVector/init(r:theta:))

Creates a new vector in polar coordinate space.

[`init(vectorHead:tail:)`](/documentation/Vision/VNVector/init(vectorHead:tail:))

Creates a new vector in Cartesian coordinate space.

[`init(XComponent:yComponent:)`](/documentation/Vision/VNVector/init(XComponent:yComponent:)-231pv)

[`init(xComponent:yComponent:)`](/documentation/Vision/VNVector/init(xComponent:yComponent:)-3p5k3)

Creates a new vector in Cartesian coordinate space, based on its x-axis and y-axis projections.

[`init(coder:)`](/documentation/Vision/VNVector/init(coder:))

[`zero`](/documentation/Vision/VNVector/zero)

A vector object with zero length.

### Inspecting a Vector

[`length`](/documentation/Vision/VNVector/length)

The length, or absolute value, of the vector.

[`r`](/documentation/Vision/VNVector/r)

The radius, absolute value, or length of the vector.

[`theta`](/documentation/Vision/VNVector/theta)

The angle between the vector direction and the positive direction of the x-axis.

[`squaredLength`](/documentation/Vision/VNVector/squaredLength)

The squared length of the vector.

[`x`](/documentation/Vision/VNVector/x)

A signed projection that indicates the vector’s direction on the x-axis.

[`y`](/documentation/Vision/VNVector/y)

A signed projection that indicates the vector’s direction on the y-axis.

[`dotProduct(of:vector:)`](/documentation/Vision/VNVector/dotProduct(of:vector:))

Caclulates the dot product of two vectors.

[`unitVector(for:)`](/documentation/Vision/VNVector/unitVector(for:))

Calculates a vector that’s normalized by preserving its direction, so that the vector length equals 1.0.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)