0
如果我有ArrayList
的Path
值,我如何计算创建的Path
值生成的图的质心?然后,我怎么才能找到质心w.r.的相对位置,由Path
生成的数字。需要指导或帮助。谢谢! :-)计算android.graphics.path值的质心,并找到质心的相对位置w.r.t路径
如果我有ArrayList
的Path
值,我如何计算创建的Path
值生成的图的质心?然后,我怎么才能找到质心w.r.的相对位置,由Path
生成的数字。需要指导或帮助。谢谢! :-)计算android.graphics.path值的质心,并找到质心的相对位置w.r.t路径
也许这可以帮助你一点(从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;
}