📄 vector3d.java
字号:
/**
*
*/
package Math;
/**
* @author PanXu
*
*/
public class Vector3D {
/**
*
*/
public static final int X = 0 ;
public static final int Y = 0 ;
public static final int Z = 0 ;
public float M[] = null;
public Vector3D() {
super();
// TODO 自动生成构造函数存根
M = new float [3];
M[0] = 0 ;
M[1] = 0 ;
M[2] = 0 ;
}
public Vector3D(float x , float y ,float z) {
super();
// TODO 自动生成构造函数存根
M = new float [3];
M[0] = x ;
M[1] = y ;
M[2] = z ;
}
/*
* Build
*/
public void Init (float x ,float y , float z)
{
this .M[0] = x;
this .M[1] = y;
this .M[2] = z;
}
public static Vector3D Build_Vec3D_Stack (Point3D s , Point3D e)
{
return new Vector3D (e.M[0] - s.M[0] , e.M[1] - s.M[1] , e.M[2] - s.M[2]);
}
public void Build_Vec3D (Point3D s , Point3D e)
{
this .M[0] = e.M[0] - s.M[0];
this .M[1] = e.M[1] - s.M[1];
this .M[2] = e.M[2] - s.M[2];
}
public void Set_Zero ()
{
this .M[0] = 0 ; this .M[1] = 0; this .M[2] = 0;
}
/*
* 规格化为2D向量
*/
public void DIVW (){
this .M[0] /= this .M[2];
this .M[1] /= this .M[2];
}
/*
* 运算
*/
public Vector3D Vec3D_ADD_Stack (Vector3D a , Vector3D b){
Vector3D res = new Vector3D();
res .M[0] = a .M[0] + b.M[0];
res .M[1] = a .M[1] + b.M[1];
res .M[2] = a .M[2] + b.M[2];
return res ;
}
public void Vec3D_ADD (Vector3D a , Vector3D b){
this .M[0] = a .M[0] + b.M[0];
this .M[1] = a .M[1] + b.M[1];
this .M[2] = a .M[2] + b.M[2];
}
//减
public Vector3D Vec3D_SUB_Stack (Vector3D a , Vector3D b){
Vector3D res = new Vector3D();
res .M[0] = a .M[0] - b.M[0];
res .M[1] = a .M[1] - b.M[1];
res .M[2] = a .M[2] - b.M[2];
return res ;
}
public void Vec3D_SUB (Vector3D a , Vector3D b){
this .M[0] = a .M[0] - b.M[0];
this .M[1] = a .M[1] - b.M[1];
this .M[2] = a .M[2] - b.M[2];
}
//点积
public float Vec3D_DOT (Vector3D a , Vector3D b)
{
return (a.M[0] * b.M[0] + a.M[1] * b.M[1] + a.M[2] * b.M[2]);
}
//叉积
public Vector3D Vec3D_Cross (Vector3D a , Vector3D b)
{
Vector3D res = new Vector3D();
res .M[X] = a .M[Y] * b.M[Z] - a.M[Z] * b.M[Y];
res .M[Y] = a .M[X] * b.M[Z] - a.M[Z] * b.M[X];
res .M[Z] = a .M[Y] * b.M[X] - a.M[X] * b.M[Y];
return res ;
}
//矩阵乘以向量
public Vector3D MAT3X3_MUL_VEC3D (Matrix3X3 Mat)
{
Vector3D res = new Vector3D();
res .M[0] = M[0] * Mat.M[0][0] + M[1] * Mat.M[1][0] + M[2] * Mat.M[2][0];
res .M[1] = M[0] * Mat.M[0][1] + M[1] * Mat.M[1][1] + M[2] * Mat.M[2][1];
res .M[2] = M[0] * Mat.M[0][2] + M[1] * Mat.M[1][2] + M[2] * Mat.M[2][2];
return res ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -