Ниже приведен код из примера Google Hello AR, который я должен изменить, чтобы найти область выбранного непересекающегося региона, но получаю неправильную область
int size = anchors.size();
arrayOfVertex = new float[size + 1][2];
Pose firstPose = getPose(anchors.get(0));
arrayOfVertex[0][0] = firstPose.tx();
arrayOfVertex[0][1] = firstPose.ty();
Pose pose0 = getPose(anchors.get(0));
for (int i = 1; i < anchors.size(); i++) {
pose1 = getPose(anchors.get(i));
float meter = (getDistance(pose0, pose1));
total += meter;
sb.append(" + ").append(String.format("%.2f", meter));
pose0 = pose1;
arrayOfVertex[i][0] = pose0.tx();
arrayOfVertex[i][1] = pose0.ty();
}
Расчет областииз вершин, полученных из Позы
area = sqrt(shoelaceFormulaToFindArea(arrayOfVertex));
final String result = "Area(m sq): " + area;
Формула, которую я использую, чтобы найти ОБЛАСТЬ
public double shoelaceFormulaToFindArea(float[][] arr)
{
int n = arr.length;
/** copy initial point to last row **/
arr[n - 1][0] = arr[0][0];
arr[n - 1][1] = arr[0][1];
double det = 0.0;
/** add product of x coordinate of ith point with y coordinate of (i + 1)th point **/
for (int i = 0; i < n - 1; i++)
det += (double) (arr[i][0] * arr[i + 1][1]);
/** subtract product of y coordinate of ith point with x coordinate of (i + 1)th point **/
for (int i = 0; i < n - 1; i++)
det -= (double) (arr[i][1] * arr[i + 1][0]);
/** find absolute value and divide by 2 **/
det = Math.abs(det);
det /= 2;
return det;
}
ПолучениеНеправильная зона, а иногда и 0,0.