値がある場合ArrayList
、Path
作成された値によって生成された図の重心を計算するにはどうすればPath
よいですか? そして、によって生成された図に対する重心の相対位置をどのように見つけることができますかPath
。ガイダンスまたはヘルプが必要です。ありがとうございました!:-)
1075 次
1 に答える
3
たぶん、これは少し役に立ちます (Android のソースから
C:\adt-bundle-windows\sdk\sources\android-17\android\gesture\GestureUtils.java
):
/**
* Calculates the centroid of a set of points.
*
* @param points the points in the form of [x1, y1, x2, y2, ..., xn, yn]
* @return the centroid
*/
static float[] computeCentroid(float[] points) {
float centerX = 0;
float centerY = 0;
int count = points.length;
for (int i = 0; i < count; i++) {
centerX += points[i];
i++;
centerY += points[i];
}
float[] center = new float[2];
center[0] = 2 * centerX / count;
center[1] = 2 * centerY / count;
return center;
}
于 2012-11-20T22:13:24.537 に答える