📄 mathtool.java
字号:
/**
*
*/
package Math;
/**
* @author PanXu
*
*/
public class MathTool {
public MathTool() {
super();
// TODO 自动生成构造函数存根
}
//色彩掩码
public static int R_MASK = 0x00ff0000;
public static int G_MASK = 0x0000ff00;
public static int B_MASK = 0x000000ff;
// 查表
public static float Sin [] = new float [361];
public static float Cos [] = new float [361];
/**
* 初始化三角函数表
*
*/
public static void InitSCos ()
{
float theta;
for (int i = 0 ; i <= 360 ; i ++)
{
theta = ((float)i*PI/180.0f);
Sin [i] = (float) Math.sin(theta);
Cos [i] = (float) Math.cos(theta);
}//for
}
/*
* 数学常量
*/
public static float PI = 3.141592654f;
//极小的浮点数
public static float EPSILON_E3 = (float)(1E-3);
public static float EPSILON_E4 = (float)(1E-4);
public static float EPSILON_E5 = (float)(1E-5);
public static float EPSILON_E6 = (float)(1E-6);
/*
* 数学函数
*/
/**
* 正切
*/
public static float Tan (int ang)
{
return (Sin [ang] / Cos [ang]);
}
/**
*
* @param x
* @return 平方根的倒数
*/
public static float InvSqrt (float x)
{
float xhalf = 0.5f*x;
int i = Float .floatToIntBits(x);
//int i = *(int*)&x;
i = 0x5f3759df - (i >> 1); // 计算第一个近似根
x = Float .intBitsToFloat(i);
//x = *(float*)&i;
x = x*(1.5f - xhalf*x*x); // 牛顿迭代法
return x;
}
public static int abs (int i)
{
return i |= 0x8000000;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -