Commit 505a3975 authored by Jayant Khatkar's avatar Jayant Khatkar
Browse files

reading and plotting stress data, although it is not aligned

parent 5299155e
csvs/
csvs/*
!csvs/stressfield-StanfordBunny_lowres.csv
models/*
!models/tensilebarrectangular.stl
!models/bracket-holes.stl
......
This source diff could not be displayed because it is too large. You can view the blob instead.
#!/usr/bin/python3
import trimesh
#import numpy as np
#from shapely.geometry import LineString
import numpy as np
import matplotlib.pyplot as plt
# from shapely.geometry import LineString
mesh = trimesh.load_mesh('models/benchy.stl')
mesh = trimesh.load_mesh('models/StanfordBunny_lowres.stl')
layer = mesh.section(plane_origin=(0, 0, 20), plane_normal=[0, 0, 1])
def get_layer(l):
return mesh.section(plane_origin=(0, 0, l), plane_normal=[0, 0, 1])
l_height = 100
layer = get_layer(l_height)
# This shows the intersections with the plane in 3d
layer.show()
# layer.show()
# this converts it into 2d
s2, s3 = layer.to_planar()
s2.show()
#z_levels = np.arange(*mesh.bounds[:,2], step = 2)
#layers = mesh.section_multiplane(plane_origin = mesh.bounds[0],
def read_csv(filename):
"""
Read csvs created by matlab FEA analysis
return dictionary where keys are (x,y,z) and vals are (sx,sy,sz)
"""
arr = np.genfromtxt(filename, delimiter=',')
arr = arr[1:, :] # remove headers
# Convert to dictionary
dic = {}
for row in arr:
dic[(row[0], row[1], row[2])] = (row[3], row[4], row[5])
return dic
vec_field = read_csv("csvs/stressfield-StanfordBunny_lowres.csv")
def plot_layer_stress(vec_field, layer_height, delta = 2):
"""
Get points form the vector field which are within delta
of the given layer
"""
x = []
y = []
u = []
v = []
layer = get_layer(layer_height)
for k in vec_field.keys():
if abs(k[2] - layer_height)<delta:
x.append(k[0] - layer.centroid[0])
y.append(k[1] - layer.centroid[1])
u.append(vec_field[k][0])
v.append(vec_field[k][1])
# display
s2, s3 = layer.to_planar()
ax = s2.plot_discrete()
#fig, ax = plt.subplots()
ax.set_title("stress near layer " + str(layer_height))
q = ax.quiver(x,y,u,v)
ax.scatter(x, y, color='r', s = 5)
ax.axis('equal')
plt.show()
plot_layer_stress(vec_field, 20)
# z_levels = np.arange(*mesh.bounds[:,2], step = 2)
# layers = mesh.section_multiplane(plane_origin = mesh.bounds[0],
# plane_normal = [0,0,1],
# heights = z_levels)
#np.sum(layers).show()
# np.sum(layers).show()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment