本文整理汇总了Java中org.andengine.util.math.MathUtils.distance方法的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.distance方法的具体用法?Java MathUtils.distance怎么用?Java MathUtils.distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.andengine.util.math.MathUtils
的用法示例。
在下文中一共展示了MathUtils.distance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBezierCurveLength
import org.andengine.util.math.MathUtils; //导入方法依赖的package包/类
/**
* Calculates the length of a Bézier curve by taking <code>pSamples</code> samples.
*
* @param pXs x-coordinates of the control points of the Bézier curve.
* @param pYs y-coordinates of the control points of the Bézier curve.
* @param pSamples the number of samples to take. The higher the more accurate.
* @return
*/
public static final float getBezierCurveLength(final float[] pXs, final float[] pYs, final int pSamples) {
float length = 0;
final int n = pXs.length - 1;
float lastX = pXs[0];
float lastY = pYs[0];
for (int k = 1; k <= LENGTH_SAMPLES_DEFAULT; k++) {
final float t = (1f * k) / LENGTH_SAMPLES_DEFAULT;
float x = 0;
float y = 0;
for (int i = 0; i <= n; i++) {
final float bernstein = BezierCurveUtils.getBernsteinPolynomial(t, i, n);
x += pXs[i] * bernstein;
y += pYs[i] * bernstein;
}
length += MathUtils.distance(lastX, lastY, x, y);
lastX = x;
lastY = y;
}
return length;
}
示例2: calculatePointerDistance
import org.andengine.util.math.MathUtils; //导入方法依赖的package包/类
/**
* Calculate the euclidian distance between the first two fingers.
*/
private static float calculatePointerDistance(final MotionEvent pMotionEvent) {
return MathUtils.distance(pMotionEvent.getX(0), pMotionEvent.getY(0), pMotionEvent.getX(1), pMotionEvent.getY(1));
}