<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/RealityCoordinateSpaceProjecting/ray(through:in:to:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "RealityKit",
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:19_RealityKit_SwiftUI0A25CoordinateSpaceProjectingP3ray7through2in2tos5SIMD3VySfG6origin_AJ9directiontSgSo7CGPointV_qd__qd_0_t0cD00eF8ProtocolRd__0A10Foundation0aeF0Rd_0_r0_lF"
  },
  "title" : "ray(through:in:to:)"
}
-->

# ray(through:in:to:)

Determines the position and direction of a ray through the given point
in the 2D space of the view.

```
func ray(through point: CGPoint, in space: some CoordinateSpaceProtocol, to realitySpace: some RealityCoordinateSpace) -> (origin: SIMD3<Float>, direction: SIMD3<Float>)?
```

## Parameters

`point`

A point in the provided coordinate space.

`space`

The 2D coordinate space in which to interpret the `point`.

`realitySpace`

The 3D coordinate space you want the returned ray in.

## Return Value

A 3D ray, expressed in the `realitySpace` coordinate space,
which starts at the camera position and passes through the
specified `point`.

---

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)