Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.

How do I get the location of a SpatialAnchor?


I have a 3D DirectX Holographic app that is using spatial anchors and I was wandering how I could get the Vector3 coordinates of the SpatialAnchor.

The spatial anchor is coming from Windows.Perception.Spatial.SpatialAnchor.

This is all in C# and I have tried using the SpatialPointerPose to get the HeadPose and get the position off that but that is the position of the HoloLens and not the position of the SpatialAnchor. I only tried the HeadPose because it was the only way I could find that would give me a position.

I have had a look into the SpatialAnchor.CoordinateSystem but could not find a way to get the Vector3 coordinates.

Any help is greatly appreciated!

Best Answer


  • I haven't looked into all the SpatialAnchor code yet, however if you have the position of the HoloLens, when it is hit testing/ collinding with your hologram, then you effectively can calculate the position of the anchor. You have an Up vector, and a surface normal vector. Anytime you have at least 2 you can orthogonally calculate the 3rd, which in this case is the X vector you're looking for to get the coordinates. By getting the cross product of the UP and Normal vectors you get your X vector, hence your position in space where the Hologram is. Is this what you're looking for?.

    Dwight Goins
    CAO & Founder| Independent Architect | Trainer and Consultant | Sr. Enterprise Architect
    MVP | MCT | MCSD | MCPD | SharePoint TS | MS Virtual TS |Windows 8 App Store Developer | Linux Gentoo Geek | Raspberry Pi Owner | Micro .Net Developer | Kinect For Windows Device Developer

  • //Creates an anchor at the origin of the specified coordinate system.
    public static SpatialAnchor TryCreateRelativeTo(SpatialCoordinateSystem coordinateSystem)

    //Creates an anchor at a specific position within the specified coordinate system.
    public static SpatialAnchor TryCreateRelativeTo(SpatialCoordinateSystem coordinateSystem, Vector3 position)

    //Creates an anchor at a specific position and orientation within the specified coordinate system.
    public static SpatialAnchor TryCreateRelativeTo(SpatialCoordinateSystem coordinateSystem, Vector3 position, Quaternion orientation)

    More info: https://msdn.microsoft.com/en-us/library/windows/apps/windows.perception.spatial.spatialanchor.aspx

  • Thanks for all the replies. I haven't continued on this project since this question but I may be jumping back into it soon so I will post my reply as best I can.

    I should have added that these spatial anchors were coming from the WorldAnchorStore
    so they are already created hence I can't get them from the position when creating them.

    As for your answer @mlfarrell, I believe that is in C++ and I mentioned that I am doing this in C# but I will set that as the answer for now and check on it when I get back to my project and convert it to C#.

Sign In or Register to comment.