★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ 小木虫(金币+0.5 ):给个红包,谢谢回帖交流 zyj8119(金币+10, 程序强帖+1):希望maomao1210继续努力。。。 2010-12-18 16:52:40
引用回帖: Originally posted by tpp001 at 2010-12-18 15:51:00:
真的不好意思,我的看懂了您上面的代码,可是我还是不会用来写我这个复杂点的情况,可能我有点笨了,不知道能不能麻烦您看看我这个情况,谢谢。。。。
总共有29条直线向量,每条直线向量上都知道2个点的坐 ...
按照你的要求,写的如下程序,可以符合你的要求:
下面是我用四条线的简单测试结果:
那个黑色的方阵 是计算结果,两两LINE之间的,构成了一个对称矩阵。
C
C ====================================================
C www.muchong.com
C ====================================================
C
Implicit None
Integer Idicp,Jdicp,Kdicp,Ldicp
Integer Num_Max,Num_Line
Real*8 X1,Y1,Z1,X2,Y2,Z2
Parameter(Num_Max=1000)
Real*8 A(3,Num_Max)
Real*8 Theta(Num_MAx,Num_MAx),Output
Open(10,File='input',Status='Old')
Open(20,File='Output',Status='Unknown')
C
C Read necessary data
C
Read (10,*) Num_Line
Do Idicp =1, Num_Line
Read(10,*) X1,Y1,Z1
Read(10,*) X2,Y2,Z2
A(1,Idicp)= X2-X1
A(2,Idicp)= Y2-Y1
A(3,Idicp)= Z2-Z1
EndDo
C
C Find the theta between every possible combin two lines
C
Do Idicp=1, Num_Line
Do Jdicp=1,Idicp
Theta(Idicp,Jdicp)= 0.0D0
Call Sub(A(1,Idicp),A(1,Jdicp),Output)
Theta(Idicp,Jdicp)= Output
Theta(Jdicp,Idicp)= Theta(Idicp,Jdicp)
EndDo
Enddo
C
C Output the matrice
C
Do Idicp=1, Num_Line
Write(*,'(30f12.3)') (Theta(Idicp,Jdicp),Jdicp=1,Num_Line)
Write(20,'(30f12.3)') (Theta(Idicp,Jdicp),Jdicp=1,Num_Line)
Enddo
End
Subroutine Sub(A,B,Output)
Implicit None
Real*8 A(3),B(3)
Real*8 Dicp,AA,BB,AB,Output
AB=A(1)*B(1)+A(2)*B(2)+A(3)*B(3)
AA=A(1)*A(1)+A(2)*A(2)+A(3)*A(3)
BB=B(1)*B(1)+B(2)*B(2)+B(3)*B(3)
Dicp = AB / ( Dsqrt(AA) * Dsqrt(BB) )
Output= Acos(Dicp)*180.0d0/3.1415926D0
Return
End
Enjoy It !!!!
[ Last edited by maomao1210 on 2010-12-18 at 16:37 ]