If I hit test using a 2D coordinate on the screen, often the HitResult list can be empty. Is it possible to return the closest point or trackable instead of an empty list?
Your best approach is probably to iterate through the available point cloud points, compute the screen space position of each (multiply by projection_matrix * view_matrix and divide by the resulting w coordinate, then map -1..1 onto the display width and height) and find the one that's closest in screen cordinates.
If using Sceneform, you can use Camera.worldToScreenPoint to convert a world position into a screen position.
I am using Sceneform. I used PointCloud to get the float buffer with points, and Camera.worldToScreenPoint to find the closest Point in float buffer.
How can I create an anchor at the closest point from the float buffer? Do I need to run a HitTest from the ScreenPoint position or is there a way to use the 3D position extracted from Float buffer?
use Session.createAnchor(Pose.makeTranslation(...)) to create an anchor at an arbitrary location.
Closing for inactivity.
Pose.makeTranslation() only gives the position with default rotation. What if we want orientation as well? I know how to use Pose.makeRotation() but going by the way mentioned above, how can we extract the quaternion of the closest point?
@arnsniper: Individual points don't have an orientation. It's only when you hit test agains them that we search for a planar cluster and compute a pose normal to the fit plane. If you want to combine the orientation of one pose and a separate translation you can do Pose.makeTranslation(...).compose(orientedPose.extractRotation()).
Most helpful comment
Your best approach is probably to iterate through the available point cloud points, compute the screen space position of each (multiply by
projection_matrix * view_matrixand divide by the resulting w coordinate, then map -1..1 onto the display width and height) and find the one that's closest in screen cordinates.