<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Spatial",
  "identifier" : "/documentation/Spatial/Vector3D",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Spatial"
    ],
    "preciseIdentifier" : "c:@UA@SPVector3D"
  },
  "title" : "Vector3D"
}
-->

# Vector3D

A three-element vector.

```
struct Vector3D
```

## Topics

### Creating a vector

[`init()`](/documentation/Spatial/Vector3D/init())

Creates a vector.

[`init(x: Double, y: Double, z: Double)`](/documentation/Spatial/Vector3D/init(x:y:z:)-2ejxw)

Creates a vector from the specified double-precision values.

[`init<T>(x: T, y: T, z: T)`](/documentation/Spatial/Vector3D/init(x:y:z:)-29hwg)

Creates a vector from the specified floating-point values.

[`init(simd_float3)`](/documentation/Spatial/Vector3D/init(_:)-73gdm)

Creates a ray from the specified single-precision vector.

[`init(simd_double3)`](/documentation/Spatial/Vector3D/init(_:)-1a9i3)

Creates a vector from the specified double-precision vector.

[`init(vector: simd_double3)`](/documentation/Spatial/Vector3D/init(vector:))

Creates a vector from the specified double-precision vector.

[`init(RotationAxis3D)`](/documentation/Spatial/Vector3D/init(_:)-3br9h)

Creates a vector from the specified Spatial rotation axis.

[`init(Point3D)`](/documentation/Spatial/Vector3D/init(_:)-8vcph)

Creates a vector from the specified Spatial point structure.

[`init(Size3D)`](/documentation/Spatial/Vector3D/init(_:)-8egfs)

Creates a vector from the specified Spatial size structure.

[`init(SphericalCoordinates3D)`](/documentation/Spatial/Vector3D/init(_:)-9ker1)

Creates a vector from the specified Spatial spherical coordinates structure.

[`static SPVector3D SPVector3DMakeWithPoint(SPPoint3D point);`](/documentation/Spatial/SPVector3DMakeWithPoint)

Creates a vector from the specified Spatial point structure.

[`static SPVector3D SPVector3DMakeWithRotationAxis(SPRotationAxis3D axis);`](/documentation/Spatial/SPVector3DMakeWithRotationAxis)

Creates a vector from the specified Spatial rotation axis.

[`static SPVector3D SPVector3DMakeWithSize(SPSize3D size);`](/documentation/Spatial/SPVector3DMakeWithSize)

Creates a vector from the specified Spatial size structure.

[`static SPVector3D SPVector3DMakeWithSphericalCoordinates(SPSphericalCoordinates3D coords);`](/documentation/Spatial/SPVector3DMakeWithSphericalCoordinates)

Returns a Spatial vector that represents the Cartesian coordinates of the specified spherical coordinates structure.

[`static SPVector3D SPVector3DMakeWithVector(simd_double3 xyz);`](/documentation/Spatial/SPVector3DMakeWithVector)

Creates a vector from the specified double-precision vector.

### Constants

[`static const SPVector3D SPVector3DZero;`](/documentation/Spatial/SPVector3DZero)

A vector that contains all zeros.

[`static const SPVector3D SPVectorInfinity;`](/documentation/Spatial/SPVectorInfinity)

A vector that contains all infinities.

### Inspecting a vector’s properties

[`var x: Double`](/documentation/Spatial/Vector3D/x)

The x-element value.

[`var y: Double`](/documentation/Spatial/Vector3D/y)

The y-element value.

[`var z: Double`](/documentation/Spatial/Vector3D/z)

The z-element value.

[`double x;`](/documentation/Spatial/SPVector3D/x)

The x-element value.

[`double y;`](/documentation/Spatial/SPVector3D/y)

The y-element value.

[`double z;`](/documentation/Spatial/SPVector3D/z)

The z-element value.

[`var vector: simd_double3`](/documentation/Spatial/Vector3D/vector)

A simd three-element vector that contains the x-, y-, and z-element values.

### Checking characteristics

[`func rotation(to: Vector3D) -> Rotation3D`](/documentation/Spatial/Vector3D/rotation(to:))

Returns the rotation from the normalized first vector to the normalized second vector.

[`static SPRotation3D SPVector3DRotationToVector(SPVector3D vector, SPVector3D other);`](/documentation/Spatial/SPVector3DRotationToVector)

Returns the rotation around the origin from the first vector to the second vector.

[`static bool SPVector3DIsZero(SPVector3D vector);`](/documentation/Spatial/SPVector3DIsZero)

[`static bool SPVector3DIsFinite(SPVector3D vector);`](/documentation/Spatial/SPVector3DIsFinite)

[`static bool SPVector3DIsNaN(SPVector3D vector);`](/documentation/Spatial/SPVector3DIsNaN)

### Geometry functions

[`func cross(Vector3D) -> Vector3D`](/documentation/Spatial/Vector3D/cross(_:))

Returns the cross product of the vector and the specified vector.

[`func dot(Vector3D) -> Double`](/documentation/Spatial/Vector3D/dot(_:))

Returns the dot product of the vector and the specified vector.

[`var length: Double`](/documentation/Spatial/Vector3D/length)

The length of the vector.

[`var lengthSquared: Double`](/documentation/Spatial/Vector3D/lengthSquared)

The square of the length of the vector.

[`func normalize()`](/documentation/Spatial/Vector3D/normalize())

Normalizes the mutable vector.

[`var normalized: Vector3D`](/documentation/Spatial/Vector3D/normalized)

A new vector that represents the normalized copy of the current vector.

[`func projected(Vector3D) -> Vector3D`](/documentation/Spatial/Vector3D/projected(_:))

Returns the vector projected onto the specified vector.

[`func reflected(Vector3D) -> Vector3D`](/documentation/Spatial/Vector3D/reflected(_:))

Returns the reflection direction of the incident vector and a specified unit normal vector.

[`static SPVector3D SPVector3DCrossProduct(SPVector3D x, SPVector3D y);`](/documentation/Spatial/SPVector3DCrossProduct)

Returns the cross product of two vectors.

[`static double SPVector3DDotProduct(SPVector3D x, SPVector3D y);`](/documentation/Spatial/SPVector3DDotProduct)

Returns the dot product of two vectors.

[`static double SPVector3DLength(SPVector3D x);`](/documentation/Spatial/SPVector3DLength)

Returns the length of the vector.

[`static double SPVector3DLengthSquared(SPVector3D x);`](/documentation/Spatial/SPVector3DLengthSquared)

Returns the square of the length of the vector.

[`static SPVector3D SPVector3DNormalize(SPVector3D x);`](/documentation/Spatial/SPVector3DNormalize)

Returns a new vector that represents the normalized copy of the vector.

[`static SPVector3D SPVector3DProject(SPVector3D x, SPVector3D y);`](/documentation/Spatial/SPVector3DProject)

Returns the first vector projected onto the second vector.

[`static SPVector3D SPVector3DReflect(SPVector3D x, SPVector3D y);`](/documentation/Spatial/SPVector3DReflect)

Returns the reflection direction of the incident vector and a specified unit normal vector.

### Transforming a vector

[`func applying(AffineTransform3D) -> Vector3D`](/documentation/Spatial/Vector3D/applying(_:)-1d0mh)

Returns the vector that results from applying an affine transform to the vector.

[`func applying(ProjectiveTransform3D) -> Vector3D`](/documentation/Spatial/Vector3D/applying(_:)-5y3xb)

Returns the vector that results from applying a projective transform to the vector.

[`func applying(Pose3D) -> Vector3D`](/documentation/Spatial/Vector3D/applying(_:)-4k2qi)

Returns a vector that results from applying the specified pose.

[`func unapplying(AffineTransform3D) -> Vector3D`](/documentation/Spatial/Vector3D/unapplying(_:)-6vl3o)

Returns the vector that results from unapplying an affine transform to the vector.

[`func unapplying(ProjectiveTransform3D) -> Vector3D`](/documentation/Spatial/Vector3D/unapplying(_:)-8ookb)

Returns the vector that results from unapplying a projective transform to the vector.

[`func unapplying(Pose3D) -> Vector3D`](/documentation/Spatial/Vector3D/unapplying(_:)-1gzyd)

Returns a vector that results from unapplying the specified pose.

[`func rotated(by: Rotation3D) -> Vector3D`](/documentation/Spatial/Vector3D/rotated(by:)-2gcq4)

Returns the vector rotated by the specified rotation around the origin.

[`func rotated(by: simd_quatd) -> Vector3D`](/documentation/Spatial/Vector3D/rotated(by:)-8bwna)

Returns the vector rotated by the specified quaternion around the origin.

[`func scaled(by: Size3D) -> Vector3D`](/documentation/Spatial/Vector3D/scaled(by:))

Returns the vector scaled by the specified size.

[`func scaledBy(x: Double, y: Double, z: Double) -> Vector3D`](/documentation/Spatial/Vector3D/scaledBy(x:y:z:))

Returns a vector that results from scaling with the specified double-precision values.

[`func uniformlyScaled(by: Double) -> Vector3D`](/documentation/Spatial/Vector3D/uniformlyScaled(by:))

Returns the entity uniformly scaled by the specified scalar value.

[`func sheared(AxisWithFactors) -> Vector3D`](/documentation/Spatial/Vector3D/sheared(_:))

Returns a vector that results from shearing over an axis by shear factors for the other two axes.

[`func applying(ScaledPose3D) -> Vector3D`](/documentation/Spatial/Vector3D/applying(_:)-8fn6a)

Returns a vector that’s transformed by the specified scaled pose.

[`func unapplying(ScaledPose3D) -> Vector3D`](/documentation/Spatial/Vector3D/unapplying(_:)-4uxr2)

Returns a vector that’s transformed by the inverse of the specified scaled pose.

[`static SPVector3D SPVector3DApplyAffineTransform(SPVector3D vector, SPAffineTransform3D transform);`](/documentation/Spatial/SPVector3DApplyAffineTransform)

Returns a vector that results from applying the specified affine transform.

[`static SPVector3D SPVector3DApplyProjectiveTransform(SPVector3D vector, SPProjectiveTransform3D transform);`](/documentation/Spatial/SPVector3DApplyProjectiveTransform)

Returns a vector that results from applying the specified projective transform.

[`static SPVector3D SPVector3DApplyPose(SPVector3D vector, SPPose3D pose);`](/documentation/Spatial/SPVector3DApplyPose)

Returns a vector that results from applying the specified pose.

[`static SPVector3D SPVector3DUnapplyAffineTransform(SPVector3D vector, SPAffineTransform3D transform);`](/documentation/Spatial/SPVector3DUnapplyAffineTransform)

Returns a vector that results from unapplying the specified affine transform.

[`static SPVector3D SPVector3DUnapplyProjectiveTransform(SPVector3D vector, SPProjectiveTransform3D transform);`](/documentation/Spatial/SPVector3DUnapplyProjectiveTransform)

Returns a vector that results from unapplying the specified projective transform.

[`static SPVector3D SPVector3DUnapplyPose(SPVector3D vector, SPPose3D pose);`](/documentation/Spatial/SPVector3DUnapplyPose)

Returns a vector that results from unapplying the specified pose.

[`static SPVector3D SPVector3DRotate(SPVector3D vector, SPRotation3D rotation);`](/documentation/Spatial/SPVector3DRotate)

Returns a vector that results from applying the specified rotation.

[`static SPVector3D SPVector3DRotateByQuaternion(SPVector3D vector, simd_quatd quaternion);`](/documentation/Spatial/SPVector3DRotateByQuaternion)

Returns a vector that results from rotating with the specified quaternion.

[`static SPVector3D SPVector3DScaleBySize(SPVector3D vector, SPSize3D scale);`](/documentation/Spatial/SPVector3DScaleBySize)

Returns a vector that results from scaling with the specified size structure.

[`static SPVector3D SPVector3DScaleBy(SPVector3D vector, double x, double y, double z);`](/documentation/Spatial/SPVector3DScaleBy)

Returns a vector that results from scaling with the specified double-precision values.

[`static SPVector3D SPVector3DScaleUniform(SPVector3D vector, double scale);`](/documentation/Spatial/SPVector3DScaleUniform)

Returns a vector that results from uniformly scaling with the specified double-precision value.

[`static SPVector3D SPVector3DShear(SPVector3D vector, SPAxis shearAxis, double shearFactor0, double shearFactor1);`](/documentation/Spatial/SPVector3DShear)

Returns a vector that results from shearing over an axis by shear factors for the other two axes.

[`static SPVector3D SPVector3DApplyScaledPose(SPVector3D vector, SPScaledPose3D pose);`](/documentation/Spatial/SPVector3DApplyScaledPose)

Returns a vector that’s transformed by the specified scaled pose.

[`static SPVector3D SPVector3DUnapplyScaledPose(SPVector3D vector, SPScaledPose3D pose);`](/documentation/Spatial/SPVector3DUnapplyScaledPose)

Returns a vector that’s transformed by the inverse of the specified scaled pose.

### Comparing values

[`static func == (Vector3D, Vector3D) -> Bool`](/documentation/Spatial/Vector3D/==(_:_:))

Returns a Boolean value that indicates whether two values are equal.

[`static bool SPVector3DEqualToVector(SPVector3D vector1, SPVector3D vector2);`](/documentation/Spatial/SPVector3DEqualToVector)

Returns a Boolean value that indicates whether two values are equal.

### Encoding and decoding a vector

[`init(from: any Decoder) throws`](/documentation/Spatial/Vector3D/init(from:))

Creates a new instance by decoding from the given decoder.

[`func encode(to: any Encoder) throws`](/documentation/Spatial/Vector3D/encode(to:))

Encodes this value into the given encoder.

### Type properties

[`static let forward: Vector3D`](/documentation/Spatial/Vector3D/forward)

A vector that contains the values 0, 0, 1.

[`static let right: Vector3D`](/documentation/Spatial/Vector3D/right)

A vector that contains the values 1, 0, 0.

[`static let up: Vector3D`](/documentation/Spatial/Vector3D/up)

A vector that contains the values 0, 1, 0.

### Applying arithmetic operations

[`static func * (Vector3D, Double) -> Vector3D`](/documentation/Spatial/Vector3D/*(_:_:)-dcwn)

Returns a vector that’s the product of a vector and a scalar value.

[`static func * (Double, Vector3D) -> Vector3D`](/documentation/Spatial/Vector3D/*(_:_:)-64lzt)

Returns a vector that’s the product of a scalar value and a vector.

[`static func * (AffineTransform3D, Vector3D) -> Vector3D`](/documentation/Spatial/Vector3D/*(_:_:)-6rxsr)

Returns the vector that results from applying the affine transform to the vector.

[`static func * (ProjectiveTransform3D, Vector3D) -> Vector3D`](/documentation/Spatial/Vector3D/*(_:_:)-3dpli)

Returns the vector that results from applying the projective transform to the vector.

[`static func * (Pose3D, Vector3D) -> Vector3D`](/documentation/Spatial/Vector3D/*(_:_:)-8y7xq)

Returns a new vector after applying the pose to the vector.

[`static func + (Vector3D, Vector3D) -> Vector3D`](/documentation/Spatial/Vector3D/+(_:_:)-7gbcj)

Returns a vector that’s the element-wise sum of two sizes.

[`static func + (Vector3D, Size3D) -> Size3D`](/documentation/Spatial/Vector3D/+(_:_:)-9xfxv)

Returns a vector that’s the element-wise sum of a vector and a size.

[`static func + (Size3D, Vector3D) -> Size3D`](/documentation/Spatial/Vector3D/+(_:_:)-1xufx)

Returns a vector that’s the element-wise sum of a size and a vector.

[`static func + (Vector3D, Point3D) -> Point3D`](/documentation/Spatial/Vector3D/+(_:_:)-1bq1m)

Returns a vector that’s the element-wise sum of a vector and a point.

[`static func + (Point3D, Vector3D) -> Point3D`](/documentation/Spatial/Vector3D/+(_:_:)-4rsou)

Returns a vector that’s the element-wise sum of a point and a vector.

[`static func - (Vector3D) -> Vector3D`](/documentation/Spatial/Vector3D/-(_:))

Returns a vector that’s the element-wise negation of the vector.

[`static func - (Vector3D, Vector3D) -> Vector3D`](/documentation/Spatial/Vector3D/-(_:_:)-6zam)

Returns a size that’s the element-wise difference of two vectors.

[`static func - (Vector3D, Size3D) -> Size3D`](/documentation/Spatial/Vector3D/-(_:_:)-6lui1)

Returns a size that’s the element-wise difference of a vector and a size.

[`static func - (Size3D, Vector3D) -> Size3D`](/documentation/Spatial/Vector3D/-(_:_:)-3qpww)

Returns a size that’s the element-wise difference of a size and a vector.

[`static func - (Vector3D, Point3D) -> Point3D`](/documentation/Spatial/Vector3D/-(_:_:)-1nz82)

Returns a size that’s the element-wise difference of a vector and a point.

[`static func - (Point3D, Vector3D) -> Point3D`](/documentation/Spatial/Vector3D/-(_:_:)-8sgai)

Returns a size that’s the element-wise difference of a point and a vector.

[`static func *= (inout Vector3D, Double)`](/documentation/Spatial/Vector3D/*=(_:_:))

Multiplies a vector and a double-precision value, and stores the result in the left-hand-side variable.

[`static func += (inout Vector3D, Vector3D)`](/documentation/Spatial/Vector3D/+=(_:_:))

Adds two vectors and stores the result in the left-hand-side variable.

[`static func -= (inout Vector3D, Vector3D)`](/documentation/Spatial/Vector3D/-=(_:_:))

Subtracts a vector from a vector and stores the difference in the left-hand-side variable.

[`static func / (Vector3D, Double) -> Vector3D`](/documentation/Spatial/Vector3D/_(_:_:))

Returns a vector with each element divided by a scalar value.

[`static func /= (inout Vector3D, Double)`](/documentation/Spatial/Vector3D/_=(_:_:))

Divides a vector by a scalar value and stores the result in the left-hand-side variable.

### Initializers

[`init(simd_packed_double4)`](/documentation/Spatial/Vector3D/init(_:)-23qst)

Creates a Spatial vector from a simd packed vector.

[`init(Vector3DFloat)`](/documentation/Spatial/Vector3D/init(_:)-272sg)

Returns a double-precision vector from a single-precision vector.

### Type Methods

[`static func lerp(from: Vector3D, to: Vector3D, t: Vector3D) -> Vector3D`](/documentation/Spatial/Vector3D/lerp(from:to:t:))

Returns a Spatial vector that represents the linear interpolation at `t` between two vectors.

[`static func smoothstep(edge0: Vector3D, edge1: Vector3D, x: Vector3D) -> Vector3D`](/documentation/Spatial/Vector3D/smoothstep(edge0:edge1:x:))

Returns a Spatial vector that represents the smooth interpolation at `x` between two vectors.

### Default Implementations

[AdditiveArithmetic Implementations](/documentation/Spatial/Vector3D/AdditiveArithmetic-Implementations)

[CustomReflectable Implementations](/documentation/Spatial/Vector3D/CustomReflectable-Implementations)

[Decodable Implementations](/documentation/Spatial/Vector3D/Decodable-Implementations)

[Encodable Implementations](/documentation/Spatial/Vector3D/Encodable-Implementations)

[Equatable Implementations](/documentation/Spatial/Vector3D/Equatable-Implementations)

[Hashable Implementations](/documentation/Spatial/Vector3D/Hashable-Implementations)

[Primitive3DProtocol Implementations](/documentation/Spatial/Vector3D/Primitive3DProtocol-Implementations)

[ProjectiveTransformable3D Implementations](/documentation/Spatial/Vector3D/ProjectiveTransformable3D-Implementations)

[Rotatable3DProtocol Implementations](/documentation/Spatial/Vector3D/Rotatable3DProtocol-Implementations)

[Scalable3DProtocol Implementations](/documentation/Spatial/Vector3D/Scalable3DProtocol-Implementations)

[Shearable3D Implementations](/documentation/Spatial/Vector3D/Shearable3D-Implementations)

## Relationships

### Conforms To

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Shearable3D`](/documentation/Spatial/Shearable3D)

[`Hashable`](/documentation/Swift/Hashable)

[`Equatable`](/documentation/Swift/Equatable)

[`CustomReflectable`](/documentation/Swift/CustomReflectable)

[`SpatialTypeProtocol`](/documentation/Spatial/SpatialTypeProtocol)

[`Animatable`](/documentation/SwiftUI/Animatable)

[`Primitive3DProtocol`](/documentation/Spatial/Primitive3DProtocol)

[`AdditiveArithmetic`](/documentation/Swift/AdditiveArithmetic)

[`Escapable`](/documentation/Swift/Escapable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Primitive3D`](/documentation/Spatial/Primitive3D)

[`Sendable`](/documentation/Swift/Sendable)

[`Copyable`](/documentation/Swift/Copyable)

[`Encodable`](/documentation/Swift/Encodable)

[`Scalable3D`](/documentation/Spatial/Scalable3D)

[`Scalable3DProtocol`](/documentation/Spatial/Scalable3DProtocol)

[`VectorArithmetic`](/documentation/SwiftUI/VectorArithmetic)

[`Rotatable3D`](/documentation/Spatial/Rotatable3D)

[`ProjectiveTransformable3D`](/documentation/Spatial/ProjectiveTransformable3D)

[`Rotatable3DProtocol`](/documentation/Spatial/Rotatable3DProtocol)

[`Decodable`](/documentation/Swift/Decodable)

---

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)