/// <summary> /// Calculates the axis-aligned bounding box of the static points /// </summary> void calcStaticCenterPoint() { if (pointsStatic.Length != 0) { staticCenter = PointTransform.GetBoxCenterPoint(pointsStatic); } }
/// <summary> /// Calculates the axis-aligned bounding box of all points /// </summary> void calcFixedCenterPoint() { if (pointsAll.Length != 0) { fixedCenter = PointTransform.GetBoxCenterPoint(pointsAll); } }
/// <summary> /// Calculates the angle against the x-axis of just one finger from the center point. /// Since the centerpoint used is the fixed center point using just one finger gives you the /// most reliable angle calculation for calculating angle changed. It's also a nice optimisation. /// There is some edge cases where this is not ideal, but they are unlikely to be encountered /// under normal usage. /// </summary> /// <param name="center">The center of the axis-aligned bounding box of all fingers</param> /// <returns></returns> float getAngle(PointF center) { if (this.Count == 0) { return(0f); } PointF pTouch = this.First().Value.TouchPoint; return(PointTransform.GetAngle(center, pTouch)); }
/// <summary> /// Calculates the distance of just one finger from the center point. /// Since the centerpoint used is the fixed center point all fingers are roughly equidistant. /// Since this is called every frame, this is a nice optimisation. /// </summary> /// <param name="center">The center of the axis-aligned bounding box of all fingers</param> /// <returns></returns> float getDistanceFromCenter(PointF center) { if (this.Count == 0) { return(0f); } PointF pTouch = this.First().Value.TouchPoint; return(PointTransform.GetDistanceFromCenter(center, pTouch)); }
/// <summary> /// Gets the average distance of the passed points from the center. /// </summary> /// <param name="center">Center to calculate distance from.</param> /// <param name="points">Points to average distance for.</param> /// <returns></returns> public static float GetAvgDistanceFromCenter(PointF center, PointF[] points) { if (points.Length == 0) { return(0f); } float avgDist = 0f; for (int i = 0; i < points.Length; i++) { PointF p = points[i]; avgDist += PointTransform.GetDistance(center, p); } avgDist /= points.Length; return(avgDist); }
/// <summary> /// Returns the angle in degrees from the passed point in comparision /// to the x-axis of the centerpoint passed. /// </summary> /// <param name="centerPoint">Center point for the x-axis to calculate the angle against.</param> /// <param name="point">The point to compare against the x-axis.</param> /// <returns>Degrees between the point and the center point.</returns> public static float GetAngle(PointF centerPoint, PointF point) { return(ExtMaths.RadiansToDegrees(PointTransform.GetAngleRadiansTan(centerPoint, point))); }
/// <summary> /// Gets the distance of the passed point from the center. /// </summary> /// <param name="center">Center to calculate distance from.</param> /// <param name="points">Point to distance for.</param> /// <returns></returns> public static float GetDistanceFromCenter(PointF center, PointF point) { float dist = PointTransform.GetDistance(center, point); return(dist); }