Search code examples
iosaugmented-realityarkit

Augmented Reality - Distance between marker image and Camera in ArKit?


I want to calculate the distance between any marker image saved in the iOS project which is used for detecting in Augmented Reality and your current position i.e. camera position using ARKIT ?


Solution

  • As Apple’s documentation and sample code note:

    • A detected image is reported to your app as an ARImageAnchor object.
    • ARImageAnchor is a subclass of ARAnchor.
    • ARAnchor has a transform property, which indicates its position and orientation in 3D space.
    • ARKit also provides you an ARCamera on every frame (or you can get it from the session’s currentFrame).
    • ARCamera also has a transform property, indicating the camera’s position and orientation in 3D space.
    • You can get the translation vector (position) from a 4x4 transform matrix by extracting the last column vector.

    That should be enough for you to connect the dots...