三角形の重心に向かって三角形の座標を調整する python スクリプトがあります。これは問題なく機能しますが、実行可能な出力を生成するには (他のソフトウェア、Abaqus でインポートできるテキスト ファイルを作成する必要があります)、座標リストをテキスト ファイルに書き込みたいと考えています。
しかし、私はこれを適切に機能させることができません。まず、numpy 配列からリストまたはタプルを作成する必要があると思います。ただし、これは正しく機能しません。このリストには、座標ごとの配列がまだあります。
どうすればこれを修正できますか? 私が現在持っているスクリプトを以下に示します。
newcoords = [[0.0, 0.0], [1.0, 0.0], [0.0, 1.0], [0.0, 0.0], [1.0, 1.0], [0.0, 1.0]]
newelems = [[0, 1, 2], [3, 4, 5]]
import numpy as np
#define triangles
triangles = np.array([[newcoords[e] for e in newelem] for newelem in newelems])
#find centroid of each triangle
CM = np.mean(triangles,axis=1)
#find vector from each point in triangle pointing towards centroid
point_to_CM_vectors = CM[:,np.newaxis] - triangles
#calculate similar triangles 1% smaller
new_triangle = triangles + 0.01*point_to_CM_vectors
newcoord = []
newcoord.append(list(zip(*new_triangle)))
print 'newcoord =', newcoord
#generate output
fout = open('_PartInput3.inp','w')
print >> fout, '*Node-new_triangle'
for i,x in enumerate(newcoord):
print >> fout, i+1, ',', x[0], ',', x[1]
fout.close()
出力ファイル '_PartInput3.inp' の座標リストは次のようになります。
*Node-new_triangle
1, 0.00333333, 0.00333333
2, 0.99333333, 0.00333333
3, 0.00333333, 0.99333333
4, 0.00333333, 0.00666667
5, 0.99333333, 0.99666667
6, 0.00333333, 0.99666667
助けてくれてありがとう!