您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > VB坐标转换程序设计
OptionExplicitDimk2#,e2#,dX2#,dY2#Dimx2#,Xx2#,y2#,Yy2#Dimk3#,Ex#,Ey#,Ez#,dX3#,dY3#,dZ3#DimX3#,Y3#,Z3#,Xx3#,Yy3#,Zz3#ConstPI=3.14159265358979PrivateSubCheck1_Click()IfCheck1.Value=1ThenfrmCoorTrans.Height=5175ElseIfCheck1.Value=0ThenfrmCoorTrans.Height=4440EndIfEndSubPrivateSubcmdBrowFile_Click()CDg1.Filter=控制点文件(*.gcp)|*.gcp|所有文件(*.*)|*.*CDg1.Action=1txtFileName.Text=CDg1.FileNameEndSubPrivateSubcmdCalc_Click()DimsAsString,iPos%,i%,iCent!Dimn%,x1#(),y1#(),x2#(),y2#()DimA()AsDouble,L()AsDouble,x(1To4)AsDoubleDimAt#(),Naa#(),W#()OpentxtFileName.TextForInputAs#1LineInput#1,sn=Val(s)ReDimx1#(n),y1#(n),x2#(n),y2#(n)Fori=1TonLineInput#1,siPos=InStr(s,,)x1(i)=Val(Left(s,iPos-1))s=Mid(s,iPos+1)iPos=InStr(s,,)y1(i)=Val(Left(s,iPos-1))s=Mid(s,iPos+1)iPos=InStr(s,,)x2(i)=Val(Left(s,iPos-1))s=Mid(s,iPos+1)y2(i)=Val(s)NextiClose#1'计算转换参数ReDimA(1To2*n,1To4)AsDouble,L(1To2*n)AsDoubleReDimAt(1To4,1To2*n),Naa(1To4,1To4),W(1To4)Debug.Print系数矩阵A:Fori=1TonA(2*i-1,1)=1:A(2*i-1,2)=0:A(2*i-1,3)=x1(i):A(2*i-1,4)=y1(i)Debug.PrintA(2*i-1,1),A(2*i-1,2),A(2*i-1,3),A(2*i-1,4)A(2*i,1)=0:A(2*i,2)=1:A(2*i,3)=y1(i):A(2*i,4)=-x1(i)Debug.PrintA(2*i,1),A(2*i,2),A(2*i,3),A(2*i,4)L(2*i-1)=x2(i):L(2*i)=y2(i)NextiDebug.Print常数向量L:Fori=1To2*nDebug.PrintL(i)NextiMatrixTransA,AtDebug.PrintA的转置矩阵:ShowMatrixAtMatrix_MultyNaa,At,ADebug.PrintNaa:ShowMatrixNaaMatrix_MultyW,At,LDebug.PrintW:Fori=1To4Debug.PrintW(i)NextiMajorInColGuassNaa,W,xDebug.PrintXFori=1To4Debug.Printx(i)Nexti'分离旋转和尺度参数IfAbs(x(3))0.00000001ThenIfx(4)0Thene2=PI/2Elsee2=PI*3/2EndIfElsee2=Atn(x(4)/x(3))'得到的是弧度Ifx(3)0Andx(4)0Thene2=PI-e2ElseIfx(3)0Andx(4)0Thene2=PI+e2ElseIfx(3)0Andx(4)0Thene2=PI*2+e2EndIfEndIfk2=x(3)/Cos(e2)'将转换参数写入相应文本框txtK2=Str(k2-1)e2=e2*180/PIDimdu%,fen%du=Int(e2):e2=(e2-du)*60fen=Int(e2):e2=(e2-fen)*60e2=Val(Format(e2,0.00))e2=du+fen/100#+e2/10000txtE2=Str(e2)txtdX2.Text=Str(x(1))txtdY2.Text=Str(x(2))EndSubPrivateSubcmdCalc2_Click()k2=Val(txtK2.Text)e2=Val(txtE2.Text)e2=DoToHu(e2)dX2=Val(txtdX2.Text)dY2=Val(txtdY2.Text)x2=Val(txtX2.Text)y2=Val(txtY2.Text)Xx2=(k2+1)*(x2*Cos(e2)+y2*Sin(e2))+dX2Yy2=(k2+1)*(y2*Cos(e2)-x2*Sin(e2))+dY2txtXx2.Text=Format(Xx2,0.0000)txtYy2.Text=Format(Yy2,0.0000)EndSubPrivateSubcmdCalc3_Click()k3=Val(txtK3.Text)Ex=Val(txtEx.Text)Ex=DoToHu(Ex)Ey=Val(txtEy.Text)Ey=DoToHu(Ey)Ez=Val(txtEz.Text)Ez=DoToHu(Ez)dX3=Val(txtdX3.Text)dY3=Val(txtdY3.Text)dZ3=Val(txtDz3.Text)X3=Val(txtX3.Text)Y3=Val(txtY3.Text)Z3=Val(txtZ3.Text)Xx3=(k3+1)*(X3*Cos(Ey)*Cos(Ez)+Y3*Cos(Ey)*Sin(Ez)-Z3*Sin(Ey))+dX3Yy3=(k3+1)*(X3*(-Cos(Ex)*Sin(Ez)+Sin(Ex)*Sin(Ey)*Cos(Ez))+Y3*(Cos(Ex)*Cos(Ez)+Sin(Ex)*Sin(Ey)*Sin(Ez))+Z3*(Sin(Ex)*Cos(Ey)))+dY3Zz3=(k3+1)*(X3*(Sin(Ex)*Sin(Ez)+Cos(Ex)*Sin(Ey)*Cos(Ez))+Y3*(-Sin(Ex)*Cos(Ez)+Cos(Ex)*Sin(Ey)*Sin(Ez))+Z3*(Cos(Ex)*Cos(Ey)))+dZ3txtXx3.Text=Format(Xx3,0.0000)txtYy3.Text=Format(Yy3,0.0000)txtZz3.Text=Format(Zz3,0.0000)EndSubPrivateSubcmdClear2_Click()txtX2.Text=txtY2.Text=txtXx2.Text=txtYy2.Text=EndSubPrivateSubcmdClear3_Click()txtX3.Text=txtY3.Text=txtZ3.Text=txtXx3.Text=txtYy3.Text=txtZz3.Text=EndSubPrivateSubcmdconCalc2_Click()k2=Val(txtK2.Text)e2=Val(txtE2.Text)e2=DoToHu(e2)dX2=Val(txtdX2.Text)dY2=Val(txtdY2.Text)Xx2=Val(txtXx2.Text)Yy2=Val(txtYy2.Text)x2=((Xx2-dX2)*Cos(e2)-(Yy2-dY2)*Sin(e2))/(k2+1)y2=((Yy2-dY2)*Cos(e2)+(Xx2-dX2)*Sin(e2))/(k2+1)txtX2.Text=Format(x2,0.0000)txtY2.Text=Format(y2,0.0000)EndSubPrivateSubcmdconCalc3_Click()k3=Val(txtK3.Text)Ex=Val(txtEx.Text)Ex=DoToHu(Ex)Ey=Val(txtEy.Text)Ey=DoToHu(Ey)Ez=Val(txtEz.Text)Ez=DoToHu(Ez)dX3=Val(txtdX3.Text)dY3=Val(txtdY3.Text)dZ3=Val(txtDz3.Text)Xx3=Val(txtXx3.Text)Yy3=Val(txtYy3.Text)Zz3=Val(txtZz3.Text)X3=((Xx3-dX3)*Cos(Ey)*Cos(Ez)+(Yy3-dY3)*(-Cos(Ex)*Sin(Ez)+Sin(Ex)*Sin(Ey)*Cos(Ez))+(Zz3-dZ3)*(Sin(Ex)*Sin(Ez)+Cos(Ex)*Sin(Ey)*Cos(Ez)))/(k3+1)Y3=((Xx3-dX3)*Cos(Ey)*Sin(Ez)+(Yy3-dY3)*(Sin(Ex)*Sin(Ey)*Sin(Ez)+Cos(Ex)*Cos(Ez))+(Zz3-dZ3)*(-Sin(Ex)*Cos(Ez)+Cos(Ex)*Sin(Ey)*Sin(Ez)))/(k3+1)Z3=((Xx3-dX3)*(-Sin(Ey))+(Yy3-dY3)*Sin(Ex)*Cos(Ey)+(Zz3-dZ3)*(Cos(Ex)*Cos(Ey)))/(k3+1)txtX3.Text=Format(X3,0.0000)txtY3.Text=Format(Y3,0.0000)txtZ3.Text=Format(Z3,0.0000)EndSubPrivateSubcmdExit_Click()EndEndSubPrivateSubForm_Load()frmCoorTrans.Height=4440EndSub'弧度化为度.分秒的形式:输入弧度值,输出度.分秒(各占两位)PublicFunctionHuToDo(ByValHuAsDouble)AsSingleDimdu%,fen%,miao%Hu=Hu*180/PIdu=Fix(Hu)Hu=(Hu-du)*60fen=Fix(Hu)Hu=(Hu-fen)*60miao=Fix(Hu+0.5)Ifmiao=60Thenfen=fen+1miao=0EndIfHuToDo=du+fen/100+miao/10000EndFunction'将度.分秒形式化为弧度:输入为度.分秒形式,输出为弧度PublicFunctionDoToHu(ByValDoFenMiaoAsDouble)AsSingleDimdu%,fen%,miao%,angle#du=Fix(DoFenMiao)DoFenMiao=(DoFenMiao-du)*100fen=Fix(DoFenMiao)miao=(DoFenMiao-fen)*100angle=du+fen/60+miao/3600DoToHu=angle*PI/180EndFunction'矩阵转置的通用过程PublicSubMatrixTrans(A,At)Dimi%,j%DimR1%,C1%OnErrorResumeNextC1=UBound(A,2)-LBound(A,2)+1IfErrThenMsgBox输入的矩阵维数不对!ExitSubEndIfR1=UBound(A,1)-LBound(A,1)+1ReDimc(1ToC1,1ToR1)Fori=1ToR1Forj=1ToC1At(j,i)=A(i,j)NextjNextiEndSub'矩阵相乘:输入矩阵或数Qa、Qb,自动识别它们的维数,并输出它们的乘积QnPublicSubMatrix_Multy(Qn,Qa,Qb)Dimia%,ib%,ic%Dimai%,bi%,ci%Dime1AsBoolean,e2AsBoolean,e3AsBoo
本文标题:VB坐标转换程序设计
链接地址:https://www.777doc.com/doc-3369812 .html