坐标转换C++自己做的

时间:2015-01-04 13:59:11
【文件属性】:

文件名称:坐标转换C++自己做的

文件大小:8KB

文件格式:TXT

更新时间:2015-01-04 13:59:11

坐标

public class CoordTrans7Param { public double[,] values=new double[7,1]; //{{dx},{dy},{dz},{rx},{ry},{rz},{k}}; //public double   两个坐标系转换一般需要平移,旋转,缩放共七参数。 Y=(1+k)*M(x,y,z)*X+dX; public double[,] values=new double[7,1]; //{{dx},{dy},{dz},{rx},{ry},{rz},{k}}; //public double dx,dy,dz,rx,ry,rz,k; public void Set4Param(double dx,double dy,double dz,double k) { this.dx=dx; this.dy=dy; this.dz=dz; this.k=k; this.rx=this.ry=this.rz=0; } public void SetRotationParamRad(double rx,double ry,double rz) { this.rx=rx; this.ry=ry; this.rz=rz; } public void SetRotationParamMM(double rx,double ry,double rz) { SetRotationParamRad(rx*Math.PI/648000,ry*Math.PI/648000,rz*Math.PI/648000); } private double[,] GetMx() { double [,] Mx=new double[,] {{1,0,0}, {0,Math.Cos(rx),Math.Sin(rx)}, {0,-Math.Sin(rx),Math.Cos(rx)}}; return Mx; } private double[,] GetMy() { double [,] My=new double[,] {{Math.Cos(ry),0,-Math.Sin(ry)}, {0,1,0}, {Math.Sin(ry),0,Math.Cos(ry)}}; return My; } private double[,] GetMz() { double [,] Mz=new double[,] {{Math.Cos(rz),Math.Sin(rz),0}, {-Math.Sin(rz),Math.Cos(rz),0}, {0,0,1}}; return Mz; } private double[,] GetM() //M=Mx*My*Mz? or M=Mz*My*Mx? { double [,] M=new double[3,3]; MatrixTool.Multi(GetMz(),GetMy(),ref M); MatrixTool.Multi(M,GetMx(),ref M); return M; } private double[,] GetMdx() { double[,] mt = {{ 0, 0, 0 }, { 0, -Math.Sin(rx), Math.Cos(rx) }, { 0, -Math.Cos(rx), -Math.Sin(rx) }}; double[,] m=new double[3,3]; MatrixTool.Multi(GetMz(),GetMy(),ref m); MatrixTool.Multi(m,mt,ref m); return m; } private double[,] GetMdy() { double[,] mt = {{ -Math.Sin(ry), 0, -Math.Cos(ry) }, { 0, 0, 0 }, { Math.Cos(ry), 0, -Math.Sin(ry) }}; double[,] m=new double[3,3]; MatrixTool.Multi(GetMz(),mt,ref m); MatrixTool.Multi(m,GetMx(),ref m); return m; } private double[,] GetMdz() { double[,] mt = {{ -Math.Sin(rz), Math.Cos(rz), 0 }, { -Math.Cos(rz), -Math.Sin(rz), 0 }, { 0, 0, 0 }}; double[,] m=new double[3,3]; MatrixTool.Multi(mt,GetMy(),ref m); MatrixTool.Multi(m,GetMx(),ref m); return m; } private double[,] specialMulti(double[,] m,double[,] X) { int rowNumM=m.GetLength(0); int colNumM=m.GetLength(1); int rowNumX=X.GetLength(0); int colNumX=X.GetLength(1); int lines=rowNumX/colNumM; double[,] mt=MatrixTool.Init(rowNumM,colNumX); double[,] subX=MatrixTool.Init(colNumM,colNumX); double[,] res=MatrixTool.Init(rowNumM*lines,colNumX); for(int i=0;ivMax) vMax=Math.Abs(V[i,0]); } return vMax; } private bool isSmall() { double s=0; for(int i=0;i<7;i++) s+=Math.Abs(values[i,0]); if (s<0.0000001) return true; else return false; } public void TransCoord(double x1,double y1,double z1,out double x2,out double y2,out double z2) { double[,] Xi={{x1},{y1},{z1}}; double[,] DX={{dx},{dy},{dz}}; double[,] tY=new double[3,1]; double[,] K={{1+k}}; double [,] M=GetM(); MatrixTool.Multi(Xi,K,ref tY); MatrixTool.Multi(M,tY,ref tY); MatrixTool.Add(tY,DX,ref tY); x2=tY[0,0]; y2=tY[1,0]; z2=tY[2,0]; } public double dx { get { return values[0,0]; } set { values[0,0]=value; } } public double dy { get { return values[1,0]; } set { values[1,0]=value; } } public double dz { get { return values[2,0]; } set { values[2,0]=value; } } public double rx { get { return values[3,0]; } set { values[3,0]=value; } } public double ry { get { return values[4,0]; } set { values[4,0]=value; } } public double rz { get { return values[5,0]; } set { values[5,0]=value; } } public double k { get { return values[6,0]; } set { values[6,0]=value; } } }


网友评论

  • 和我想要的不一样