Files
FridaBox/app/src/main/java/top/niunaijun/blackboxa/util/MathUtil.java
T
2026-02-04 22:09:34 +05:30

47 lines
1.2 KiB
Java

package top.niunaijun.blackboxa.util;
import android.graphics.Point;
import android.graphics.PointF;
public class MathUtil {
public MathUtil() {
}
public static int getDistance(PointF A, PointF B) {
return (int) Math.sqrt(Math.pow(A.x - B.x, 2) + Math.pow(A.y - B.y, 2));
}
public static int getDistance(float x1, float y1, float x2, float y2) {
return (int) Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
}
public static Point getPointByCutLength(Point A, Point B, int cutLength) {
float radian = getRadian(A, B);
return new Point(A.x + (int) (cutLength * Math.cos(radian)), A.y + (int) (cutLength * Math.sin(radian)));
}
public static float getRadian(Point A, Point B) {
float lenA = B.x - A.x;
float lenB = B.y - A.y;
float lenC = (float) Math.sqrt(lenA * lenA + lenB * lenB);
float radian = (float) Math.acos(lenA / lenC);
radian = radian * (B.y < A.y ? -1 : 1);
return radian;
}
public static double angle2Radian(double angle) {
return angle / 180 * Math.PI;
}
public static double radian2Angle(double radian) {
return radian / Math.PI * 180;
}
}