<!--
{
  "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/Ray3D",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Spatial"
    ],
    "preciseIdentifier" : "c:@SA@SPRay3D"
  },
  "title" : "Ray3D"
}
-->

# Ray3D

A ray in a 3D coordinate system.

```
struct Ray3D
```

## Topics

### Creating a 3D ray structure

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

Creates a ray structure.

[`init(origin: Point3D, direction: Vector3D)`](/documentation/Spatial/Ray3D/init(origin:direction:)-5sxkl)

Creates a ray with the specified origin and the specified direction from Spatial primitives.

[`init(origin: simd_float3, direction: simd_float3)`](/documentation/Spatial/Ray3D/init(origin:direction:)-3gfcj)

Creates a ray with the specified origin and the specified direction from single-precision vectors.

[`init(origin: simd_double3, direction: simd_double3)`](/documentation/Spatial/Ray3D/init(origin:direction:)-47w1c)

Creates a ray with the specified origin and the specified direction from double-precision vectors.

[`static SPRay3D SPRay3DMakeWithVector(simd_double3 origin, simd_double3 direction);`](/documentation/Spatial/SPRay3DMakeWithVector)

Creates a ray with the specified origin and the specified direction from double-precision vectors.

### Inspecting a 3D ray’s properties

[`var origin: Point3D`](/documentation/Spatial/Ray3D/origin)

The origin of the ray.

[`var direction: Vector3D`](/documentation/Spatial/Ray3D/direction)

The direction of the ray.

### Transforming a 3D ray structure

[`func apply(Pose3D)`](/documentation/Spatial/Ray3D/apply(_:))

Applies the specified pose to the ray.

[`func applying(AffineTransform3D) -> Ray3D`](/documentation/Spatial/Ray3D/applying(_:)-337n0)

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

[`func applying(ProjectiveTransform3D) -> Ray3D`](/documentation/Spatial/Ray3D/applying(_:)-2aom9)

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

[`func applying(Pose3D) -> Ray3D`](/documentation/Spatial/Ray3D/applying(_:)-34rqi)

Returns a ray that results from applying the specified pose.

[`func unapplying(AffineTransform3D) -> Ray3D`](/documentation/Spatial/Ray3D/unapplying(_:)-7bc37)

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

[`func unapplying(ProjectiveTransform3D) -> Ray3D`](/documentation/Spatial/Ray3D/unapplying(_:)-6tj2w)

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

[`func unapplying(Pose3D) -> Ray3D`](/documentation/Spatial/Ray3D/unapplying(_:)-928o9)

Unapplies the specified pose to the ray.

[`func rotated(by: Rotation3D) -> Ray3D`](/documentation/Spatial/Ray3D/rotated(by:)-qxp0)

Returns a ray that results from applying the specified rotation.

[`func rotated(by: simd_quatd) -> Ray3D`](/documentation/Spatial/Ray3D/rotated(by:)-81glv)

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

[`func rotated(by: simd_quatd, around: Point3D) -> Ray3D`](/documentation/Spatial/Ray3D/rotated(by:around:)-uzon)

Returns a ray that’s rotated by the specified quaternion around a specified pivot.

[`func rotated(by: Rotation3D, around: Point3D) -> Ray3D`](/documentation/Spatial/Ray3D/rotated(by:around:)-7h43)

Returns a ray that’s rotated by the specified rotation around a specified pivot.

[`func applying(ScaledPose3D) -> Ray3D`](/documentation/Spatial/Ray3D/applying(_:)-6hfqw)

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

[`func unapplying(ScaledPose3D) -> Ray3D`](/documentation/Spatial/Ray3D/unapplying(_:)-9x164)

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

[`static SPRay3D SPRay3DApplyAffineTransform(SPRay3D ray, SPAffineTransform3D transform);`](/documentation/Spatial/SPRay3DApplyAffineTransform)

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

[`static SPRay3D SPRay3DApplyProjectiveTransform(SPRay3D ray, SPProjectiveTransform3D transform);`](/documentation/Spatial/SPRay3DApplyProjectiveTransform)

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

[`static SPRay3D SPRay3DTranslate(SPRay3D ray, SPSize3D offset);`](/documentation/Spatial/SPRay3DTranslate-13y4m)

Returns a ray with an origin that’s offset by the specified size.

[`static SPRay3D SPRay3DTranslate(SPRay3D ray, SPVector3D offset);`](/documentation/Spatial/SPRay3DTranslate-2t6zr)

Returns a ray with an origin that’s offset by the specified vector.

[`static SPRay3D SPRay3DApplyPose(SPRay3D ray, SPPose3D pose);`](/documentation/Spatial/SPRay3DApplyPose)

Returns a ray that results from applying the specified pose.

[`static SPRay3D SPRay3DUnapplyAffineTransform(SPRay3D ray, SPAffineTransform3D transform);`](/documentation/Spatial/SPRay3DUnapplyAffineTransform)

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

[`static SPRay3D SPRay3DUnapplyProjectiveTransform(SPRay3D ray, SPProjectiveTransform3D transform);`](/documentation/Spatial/SPRay3DUnapplyProjectiveTransform)

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

[`static SPRay3D SPRay3DUnapplyPose(SPRay3D ray, SPPose3D pose);`](/documentation/Spatial/SPRay3DUnapplyPose)

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

[`static SPRay3D SPRay3DRotate(SPRay3D ray, SPRotation3D rotation);`](/documentation/Spatial/SPRay3DRotate)

Returns a ray that results from applying the specified rotation.

[`static SPRay3D SPRay3DRotateAroundPoint(SPRay3D ray, SPRotation3D rotation, SPPoint3D pivot);`](/documentation/Spatial/SPRay3DRotateAroundPoint)

Returns a ray that’s rotated by the specified rotation around a specified pivot.

[`static SPRay3D SPRay3DRotateByQuaternion(SPRay3D ray, simd_quatd quaternion);`](/documentation/Spatial/SPRay3DRotateByQuaternion)

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

[`static SPRay3D SPRay3DRotateByQuaternionAroundPoint(SPRay3D ray, simd_quatd quaternion, SPPoint3D pivot);`](/documentation/Spatial/SPRay3DRotateByQuaternionAroundPoint)

Returns a ray that’s rotated by the specified quaternion around a specified pivot.

[`static SPRay3D SPRay3DApplyScaledPose(SPRay3D ray, SPScaledPose3D pose);`](/documentation/Spatial/SPRay3DApplyScaledPose)

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

[`static SPRay3D SPRay3DUnapplyScaledPose(SPRay3D ray, SPScaledPose3D pose);`](/documentation/Spatial/SPRay3DUnapplyScaledPose)

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

### Checking characteristics

[`var isFinite: Bool`](/documentation/Spatial/Ray3D/isFinite)

A Boolean value that indicates whether all of the values of the ray are finite.

[`var isNaN: Bool`](/documentation/Spatial/Ray3D/isNaN)

A Boolean value that indicates whether the ray contains any NaN values.

[`var isZero: Bool`](/documentation/Spatial/Ray3D/isZero)

A Boolean value that indicates whether all of the values of the ray are zero.

[`func intersects(Rect3D) -> Bool`](/documentation/Spatial/Ray3D/intersects(_:))

Returns a Boolean value that indicates whether a ray intersects a rectangle.

[`func intersects(sphereOrigin: Point3D, sphereRadius: Double) -> Bool`](/documentation/Spatial/Ray3D/intersects(sphereOrigin:sphereRadius:))

Returns a Boolean value that indicates whether the ray intersects a specified sphere.

[`static bool SPRay3DIsFinite(SPRay3D ray);`](/documentation/Spatial/SPRay3DIsFinite)

A Boolean value that indicates whether all of the values of the ray are finite.

[`static bool SPRay3DIsNaN(SPRay3D ray);`](/documentation/Spatial/SPRay3DIsNaN)

A Boolean value that indicates whether the ray contains any NaN values.

[`static bool SPRay3DIsZero(SPRay3D ray);`](/documentation/Spatial/SPRay3DIsZero)

A Boolean value that indicates whether all of the values of the ray are zero.

[`static bool SPRay3DIntersectsRect(SPRay3D ray, SPRect3D rect);`](/documentation/Spatial/SPRay3DIntersectsRect)

Returns a Boolean value that indicates whether a ray intersects a rectangle.

### Comparing values

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

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

[`static bool SPRay3DEqualToRay(SPRay3D ray1, SPRay3D ray2);`](/documentation/Spatial/SPRay3DEqualToRay)

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

### Ray constants

[`static const SPRay3D SPRay3DInfinity;`](/documentation/Spatial/SPRay3DInfinity)

[`static const SPRay3D SPRay3DZero;`](/documentation/Spatial/SPRay3DZero)

### Applying arithmetic operations

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

Returns the ray that results from applying the pose to the ray.

### Initializers

[`init(Ray3DFloat)`](/documentation/Spatial/Ray3D/init(_:))

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

[`init(origin: Point3D, direction: Vector3D)`](/documentation/Spatial/Ray3D/init(origin:direction:)-63yk4)

Creates a ray from Spatial primitives that describe the origin and direction.

### Default Implementations

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

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

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

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

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

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

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

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

## Relationships

### Conforms To

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

---

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)