The application use AR Core for measuring distance, area and volume also measuring distance and area by GPS. The app use AR Core with Scene View.
AR Core is not an abbreviation. It is the official name of Google’s augmented - reality platform and does not stand for anything like “Augmented Reality Core.” This is confirmed by Google’s documentation, which describes AR Core simply as Google’s platform/SDK for building augmented - reality experiences, not as an acronym.
Implementing measurement tools in AR Core using Java involves a mix of Anchor placement, Pose math, and geometric calculations.
1. Measuring Distance
Distance is the most fundamental AR measurement. It is calculated as the Euclidean distance between two 3D coordinates (Anchors) placed in the AR scene.
The Math:
Given two points P_1(x_1, y_1, z_1)$ and P_2(x_2, y_2, z_2)$ from AR Core Pose objects:
Distance = ((x_2 - x_1)^2 + (y_2 - y_1)^2 + (z_2 - z_1)^2)^(1/2)
2. Measuring Area
To measure area, the user must place at least three anchors to form a polygon. Most AR area measurements assume the surface is a flat plane (2D surface in 3D space).
The Algorithm:
The most common approach is the Shoelace Formula (Surveyor's Formula). Since the points are in 3D, you should first project them onto a 2D plane (using the plane's normal) or ensure all points lie on the same detected AR Core Plane.
Simplified Shoelace Formula:
Area = (1/2) *| sum_{i=1}^{n-1} (x_{i} * y_{i+1} - x_{i+1} *y_{i}) |
3. Measuring Volume
Volume is significantly more complex because it requires depth. There are two primary ways to approach this:
- Box Method (Extrusion):Measure the floor area (as described above) and then measure a vertical distance (height).
Formula: Volume = Area*Height
- Bounding Box Method: Use two diagonal corner points to define a 3D cube.
Formula: V = |x_2 - x_1| * |y_2 - y_1| * |z_2 – z_1|
- Depth API (Advanced): Use AR Core Raw Depth API to create a point cloud of an object and calculate volume via a convex hull or voxelization. This is much more accurate for irregular objects but requires a device with a Time-of-Flight (To F) sensor or high-quality depth support.
Since you're diving into the implementation, the real challenge in AR Core isn't just the math—it's the UX and precision. Measuring a 3D space on a 2D screen can be finicky for users.
Here is a breakdown of how to structure your Java logic for these features:
1. Distance (The Foundation)
To get a clean measurement, you should use to place Anchors. Using anchors ensures that even if the camera drifts, the points stay "locked" to the physical world coordinates.
2. Area (Planar Geometry)
You should restrict your points to a single Plane. If the points are on the same horizontal plane (y values are nearly identical), you can ignore the y-axis and treat it as a 2D polygon calculation.
Implementation Tip: Store your points in a List. As the user adds a new point, dynamically update a "current area" preview. The Shoelace Formula is the standard here because it works for any non-self-intersecting polygon (irregular shapes).
3. Volume (The "Box" Method)
Calculating the volume of an arbitrary 3D object is very difficult without a LiDAR sensor. For a standard Java/AR Core app, the most reliable way is the Extruded Polygon method:
1. Define the Base: User clicks points to define the floor area (A).
2. Define the Height: The user clicks on a point above the ground and sets the height (h), which corresponds to the distance between that point and the center of the base.
3. Calculate: V = A * h.
The Depth API: If the device supports it, enable the Raw Depth API. It allows you to perform hit-tests against "non-planar" objects (like a couch or a ball) which standard plane-finding might miss.
Smoothing: AR coordinates can jitter. Use a simple Moving Average Filter on the camera pose or the hit-test results to prevent the measurement numbers from jumping around rapidly.