资源描述:
《求空间直线的交点》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、因为一个小任务需要用到求空间直线交点的MATLAB函数和求空间中两个平面的相交线的函数,但是在网上找了一下没有,只好自己写了几个函数,自己觉得还能用,在这里给大家分享一下。1.MATLAB求空间中的两个平面的相交线function[flag,n,p]=PlanePlane2Line(n1,p1,n2,p2)%---------------------------------------------------------%calulatethelinesharedbytwointersectingplane%input:%n1n
2、ormalvectorofplaneone%p1anypointonplaneone%n2normalvectorofplanetwo%p2anypointonplanetwo%%output:%flagwhetherthetwoplanesareintersecting(1or0)%nthedirectionvectoroftheexpectedline%panypointintheexpectedline%%author:LaiZhenzhoufromHarbinInstituteofTechnology%email:lai
3、zhenzhou@126.com%date:2014.1.16%----------------------------------------------------------if(~(isvector(n1)&&isvector(p1)&&isvector(n2)&&isvector(p2)))error('PlanePlane2Line:theparameterisnotvector');endif((length(n1)~=3)
4、
5、(length(p1)~=3)
6、
7、(length(n2)~=3)
8、
9、(length(p2
10、)~=3))error('PlanePlane2Line:theparameterisnot3dvector');endA=[n1(1)n1(2)n1(3);n2(1)n2(2)n2(3)];if(rank(A)<2)flag=0;elseflag=1;endif(flag==1)%calculatethenormalvectorn=cross(n1,n2);c1=[n1(1)n1(2)n1(3)-dot(n1,p1)];c2=[n2(1)n2(2)n2(3)-dot(n2,p2)];%calculatethesimplestR
11、owechelonmatrixtemp1=rref(A);temp2=[123];index(1)=find(temp1(1,:),1,'first');%thefirstnonzeroelementindex(2)=find(temp1(2,:),1,'first');%thefirstnonzeroelementD=[A(:,index(1))A(:,index(2))];Y=[dot(n1,p1);dot(n2,p2)];X=inv(D)*Y;fori=1:3if(i~=index(1)&&i~=index(2))inde
12、x(3)=i;endendp(index(1))=X(1);p(index(2))=X(2);p(index(3))=0;elsen=[];p=[];end%-----------fortest------------------%[flagnp]=PlanePlane2Line([123],[101],[234],[0-10])%[flagnp]=PlanePlane2Line([001],[0.50.50.5],[100],[001])1.MATLAB求空间中两条直线的交点function[flag,p]=LineLine2
13、Point(n1,p1,n2,p2)%---------------------------------------------------------%determinetherelationbetweentwostraightlinesand%calulatetheintersectionpointiftheyareintersecting%%input:%n1directionvectoroflineone%p1anypointinlineone%n2directionvectoroflinetwo%p2anypointi
14、nlinetwo%%output:%flagtherelationofthetwoline%flag=0thetwolineareondifferentplane%flag=1thetwolineareonthesameplaneandtheyareparall