问题描述
是否可以计算两个HitResult
`s之间的距离?
Is it possible to calculate distance between two HitResult
`s ?
或者我们如何使用ARCore计算真实距离(例如米)?
Or how we can calculate real distance (e.g. meters) using ARCore?
推荐答案
在Java ARCore中,世界单位是米(我刚刚意识到我们可能不会对此进行记录... aaa看起来不行.糟糕,错误归档).通过减去两个Pose
的平移分量,您可以获得它们之间的距离.您的代码如下所示:
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:
首次命中为hitResult
:
startAnchor = session.addAnchor(hitResult.getHitPose());
第二次命中为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);
假定这些命中结果不在同一帧上发生,则创建Anchor
很重要,因为每次调用Session.update()
时都可以重塑虚拟世界.通过使用锚点而不是仅使用Pose保持该位置,其Pose将会更新以在这些重塑过程中跟踪物理特征.
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.
这篇关于如何使用ARCore测量距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!