ในสคริปต์หลามของฉัน ฉันต้องการเขียนพิกัดของรูปร่างตัวเลขลงในไฟล์ข้อความ ฉันนำเข้าพิกัดและคำจำกัดความขององค์ประกอบ จากนั้นใช้รูปร่างตัวเลขเพื่อปรับพิกัด
จากนั้นฉันต้องการเขียนไฟล์ข้อความที่ฉันเขียนพิกัดที่ปรับแล้ว
ด้วยสคริปต์ปัจจุบันของฉัน มันสร้างได้เพียง 6 พิกัดเท่านั้น ฉันคิดว่านี่เป็นเพราะคำจำกัดความของฉันที่ s = new_triangle.shape
(ดูสคริปต์ด้านล่าง)
สิ่งนี้ควรกำหนดอย่างไรเพื่อให้พิกัดใหม่ทั้งหมดถูกเขียนลงในไฟล์เอาต์พุต
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], [0.0, 1.0], [1.0, 1.0], [0.0, 2.0], [0.0, 2.0], [1.0, 1.0], [1.0, 2.0], [1.0, 1.0], [2.0, 1.0], [1.0, 2.0], [1.0, 2.0], [2.0, 1.0], [2.0, 2.0], [1.0, 1.0], [2.0, 0.0], [2.0, 1.0], [1.0, 0.0], [2.0, 0.0], [1.0, 1.0]]
newelems = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11], [12, 13, 14], [15, 16, 17], [18, 19, 20], [21, 22, 23]]
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
#Define new coordinates
newcoord = []
newcoord.append(list(zip(*new_triangle)))
s = new_triangle.shape
print 'newcoords =', newcoords
print 'newcoord =', newcoord
print s
#generate output
fout = open('_PartInput4.inp','w')
fout.write('*Node-new_triangle\n')
for i, x in enumerate(new_triangle.reshape(s[1]*s[2], len(newelems))):
fout.write("{}, {}, {}\n".format(i+1, x[0], x[1]))
fout.close()
ขอบคุณล่วงหน้าสำหรับความช่วยเหลือใด ๆ !
s[1]*s[2]
ควรจะเป็นs[0]*s[1]
- person YXD   schedule 17.04.2013