【越飛越高講堂15】用LISP論矩陣
Matrix-Lib.LSP(50.58 KB, 下載次數: 81, 售價: 1 個明經幣)
;;;-----------------------------------------------------------;;
;;;兩向量相加addition;;
;;;Input:v1,v2-vectorsinR^n;;
;;;OutPut:Avector;;
;;;-----------------------------------------------------------;;
(defunMAT:v+v(v1v2)
(mapcar"+v1v2)
)
;;;-----------------------------------------------------------;;
;;;兩向量相減subtraction;;
;;;Input:v1,v2-vectorsinR^n;;
;;;OutPut:Avector;;
;;;-----------------------------------------------------------;;
(defunMAT:v-v(v1v2)
(mapcar"-v1v2)
)
;;;-----------------------------------------------------------;;
;;;兩向量相乘multiplication;;
;;;Input:v1,v2-vectorsinR^n;;
;;;OutPut:Avector;;
;;;-----------------------------------------------------------;;
(defunMAT:v*v(v1v2)
(mapcar"*v1v2)
)
;;;-----------------------------------------------------------;;
;;;兩向量相除division;;
;;;Input:v1,v2-vectorsinR^n;;
;;;OutPut:Avector;;
;;;-----------------------------------------------------------;;
(defunMAT:v/v(v1v2)
(mapcar"/v1v2)
)
;;;-----------------------------------------------------------;;
;;;向量乘標量(係數);;
;;;VectorxScalar-LeeMac;;
;;;Args:v-vectorinR^n,s-realscalar;;
;;;-----------------------------------------------------------;;
(defunMAT:vxs(vs)
(mapcar(function(lambda(n)(*ns)))v)
)
;;;-----------------------------------------------------------;;
;;;兩向量的點積;;
;;;VectorDotProduct;;
;;;Input:v1,v2-vectorsinR^n;;
;;;-----------------------------------------------------------;;
(defunMAT:Dot(v1v2)
(apply"+(mapcar"*v1v2))
)
;;;-----------------------------------------------------------;;
;;;兩向量的叉積;;
;;;VectorCrossProduct;;
;;;Args:u,v-vectorsinR^3;;
;;;-----------------------------------------------------------;;
(defunMAT:vxv(uv)
(list
(-(*(cadru)(caddrv))(*(cadrv)(caddru)))
(-(*(carv)(caddru))(*(caru)(caddrv)))
(-(*(caru)(cadrv))(*(carv)(cadru)))
)
)
;;;-----------------------------------------------------------;;
;;;線性組合標量組乘向量組;;
;;;Linearcombination-highflybird;;
;;;Input:Vectors-vectors,Scalars,-arealnumberlist;;
;;;Output:avector;;
;;;-----------------------------------------------------------;;
(defunMAT:SxVs(VectorsScalars)
(apply"mapcar(cons"+(mapcar"MAT:vxsVectorsScalars)))
)
;;;-----------------------------------------------------------;;
;;;向量的模(長度);;
;;;VectorNorm-LeeMac;;
;;;Args:v-vectorinR^n;;
;;;-----------------------------------------------------------;;
(defunMAT:norm(v)
(sqrt(apply"+(mapcar"*vv)))
)
;;;-----------------------------------------------------------;;
;;;向量的模(長度);;
;;;VectorNorm-highflybird;;
;;;Args:v-vectorinR^3;;
;;;-----------------------------------------------------------;;
(defunMAT:Norm3D(v)
(distance"(000)v)
)
;;;-----------------------------------------------------------;;
;;;單位向量;;
;;;UnitVector-LeeMac;;
;;;Args:v-vectorinR^n;;
;;;-----------------------------------------------------------;;
(defunMAT:Unitization(v)
((lambda(n)
(if(equal0.0n1e-14)
nil
(MAT:vxsv(/1.0n))
)
)
(MAT:normv)
)
)
;;;-----------------------------------------------------------;;
;;;單位向量;;
;;;UnitVector-highflybird;;
;;;Args:v-vectorinR^3;;
;;;-----------------------------------------------------------;;
(defunMAT:unit(v/l)
(cond
((=(setql(MAT:Norm3Dv))1.0)v)
((>l1e-14)(MAT:vxsv(/1.0l)))
)
)
;;;-----------------------------------------------------------;;
;;;兩個2d向量的叉積的數值;;
;;;輸入:兩個點(或者兩個向量);;
;;;輸出:一個數值.如果為正則是逆時針,兩向量形成的平面法線向量;;
;;;向上,為負則是順時針,為零則兩向量共線或平行。;;
;;;這個數值也為原點,P1,P2三點面積的兩倍。;;
;;;-----------------------------------------------------------;;
(defunMAT:Det2V(v1v2)
(-(*(carv1)(cadrv2))(*(carv2)(cadrv1)))
)
二、向量的旋轉普通瀏覽複製代碼
;;;-----------------------------------------------------------;;
;;;旋轉一個向量或者點90度;;
;;;輸入:一個向量;;
;;;輸出:被旋轉90度後的向量;;
;;;-----------------------------------------------------------;;
(defunMAT:Rot90(vec)
(vl-list*(-(cadrvec))(carvec)(cddrvec))
)
;;;-----------------------------------------------------------;;
;;;旋轉向量到指定角度;;
;;;輸入:一個向量和指定的角度;;
;;;輸出:被旋轉後的向量;;
;;;-----------------------------------------------------------;;
(defunMAT:Rot2D(va/csxy)
(setqc(cosa)s(sina))
(setqx(carv)y(cadrv))
(list(-(*xc)(*ys))(+(*xs)(*yc)))
)
三、 行列式這裡只討論二階和三階的行列式普通瀏覽複製代碼
;;;-----------------------------------------------------------;;
;;;2d行列式determinantinR^2;;
;;;Args:4numbers;;
;;;-----------------------------------------------------------;;
(defunMAT:Det2(x1y1x2y2)
(-(*x1y2)(*x2y1))
)
;;;-----------------------------------------------------------;;
;;;3d行列式determinantinR^3;;
;;;Args:9numbers;;
;;;-----------------------------------------------------------;;
(defunMAT:Det3(a1b1c1a2b2c2a3b3c3)
(+(*a1(-(*b2c3)(*b3c2)))
(*a2(-(*b3c1)(*b1c3)))
(*a3(-(*b1c2)(*b2c1)))
)
)
四、 矩陣的基本運算普通瀏覽複製代碼
;;;-----------------------------------------------------------;;
;;;矩陣轉置;;
;;;MAT:trpTransposeamatrix-DougWilson-;;
;;;輸入:矩陣;;
;;;輸出:轉置後的矩陣;;
;;;-----------------------------------------------------------;;
(defunMAT:trp(m)
(apply"mapcar(cons"listm))
)
;;;-----------------------------------------------------------;;
;;;矩陣相加;;
;;;Matrix+Matrix-LeeMac;;
;;;Args:m,n-nxnmatrices;;
;;;-----------------------------------------------------------;;
(defunMAT:m+m(mn)
(mapcar"(lambda(rs)(mapcar"+rs))mn)
)
;;;-----------------------------------------------------------;;
;;;矩陣相減;;
;;;Matrix-Matrix-LeeMac;;
;;;Args:m,n-nxnmatrices;;
;;;-----------------------------------------------------------;;
(defunMAT:m-m(mn)
(mapcar"(lambda(rs)(mapcar"-rs))mn)
)
;;;-----------------------------------------------------------;;
;;;矩陣相乘;;
;;;MAT:mxmMultiplytwomatrices-VladimirNesterovsky-;;
;;;-----------------------------------------------------------;;
(defunMAT:mxm(mq)
(mapcar(function(lambda(r)(MAT:mxv(MAT:trpq)r)))m)
)
;;;-----------------------------------------------------------;;
;;;矩陣乘標量;;
;;;MatrixxScalar-LeeMac;;
;;;Args:m-nxnmatrix,n-realscalar;;
;;;-----------------------------------------------------------;;
(defunMAT:mxs(ms)
(mapcar(function(lambda(v)(MAT:VxSvs)))m)
)
五、 矩陣與向量的運算普通瀏覽複製代碼
;;;-----------------------------------------------------------;;
;;;向量或點的矩陣變換(向量乘矩陣);;
;;;MatrixxVector-VladimirNesterovsky;;
;;;Args:m-nxnmatrix,v-vectorinR^n;;
;;;-----------------------------------------------------------;;
(defunMAT:mxv(mv)
(mapcar(function(lambda(r)(apply"+(mapcar"*rv))))m)
)
;;;-----------------------------------------------------------;;
;;;點的矩陣(4x4matrix)變換;;
;;;輸入:矩陣m和一個三維點p;;
;;;輸出:點變換後的位置;;
;;;-----------------------------------------------------------;;
(defunMAT:mxp(mp)
(reverse(cdr(reverse(MAT:mxvm(appendp"(1.0))))))
)
六、矩陣的平面和空間變換以下是一些矩陣變換的函數。平移變換普通瀏覽複製代碼
;;;-----------------------------------------------------------;;
;;;平移變換矩陣方式1;;
;;;參數:;;
;;;v-位移矢量;;
;;;-----------------------------------------------------------;;
;;;---------------=={TranslatebyMatrix}==-----------------;;
;;;;;
;;;TranslationMatrix;;
;;;-----------------------------------------------------------;;
;;;Author:highflybird,Copyright?2012;;
;;;-----------------------------------------------------------;;
;;;Arguments:;;
;;;v-Displacementvectorbywhichtotranslate;;
;;;-----------------------------------------------------------;;
(defunMAT:Translation(v)
(list
(list1.0.0.(carv))
(list0.1.0.(cadrv))
(list0.0.1.(caddrv))
(list0.0.0.1.)
)
)
等比縮放變換普通瀏覽複製代碼
;;;-----------------------------------------------------------;;
;;;比例縮放矩陣;;
;;;參數:;;
;;;Cen-基點;;
;;;scale-縮放比例;;
;;;-----------------------------------------------------------;;
;;;-----------------=={ScalebyMatrix}==-------------------;;
;;;;;
;;;ScalingMatrix;;
;;;-----------------------------------------------------------;;
;;;Author:highflybird,Copyright?2012;;
;;;-----------------------------------------------------------;;
;;;Arguments:;;
;;;Cen-BasePointforScalingTransformation;;
;;;scale-ScaleFactorbywhichtoscaleobject;;
;;;-----------------------------------------------------------;;
(defunMAT:Scaling(Censcale/s)
(setqs(-1scale))
(list
(listscale0.0.(*s(carCen)))
(list0.scale0.(*s(cadrCen)))
(list0.0.scale(*s(caddrCen)))
"(0.0.0.1.)
)
)
二維旋轉變換普通瀏覽複製代碼
;;;-----------------------------------------------------------;;
;;;二維旋轉變換矩陣;;
;;;參數:;;
;;;Cen-基點;;
;;;ang-旋轉角度;;
;;;-----------------------------------------------------------;;
;;;-----------------=={RotatebyMatrix}==------------------;;
;;;;;
;;;RotationMatrix;;
;;;-----------------------------------------------------------;;
;;;Author:highflybird,Copyright?2012;;
;;;-----------------------------------------------------------;;
;;;Arguments:;;
;;;Cen-BasePointforRotationTransformation;;
;;;ang-Anglethroughwhichtorotateobject;;
;;;-----------------------------------------------------------;;
(defunMAT:Rotation(Cenang/csxy)
(setqc(cosang)s(sinang))
(setqx(carCen)y(cadrCen))
(list
(listc(-s)0.(-x(-(*cx)(*sy))))
(listsc0.(-y(+(*sx)(*cy))))
"(0.0.1.0.)
"(0.0.0.1.)
)
)
三維旋轉變換普通瀏覽複製代碼
;;;-----------------------------------------------------------;;
;;;三維旋轉變換矩陣;;
;;;參數:;;
;;;Cen-基點;;
;;;Axis-旋轉軸;;
;;;ang-旋轉角;;
;;;-----------------------------------------------------------;;
;;;---------------=={3DRotatebyMatrix}==-----------------;;
;;;Author:highflybird.;;
;;;Arguments:;;
;;;Cen---Inputoriginpointofrotation;;
;;;Axis---Inputaxisvectorofrotation;;
;;;Ang---Inputangleofrotation;;
;;;-----------------------------------------------------------;;
(defunMAT:Rotation3D(CenAxisAng/ABCDMNPxyz)
(setqD(distance"(000)Axis))
(if(or(<D1e-8)(zeropang))
"((1.0.0.0.)(0.1.0.0.)(0.0.1.0.)(0.0.0.1.))
(setqN(mapcar"/Axis(listDDD))
x(carN)
y(cadrN)
z(caddrN)
A(cosAng)
B(sinAng)
C(-1A)
M(list(list(+A(*xxC))
(-(*xyC)(*zB))
(+(*yB)(*xzC))
)
(list(+(*zB)(*xyC))
(+A(*yyC))
(-(*yzC)(*xB))
)
(list(-(*xzC)(*yB))
(+(*xB)(*yzC))
(+A(*zzC))
)
)
p(mapcar"-Cen(Mat:mxvMCen))
M(Mat:DispToMatrixMp)
)
)
)
二維鏡像變換普通瀏覽複製代碼
;;;-----------------------------------------------------------;;
;;;二維鏡像變換矩陣;;
;;;參數:;;
;;;p1-鏡像向量第一點;;
;;;p2-鏡像向量第二點;;
;;;-----------------------------------------------------------;;
;;;----------------=={ReflectbyMatrix}==------------------;;
;;;;;
;;;ReflectsaVLA-ObjectorPointListusinga;;
;;;TransformationMatrix;;
;;;-----------------------------------------------------------;;
;;;Author:LeeMac,Copyright?2010-<arel="nofollow"href="/plugin.php?id=laoyang_wailianx&url=http://www.lee-mac.com"target="_blank">www.lee-mac.com</a>;;
;;;-----------------------------------------------------------;;
;;;Arguments:;;
;;;target-VLA-ObjectorPointListtotransform;;
;;;p1,p2-Pointsrepresentingvectorinwhichtoreflect;;
;;;-----------------------------------------------------------;;
(defunMAT:Reflect(p1p2/acsxy)
(setqa(anglep1p2)a(+aa))
(setqc(cosa)s(sina))
(setqx(carp1)y(cadrp1))
(list
(listcs0.(-x(+(*cx)(*sy))))
(lists(-c)0.(-y(-(*sx)(*cy))))
"(0.0.1.0.)
"(0.0.0.1.)
)
)
三維鏡像變換普通瀏覽複製代碼
;;;-----------------------------------------------------------;;
;;;三維鏡像變換矩陣;;
;;;參數:;;
;;;p1,p2,p3-三點定義的鏡像平面;;
;;;-----------------------------------------------------------;;
;;;---------------=={3DReflectbyMatrix}==----------------;;
;;;;;
;;;Reflectionmatrix;;
;;;-----------------------------------------------------------;;
;;;Author:highflybird,Copyright?2012-;;
;;;-----------------------------------------------------------;;
;;;Arguments:;;
;;;p1,p2,p3-Three3Dpointsdefiningthereflectionplane;;
;;;-----------------------------------------------------------;;
(defunMAT:Reflect3D(p1p2p3/muxuyuz)
(mapcar
"set
"(uxuyuz)
(MAT:unit(MAT:vxv(mapcar"-p2p1)(mapcar"-p3p1)))
)
(setqm(list(list(-1.(*2.uxux))(*-2.uyux)(*-2.uxuz))
(list(*-2.uxuy)(-1.(*2.uyuy))(*-2.uyuz))
(list(*-2.uxuz)(*-2.uyuz)(-1.(*2.uzuz)))
)
)
(Mat:DispToMatrixm(mapcar"-p1(MAT:mxvmp1)))
)
附件中包含Lee-mac的一些演算法,與我的大同小異。區別在於,我的矩陣是為大量運算準備,Lee-mac的為單次次數不多時運用。 七、塊參照,屬性的變換矩陣和逆矩陣附件普通瀏覽複製代碼
;;;-----------------------------------------------------------;;
;;;功能:某點在塊內坐標系統和世界或者用戶坐標系統的轉換;;
;;;參數:pt要變換的點。;;
;;;rlst用nentselp或者nentsel得到的表的最後一項;;
;;;from坐標系:0,WCS;1,當前UCS;2,塊參照坐標系RCS;;
;;;to坐標系:0,WCS;1,當前UCS;2,塊參照坐標系RCS;;
;;;-----------------------------------------------------------;;
;;;MAT:TransNested(gile);;
;;;TranslatesapointcoordinatesfromWCSorUCStoRCS;;
;;;-coordinatessystemofa;;
;;;reference(xreforblock)whateveritsnestedlevel-;;
;;;;;
;;;Arguments;;
;;;pt:thepointtotranslate;;
;;;rlst:theparentsentitieslistfromthedeepestnested;;
;;;totheoneinsertedincurrentspace-sameas;;
;;;(last(nentsel))or(last(nentselp));;
;;;fromto:aswithtransfunction:0.WCS,1.UCS,2.RCS;;
;;;-----------------------------------------------------------;;
(defunMAT:TransNested(ptrlstfromto/GEOM)
(and(=1from)(setqpt(transpt10)))
(and(=2to)(setqrlst(reverserlst)))
(and(or(=2from)(=2to))
(whilerlst
(setqgeom(if(=2to)
(MAT:RevRefGeom(carrlst))
(MAT:RefGeom(carrlst))
)
rlst(cdrrlst)
pt(mapcar"+(MAT:mxv(cargeom)pt)(cadrgeom))
)
)
)
(if(=1to)
(transpt01)
pt
)
)
;;;-----------------------------------------------------------;;
;;;功能:圖塊的變換矩陣;;
;;;輸入:塊參照的圖元名;;
;;;輸出:塊參照的變換矩陣;;
;;;-----------------------------------------------------------;;
;;;MAT:RefGeom(gile);;
;;;Returnsalistwhichfirstitemisa3x3transformation;;
;;;matrix(rotation,scalesnormal)andseconditemtheobject;;
;;;insertionpointinitsparent(xref,blocorspace);;
;;;;;
;;;Argument:anename;;
;;;-----------------------------------------------------------;;
(defunMAT:RefGeom(ename/elstangnormmat)
(setqelst(entgetename)
ang(cdr(assoc50elst))
norm(cdr(assoc210elst))
)
(list
(setqmat
(MAT:mxm
(mapcar(function(lambda(v)(transv0normT)))
"((1.00.00.0)(0.01.00.0)(0.00.01.0))
)
(MAT:mxm
(list(list(cosang)(-(sinang))0.0)
(list(sinang)(cosang)0.0)
"(0.00.01.0)
)
(list(list(cdr(assoc41elst))0.00.0)
(list0.0(cdr(assoc42elst))0.0)
(list0.00.0(cdr(assoc43elst)))
)
)
)
)
(mapcar
"-
(trans(cdr(assoc10elst))norm0)
(MAT:mxvmat
(cdr(assoc10(tblsearch"BLOCK"(cdr(assoc2elst)))))
)
)
)
)
;;;-----------------------------------------------------------;;
;;;功能:圖塊的變換矩陣的逆矩陣;;
;;;-----------------------------------------------------------;;
;;;MAT:RevRefGeom(gile);;
;;;MAT:RefGeominversefunction;;
;;;輸入:塊參照的圖元名;;
;;;輸出:塊參照的變換矩陣的逆矩陣;;
;;;-----------------------------------------------------------;;
(defunMAT:RevRefGeom(ename/entDataangnormmat)
(setqentData(entgetename)
ang(-(cdr(assoc50entData)))
- 360docimg_501_norm(cdr(assoc210entData))
- 360docimg_502_)
- 360docimg_503_(list
- 360docimg_504_(setqmat
- 360docimg_505_(MAT:mxm
- 360docimg_506_(list(list(/1(cdr(assoc41entData)))0.00.0)
- 360docimg_507_(list0.0(/1(cdr(assoc42entData)))0.0)
- 360docimg_508_(list0.00.0(/1(cdr(assoc43entData))))
- 360docimg_509_)
- 360docimg_510_(MAT:mxm
- 360docimg_511_(list(list(cosang)(-(sinang))0.0)
- 360docimg_512_(list(sinang)(cosang)0.0)
- 360docimg_513_"(0.00.01.0)
- 360docimg_514_)
- 360docimg_515_(mapcar(function(lambda(v)(transvnorm0T)))
- 360docimg_516_"((1.00.00.0)(0.01.00.0)(0.00.01.0))
- 360docimg_517_)
- 360docimg_518_)
- 360docimg_519_)
- 360docimg_520_)
- 360docimg_521_(mapcar"-
- 360docimg_522_(cdr(assoc10(tblsearch"BLOCK"(cdr(assoc2entData)))))
- 360docimg_523_(MAT:mxvmat(trans(cdr(assoc10entData))norm0))
- 360docimg_524_)
- 360docimg_525_)
- 360docimg_526_)
- 360docimg_527_
- 360docimg_528_;;;-----------------------------------------------------------;;
- 360docimg_529_;;;屬性的變換矩陣AttribTransformationMatrix.-highflybird;;
- 360docimg_530_;;;輸入:Ename屬性的圖元名;;
- 360docimg_531_;;;輸出:屬性的變換矩陣;;
- 360docimg_532_;;;-----------------------------------------------------------;;
- 360docimg_533_(defunMAT:AttGeom(ename/angnormmatelst)
- 360docimg_534_(setqelst(entgetename)
- 360docimg_535_ang(cdr(assoc50elst))
- 360docimg_536_norm(cdr(assoc210elst))
- 360docimg_537_)
- 360docimg_538_(list
- 360docimg_539_(setqmat
- 360docimg_540_(mxm
- 360docimg_541_(mapcar(function(lambda(v)(transv0normT)))
- 360docimg_542_"((1.00.00.0)(0.01.00.0)(0.00.01.0))
- 360docimg_543_)
- 360docimg_544_(list(list(cosang)(-(sinang))0.0)
- 360docimg_545_(list(sinang)(cosang)0.0)
- 360docimg_546_"(0.00.01.0)
- 360docimg_547_)
- 360docimg_548_)
- 360docimg_549_)
- 360docimg_550_(trans(cdr(assoc10elst))norm0)
- 360docimg_551_)
- 360docimg_552_)
八、三點變換矩陣,UCS變換矩陣,圖元變換矩陣和通用變換矩陣普通瀏覽複製代碼
- 360docimg_553_;;;-----------------------------------------------------------;;
- 360docimg_554_;;;Appenddisplacementvectortoamatrix-Highflybird-;;
- 360docimg_555_;;;把位移矢量添加到矩陣中;;
- 360docimg_556_;;;輸入:mat--矩陣(3x3),disp--位移矢量;;
- 360docimg_557_;;;輸出:一個4X4的變換CAD的標準變換矩陣;;
- 360docimg_558_;;;-----------------------------------------------------------;;
- 360docimg_559_(defunMat:DispToMatrix(matdisp)
- 360docimg_560_(append
- 360docimg_561_(mapcar"appendmat(mapcar"listdisp))
- 360docimg_562_"((0.0.0.1.))
- 360docimg_563_)
- 360docimg_564_)
- 360docimg_565_
- 360docimg_566_;;;-----------------------------------------------------------;;
- 360docimg_567_;;;從一個坐標系統到另一個坐標系統的變換矩陣;;
- 360docimg_568_;;;輸入:from-源坐標系;to-目的坐標系;;
- 360docimg_569_;;;輸出:一個4X4的變換CAD的標準變換矩陣;;
- 360docimg_570_;;;-----------------------------------------------------------;;
- 360docimg_571_(defunMAT:Trans(fromto)
- 360docimg_572_(Mat:DispToMatrix
- 360docimg_573_(mapcar
- 360docimg_574_(function(lambda(v)(transvfromtot)))
- 360docimg_575_"((1.0.0.)(0.1.0.)(0.0.1.))
- 360docimg_576_)
- 360docimg_577_(trans"(000)tofrom)
- 360docimg_578_)
- 360docimg_579_)
- 360docimg_580_
- 360docimg_581_;;;-----------------------------------------------------------;;
- 360docimg_582_;;;wcs到ucs矩陣,也可稱UCS的變換矩陣;;
- 360docimg_583_;;;-----------------------------------------------------------;;
- 360docimg_584_(defunMAT:w2u()(MAT:Trans01))
- 360docimg_585_
- 360docimg_586_;;;-----------------------------------------------------------;;
- 360docimg_587_;;;ucs到wcs矩陣,也可稱UCS的逆變換矩陣;;
- 360docimg_588_;;;-----------------------------------------------------------;;
- 360docimg_589_(defunMAT:u2w()(MAT:Trans10))
- 360docimg_590_
- 360docimg_591_;;;-----------------------------------------------------------;;
- 360docimg_592_;;;通用變換矩陣byhighflybird;;
- 360docimg_593_;;;輸入:from-原坐標系,;;
- 360docimg_594_;;;to-目的坐標系,;;
- 360docimg_595_;;;Org-目的坐標系的原點相對原坐標系的位置;;
- 360docimg_596_;;;Ang-相對於原坐標系的旋轉角度;;
- 360docimg_597_;;;輸出:兩個矩陣,一個是從原坐標系變換到目的坐標系的變換矩陣;;
- 360docimg_598_;;;一個是從目的坐標系變換到原坐標系的變換矩陣;;
- 360docimg_599_;;;-----------------------------------------------------------;;
- 360docimg_600_(defunMAT:Trans1(fromtoOrgAng/MatRotInvCen)
- 360docimg_601_(setqMat(mapcar(function(lambda(v)(transvfromtoT)))
- 360docimg_602_"((1.0.0.)(0.1.0.)(0.0.1.))
- 360docimg_603_)
- 360docimg_604_)
- 360docimg_605_(if(not(equalang01e-14))
- 360docimg_606_(setqRot(list(list(cosang)(-(sinang))0.)
- 360docimg_607_(list(sinang)(cosang)0.)
- 360docimg_608_(list0.0.1.)
- 360docimg_609_)
- 360docimg_610_mat(MAT:mxmmatRot)
- 360docimg_611_)
- 360docimg_612_)
- 360docimg_613_(setqCen(transOrgtofrom))
- 360docimg_614_(setqInv(mat:trpmat))
- 360docimg_615_(list
- 360docimg_616_(Mat:DispToMatrixInv(mat:mxvInv(mapcar"-Cen)));from->to(transptfromto)
- 360docimg_617_(Mat:DispToMatrixmatCen);to->from(transpttofrom)
- 360docimg_618_)
- 360docimg_619_)
- 360docimg_620_
- 360docimg_621_;;;-----------------------------------------------------------;;
- 360docimg_622_;;;通過兩個坐標軸和坐標原點定義的變換矩陣-byhighflybird;;
- 360docimg_623_;;;輸入:Org-坐標系原點,;;
- 360docimg_624_;;;Vx-坐標系X方向,;;
- 360docimg_625_;;;Vy-坐標系y方向;;
- 360docimg_626_;;;輸出:兩個矩陣,一個是該坐標系的變換矩陣,一個是其逆矩陣;;
- 360docimg_627_;;;-----------------------------------------------------------;;
- 360docimg_628_(defunMAT:2VMatrix(OrgVxVy/VzRot)
- 360docimg_629_(if(or(equalVx"(000)1e-14)(equalVy"(000)1e-14))
- 360docimg_630_"((1.0.0.0.)(0.1.0.0.)(0.0.1.0.)(0.0.0.1.))
- 360docimg_631_(progn
- 360docimg_632_(setqVx(Mat:UnitVx));XAxis
- 360docimg_633_(setqVy(Mat:UnitVy));YAxis
- 360docimg_634_(setqVz(Mat:unit(MAT:vxvVxVy)));ZAxis
- 360docimg_635_(setqVy(Mat:unit(MAT:vxvVzVx)));YAxis
- 360docimg_636_(setqRot(listVxVyVz));Rotationmatrix
- 360docimg_637_(list;InverseRotationmatrix
- 360docimg_638_(Mat:DispToMatrix(MAT:trpRot)Org);ThetransformationmatrixfromUCStoWCS
- 360docimg_639_(Mat:DispToMatrixRot(MAT:mxvRot(mapcar"-Org)));ThetransformationmatrixfromWCStoUCS
- 360docimg_640_)
- 360docimg_641_)
- 360docimg_642_)
- 360docimg_643_)
- 360docimg_644_
- 360docimg_645_;;;-----------------------------------------------------------;;
- 360docimg_646_;;;Mat:3PMatrix-Highflybird-;;
- 360docimg_647_;;;通過兩個坐標軸和坐標原點定義的變換矩陣-byhighflybird;;
- 360docimg_648_;;;輸入:P1-坐標系原點,;;
- 360docimg_649_;;;P2-坐標系的第2點;;
- 360docimg_650_;;;P3-坐標系的第3點;;
- 360docimg_651_;;;輸出:兩個矩陣,一個是該坐標系的變換矩陣,一個是其逆矩陣;;
- 360docimg_652_;;;-----------------------------------------------------------;;
- 360docimg_653_(defunMat:3PMatrix(p1p2p3/v1v2v3)
- 360docimg_654_(MAT:2VMatrixP1(mapcar"-p2p1)(mapcar"-p3p1))
- 360docimg_655_)
- 360docimg_656_
- 360docimg_657_;;;-----------------------------------------------------------;;
- 360docimg_658_;;;平齊實體的變換矩陣-byhighflybird;;
- 360docimg_659_;;;輸入:Ent-實體名;;
- 360docimg_660_;;;輸出:平齊這個實體的變換矩陣和它的逆矩陣;;
- 360docimg_661_;;;-----------------------------------------------------------;;
- 360docimg_662_(defunMat:EntityMatrix(Ent/zdxfCenobjanm1matInvorg)
- 360docimg_663_(setqdxf(entgetent))
- 360docimg_664_(if(setqCen(cdr(assoc10dxf)));Insertpoint,centerorstartpoint,etc.
- 360docimg_665_(if(null(caddrCen))
- 360docimg_666_(setqCen(appendCen"(0.0)))
- 360docimg_667_)
- 360docimg_668_(setqCen"(000))
- 360docimg_669_)
- 360docimg_670_(setqobj(vlax-ename->vla-objectEnt))
- 360docimg_671_(if(and(vlax-property-available-pobj"elevation);Ifithaselevationvalue.
- 360docimg_672_(wcmatch(vla-get-objectnameobj)"*Polyline");It"sa"AcDb2dPolyline"or"AcDbPolyline"object
- 360docimg_673_)
- 360docimg_674_(setqz(vla-get-elevationobj)
- 360docimg_675_Cen(list(carCen)(cadrCen)(+(caddrCen)z));addelevationvalue
- 360docimg_676_)
- 360docimg_677_)
- 360docimg_678_(if(vlax-property-available-pobj"rotation);ifithasarotaionangle
- 360docimg_679_(setqan(vla-get-rotationobj))
- 360docimg_680_(setqan0)
- 360docimg_681_)
- 360docimg_682_(MAT:Trans10EntCenan);returntwomatrices,thefirstisWCS->OCS,thesecondisOCS->WCS
- 360docimg_683_)
九、軸測變換矩陣普通瀏覽複製代碼
- 360docimg_684_;;;-----------------------------------------------------------;;
- 360docimg_685_;;;通用的軸測變換矩陣highflybird2012.12;;
- 360docimg_686_;;;AxonometricprojectionsRotationmatrices;;
- 360docimg_687_;;;Isometricprojection:a=(/pi4),b=(atan(-(sqrt2)));;
- 360docimg_688_;;;Input:a-Rotationangleabouttheverticalaxis;;
- 360docimg_689_;;;b-Rotationangleaboutthehorizontalaxis;;
- 360docimg_690_;;;Output:transforamtionmatrixofthisprojection;;
- 360docimg_691_;;;-----------------------------------------------------------;;
- 360docimg_692_(defunMAT:ISO(ab/casacbsb)
- 360docimg_693_(setqca(cosa))
- 360docimg_694_(setqsa(sina))
- 360docimg_695_(setqcb(cosb))
- 360docimg_696_(setqsb(sinb))
- 360docimg_697_(list(listca(-sa)00)
- 360docimg_698_(list(*sacb)(*cacb)(-sb)0)
- 360docimg_699_(list(*sasb)(*casb)cb0)
- 360docimg_700_(list0001)
- 360docimg_701_)
- 360docimg_702_)
演示:
推薦閱讀:
※C++矩陣處理庫
※gal2mat:將gal權重文件轉成n-by-n矩陣
※74. Search a 2D Matrix
※語料庫語言學基礎知識:矩陣(Haskell版)
※矩陣(三)
TAG:矩陣 |