Is it possible to calculate distance between two HitResult
`s ?
Or how we can calculate real distance (e.g. meters) using ARCore?
Google says the Measure app is accurate to within half an inch. Having tested it a few times, I'd say that's a safe bet. However, ARCore isn't as good at remembering where objects were when you move the camera to an entirely different part of a room and then come back to your measurement tool.
Measure Up uses WebXR to help you calculate the length, area and volume of the things around you - all straight from the browser. Follow the link to open Measure Up in Chrome for Android and start measuring the world in augmented reality. Built by Google Creative Lab using the WebXR API.
In Java ARCore world units are meters (I just realized we might not document this... aaaand looks like nope. Oops, bug filed). By subtracting the translation component of two Pose
s you can get the distance between them. Your code would look something like this:
On first hit as hitResult
:
startAnchor = session.addAnchor(hitResult.getHitPose());
On second hit as hitResult
:
Pose startPose = startAnchor.getPose();
Pose endPose = hitResult.getHitPose();
// Clean up the anchor
session.removeAnchors(Collections.singleton(startAnchor));
startAnchor = null;
// Compute the difference vector between the two hit locations.
float dx = startPose.tx() - endPose.tx();
float dy = startPose.ty() - endPose.ty();
float dz = startPose.tz() - endPose.tz();
// Compute the straight-line distance.
float distanceMeters = (float) Math.sqrt(dx*dx + dy*dy + dz*dz);
Assuming that these hit results don't happen on the same frame, creating an Anchor
is important because the virtual world can be reshaped every time you call Session.update()
. By holding that location with an anchor instead of just a Pose, its Pose will update to track the physical feature across those reshapings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With