版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
1、因為一個小任務(wù)需要用到求空間直線交點的 MATLAB函數(shù)和求空間中兩個 平面的相交線的函數(shù),但是在網(wǎng)上找了一下沒有,只好自己寫了幾個函數(shù),自 己覺得還能用,在這里給大家分享一下。1.MATLAB求空間中的兩個平面的相交線functionflag,n,p = Plane2Line(n1,p1,n2,p2)% calulate the line shared by two intersecting plane% input:% n1 normal vector of plane one% p1 any point on plane one% n2 normal vector of plane tw
2、o% p2 any point on plane two% output:% flag whether the two planes are intersecting ( 1 or 0)% n the direction vector of the expected line% p any point in the expected line% author:Lai Zhenzhou from Harbin Institute of Technology% email:% date:2014.1.16%if(isvector(n1) & isvector(p1) & isvector(n2)
3、&isvector(p2)error(Plane2Line:1 / 12the parameter is not vector);endif(length(n1)=3)|(length(p1)=3)|(length(n2)=3)|(length(p2)=3) error(Plane2Line:the parameter is not 3d vector);endA = n1(1) n1(2) n1(3) ;n2(1) n2(2) n2(3) ;if(rank(A)2)flag = 0;elseflag = 1;endif(flag=1)% calculate the normal vector
4、n = cross(n1,n2);2 / 12c1 = n1(1) n1(2) n1(3) -dot(n1,p1);c2 = n2(1) n2(2) n2(3) -dot(n2,p2);% calculate the simplest Row echelon matrix temp1 = rref(A);temp2 = 1 2 3;index(1) = find(temp1(1,:),1,first);% the first nonzero elementindex(2) = find(temp1(2,:),1,first);% the first nonzero elementD = A(:
5、 ,index(1) ) A(:,index(2) );Y = dot(n1,p1);dot(n2,p2);3 / 12X = inv(D)*Y; fori=1:3 if(i=index(1) & i=index(2) ) index(3) = i;endend p(index(1) ) = X(1) ; p(index(2) ) = X(2) ; p(index(3) ) = 0; else n=;p=; end4 / 12for test% flag n p = Plane2Line(1 2 3,1 0 1,2 3 4,0 -1 0)% flag n p = Plane2Line(0 0
6、1,0.5 0.5 0.5,1 0 0,0 0 1)2.MATLAB求空間中兩條直線的交點functionflag,p = Line2Point(n1,p1,n2,p2)% determine the relation between two straight lines and% calulate the intersection point if they are intersecting% input:% n1 direction vector of line one% p1 any point in line one% n2 direction vector of line two%
7、p2 any point in line two% output:% flag the relation of the two line% flag = 0 the two line are on different plane% flag=1 thetwo line are on the same plane and they are parallel% flag = 2 the two line are on the same plane and they areintersecting% pthe point shared by the two intersecting line% au
8、thor:Lai Zhenzhou from Harbin Institute of Technology% email:% date:2014.1.17% reference:http:5 / 12%if(isvector(n1) & isvector(p1) & isvector(n2) & isvector(p2)error(Line2Point:the parameter is not vector);endif(length(n1)=3)|(length(p1)=3)|(length(n2)=3)|(length(p2)=3)error(Line2Point:the paramete
9、r is not 3d vector);endA = p2(1) -p1(1) p2(2) -p1(2) p2(3) -p1(3) ;n1(1) n1(2) n1(3) ;n2(1) n26 / 12n2(2)(3) ; if(det(A)=0) flag = 0; else if(rank(A(2:3,: )2) flag = 1; else flag = 2; end end if(flag = 2) B = rref(A(2:3,: );index(1) = find(B(1,: ),1,first); index(2) = find(B(2,: ),1,first);7 / 12for
10、i=1:3if(i=index(1) & i=index(2) )index(3) = i;endendY(1,1) = -p1(index(1) ) + p2(index(1) );Y(2,1) = -p1(index(2) ) + p2(index(2) );D = n1(index(1) -n2(index(1);n1(index(2) ) -n2(index(2);t = inv(D)*Y;p(1) = p1(1) + n1(1)*t8 / 12(1);p(2) = p1(2) + n1(2)*t(1);p(3) = p1(3) + n1(3) *t(1);elsep = ;enden
11、d%for test% flag p = Line2Point(1 0 0,0 0 0,0 1 0,1 1 0)% flag p = Line2Point(1 1 0,0 0 0,0 1 0,1 1 0)% flag p = Line2Point(1 1 -1,0 0 1,0 1 0,1 1 0)% flag p = Line2Point(1 1 - 1,0 0 1,1 1 -1,1 1 0)% flag p = Line2Point(1 1 1,0 0 0,2 0 0,2 1 1)% flagp=Line2Point(0-42050 -21025,-100,00145,00 0)3.MATL
12、AB求空間中直線和某一線段的交點functionflag,p = LineSegment2Point(n1,p1,p21,p22)% determine the relation between a straight line and% a line segment and calulate the intersecting point9 / 12% if they are intersecting% input:% n1 direction vector of the straight line% p1 any point in the straight line% p21 any poin
13、t in the line segment% p22 any another different point in the line segment% output:% flag the relation of the two line% flag=0 thestraight line and line segment are not intersecting% flag = 1 the straight line and line segment are intersecting% p the point shared by the two intersecting line% author
14、:Lai Zhenzhou from Harbin Institute of Technology% email:% date:2014.1.17%if(isvector(n1) & isvector(p1) & isvector(p21) & isvector(p22)error(LineSegment2Point:the parameter is not vector);endif(length(n1)=3)|(length(p1)=3)|(length(p21)=3)|(length(p22)=3)error(LineSegment2Point:the parameter is not
15、3d vector);endif(p21(1)=p2210 / 12(1)&(p21(2)=p22(2)&(p21(3) =p22(3) )error(LineSegment2Point:the two appointed points of line segment are the same);end%calculate the direction vector of line segmentn2 = p22(1)-p21(1),p22(2)-p21(2),p22(3) -p21(3) ;flag0,p0 = Line2Point(n1,p1,n2,p21);if(flag0 = 2)if(norm(p0-p21)=norm(p22-p21) & norm(p0-p22)=norm(p22-p21)flag = 1; p = p0;else11 / 12flag = 0;p=;endelseflag
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024版購銷合作協(xié)議合同
- 2024版機電安裝工程勞務(wù)分包合同
- 二零二五年度健身房裝修工程合同范本2篇
- 2024未交房二手房買賣合同房屋質(zhì)量驗收標(biāo)準(zhǔn)規(guī)范3篇
- 2024年高校青椒試用期教學(xué)科研合同
- 2024版創(chuàng)意設(shè)計及咨詢服務(wù)合同書版B版
- 二零二五年度新能源設(shè)備招標(biāo)采購服務(wù)合同3篇
- 2025年度租賃合同(含房產(chǎn)與設(shè)備)3篇
- 2024年苗木種植基地樹木銷售與回購合同范本3篇
- 音響設(shè)備采購銷售合同
- 2024年醫(yī)療器械經(jīng)營質(zhì)量管理規(guī)范培訓(xùn)課件
- 2024年計算機二級WPS考試題庫380題(含答案)
- 安徽省血液凈化專科護士臨床培訓(xùn)基地條件
- 建筑消防設(shè)施檢測誠信承諾書
- ojt問答題未升版ojt204
- 五年級語文滲透法制教育滲透點教案呈現(xiàn)
- 凱普21種基因型HPV分型與其它比較
- 小學(xué)數(shù)學(xué)小專題講座《數(shù)學(xué)教學(xué)生活化 》(課堂PPT)
- 雞場養(yǎng)殖情況記錄登記表
- 高壓配電柜系列產(chǎn)品出廠檢驗規(guī)范
- 節(jié)流孔板孔徑計算
評論
0/150
提交評論