gpt4 book ai didi

android - 如果已知顶点和边,如何在 android ArCore 中找到以平方米为单位的面积?

转载 作者:行者123 更新时间:2023-11-30 05:12:06 24 4
gpt4 key购买 nike

下面是来自 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();
}

从 Pose 获得的顶点计算 AREA

area = sqrt(shoelaceFormulaToFindArea(arrayOfVertex));
final String 结果 = "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。

最佳答案

犯了一个简单的错误。我从 3d 平面传递 ty() 而不是 tz()。一旦我将 tx & tz() 传递给鞋带公式,就得到了这个区域。

关于android - 如果已知顶点和边,如何在 android ArCore 中找到以平方米为单位的面积?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53533445/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com