BASH, Dihedral angle with four points

后端 未结 3 1350
北海茫月
北海茫月 2021-01-27 02:48

Points:

A -2.08576        1.76533       -0.46417
B -0.95929        0.87554        0.03365
C  0.28069        1.66193        0.42640
D  0.62407        2.22927              


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-27 03:11

    After a long night, I found the solution:

    awk -v var=$((x+2)) 'NR==var' $FILE > LINEaa
    awk -v var=$((y+2)) 'NR==var' $FILE > LINEbb
    awk -v var=$((z+2)) 'NR==var' $FILE > LINEcc
    awk -v var=$((w+2)) 'NR==var' $FILE > LINEd
    x1=`awk '{print $2}' LINEaa` # x1
    y1=`awk '{print $3}' LINEaa` # y1
    z1=`awk '{print $4}' LINEaa` # z1
    x2=`awk '{print $2}' LINEbb` # x2
    y2=`awk '{print $3}' LINEbb` # y2
    z2=`awk '{print $4}' LINEbb` # z2
    x3=`awk '{print $2}' LINEcc` # x3
    y3=`awk '{print $3}' LINEcc` # y3
    z3=`awk '{print $4}' LINEcc` # z3
    x4=`awk '{print $2}' LINEd` # x4
    y4=`awk '{print $3}' LINEd` # y4
    z4=`awk '{print $4}' LINEd` # z4
    v1x=`calc "($x2)-($x1)" | sed 's/^\t//g'` #plane1
    v1y=`calc "($y2)-($y1)" | sed 's/^\t//g'` #plane1
    v1z=`calc "($z2)-($z1)" | sed 's/^\t//g'` #plane1
    v2x=`calc "($x3)-($x2)" | sed 's/^\t//g'` #plane1
    v2y=`calc "($y3)-($y2)" | sed 's/^\t//g'` #plane1
    v2z=`calc "($z3)-($z2)" | sed 's/^\t//g'` #plane1
    v3x=`calc "($x2)-($x3)" | sed 's/^\t//g'` #plane2
    v3y=`calc "($y2)-($y3)" | sed 's/^\t//g'` #plane2
    v3z=`calc "($z2)-($z3)" | sed 's/^\t//g'` #plane2
    v4x=`calc "($x3)-($x4)" | sed 's/^\t//g'` #plane2
    v4y=`calc "($y3)-($y4)" | sed 's/^\t//g'` #plane2
    v4z=`calc "($z3)-($z4)" | sed 's/^\t//g'` #plane2
    plane1_x=`calc "($v1y)*($v2z)-($v1z)*($v2y)" | sed 's/^\t//g'` # normal vector 1
    plane1_y=`calc "($v2x)*($v1z)-($v2z)*($v1x)" | sed 's/^\t//g'` # normal vector 1
    plane1_z=`calc "($v1x)*($v2y)-($v1y)*($v2x)" | sed 's/^\t//g'` # normal vector 1
    plane2_x=`calc "($v3y)*($v4z)-($v3z)*($v4y)" | sed 's/^\t//g'` # normal vector 2
    plane2_y=`calc "($v4x)*($v3z)-($v4z)*($v3x)" | sed 's/^\t//g'` # normal vector 2
    plane2_z=`calc "($v3x)*($v4y)-($v3y)*($v4x)" | sed 's/^\t//g'` # normal vector 2
    v1mag=`calc "sqrt(($plane1_x)**2+($plane1_y)**2+($plane1_z)**2)" | sed 's/^\t//g'`  # magnitude normal vector 1
    v2mag=`calc "sqrt(($plane2_x)**2+($plane2_y)**2+($plane2_z)**2)" | sed 's/^\t//g'`  # magnitude normal vector 2
    vn1x=`calc "($plane1_x)/($v1mag)" | sed 's/^\t//g'`  # normalization normal vector 1
    vn1y=`calc "($plane1_y)/($v1mag)" | sed 's/^\t//g'`  # normalization normal vector 1
    vn1z=`calc "($plane1_z)/($v1mag)" | sed 's/^\t//g'`  # normalization normal vector 1
    vn2x=`calc "($plane2_x)/($v2mag)" | sed 's/^\t//g'`  # normalization normal vector 2
    vn2y=`calc "($plane2_y)/($v2mag)" | sed 's/^\t//g'`  # normalization normal vector 2
    vn2z=`calc "($plane2_z)/($v2mag)" | sed 's/^\t//g'`  # normalization normal vector 2
    calc "acos(($vn1x)*($vn2x)+($vn1y)*($vn2y)+($vn1z)*($vn2z))*180/3.141592653589793" | sed 's/^\t//g' | sed 's/^~//g'
    

提交回复
热议问题