This commit is contained in:
2024-10-05 04:22:34 +08:00
parent 5993f231fd
commit 30911fcf5c
298 changed files with 28632 additions and 28632 deletions

View File

@@ -1,61 +1,61 @@
import { Vec2 } from 'cc'
export default class MathUtils {
/**
* 2个点之前的直线距离
* @param x1
* @param y1
* @param x2
* @param y2
*/
public static distance(x1: number, y1: number, x2: number, y2: number) {
// 设两点AX1,Y1,BX2,Y2
// 距离D=X2-X1的平方+Y2-Y1平方的和开平方
return Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
}
/**
* 2点间的向量
* @param p1
* @param p2
*/
public static sub(p1: Vec2, p2: Vec2) {
return new Vec2(p1.x - p2.x, p1.y - p2.y)
}
/**
* 弧度转角度
* @param radians
*/
public static radiansToDegrees(radians: number) {
return (180 / Math.PI) * radians
}
/**
* 角度转弧度
* @param degrees
*/
public static degreesToRadians(degrees: number) {
return (Math.PI * degrees) / 180
}
/**
* 返回2点间的弧度
* @param startP
* @param endP
*/
public static p2pRad(startP: Vec2, endP: Vec2) {
const rad: number = Math.atan2(endP.y - startP.y, endP.x - startP.x)
return rad
}
/**
* 针对捕鱼鱼的方向特定实现的鱼方向转换
* @param rot
*/
public static rotation2Fish(rot: number) {
if (rot >= 0 && rot <= 180) rot = 180 - rot
else rot = -180 - rot
return rot
}
}
import { Vec2 } from 'cc'
export default class MathUtils {
/**
* 2个点之前的直线距离
* @param x1
* @param y1
* @param x2
* @param y2
*/
public static distance(x1: number, y1: number, x2: number, y2: number) {
// 设两点AX1,Y1,BX2,Y2
// 距离D=X2-X1的平方+Y2-Y1平方的和开平方
return Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
}
/**
* 2点间的向量
* @param p1
* @param p2
*/
public static sub(p1: Vec2, p2: Vec2) {
return new Vec2(p1.x - p2.x, p1.y - p2.y)
}
/**
* 弧度转角度
* @param radians
*/
public static radiansToDegrees(radians: number) {
return (180 / Math.PI) * radians
}
/**
* 角度转弧度
* @param degrees
*/
public static degreesToRadians(degrees: number) {
return (Math.PI * degrees) / 180
}
/**
* 返回2点间的弧度
* @param startP
* @param endP
*/
public static p2pRad(startP: Vec2, endP: Vec2) {
const rad: number = Math.atan2(endP.y - startP.y, endP.x - startP.x)
return rad
}
/**
* 针对捕鱼鱼的方向特定实现的鱼方向转换
* @param rot
*/
public static rotation2Fish(rot: number) {
if (rot >= 0 && rot <= 180) rot = 180 - rot
else rot = -180 - rot
return rot
}
}