The problem with this method:
If the user isn’t moving and simply marks two points in front of them, the app has no way of knowing the angle between them based solely on the distance. To be mathematically accurate, we must also use the Azimuth from the compass.
The more accurate "Java" code for Area (with angle):
If you want the user to mark 2 points from the same location, you need to calculate the angle at which the phone was rotated between the two measurements.
// In onSensorChanged, we also record the azimuth (orientation[0])
float currentAzimuth;
// When a point is captured, we record the distance AND the angle
double d1 = capturedDistances.get(0);
double d2 = capturedDistances.get(1);
double angleBetween = Math.abs(azimuth2 - azimuth1);
// Formula for the area of a triangle given two sides and the angle between them
// (Assuming we are measuring the area of a triangle from our location to the two points)
double area = 0.5 * d1 * d2 * Math.sin(Math.toRadians(angleBetween));
For Volume (3 points):
With the two points, we have the base (Area). The third point is usually used for Height.
The user points at the base of the wall (records the distance).
The user raises the phone toward the ceiling.
We calculate the difference in slope to find the vertical height H.
Volume = Area \times H.
The app, along with other specific features, has additional functions such as location tracking; calculated distances, areas, and volumes can be measured in meters, centimeters, inches, and feet, and you can select the height at which the device’s camera will measure.