I have a stress-strain curve (consisting of line segments), which is defined by the following lists:
true_strain = [0, 0.005, 0.01, 0.015, 0.022, 0.025, 0.03, 0.035, 0.04, 0.06, 0.08, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.75]
true_stress_GPa = [0.00251, 0.007, 0.016, 0.026, 0.043, 0.074, 0.1, 0.133, 0.15, 0.16, 0.165, 0.168, 0.189, 0.221, 0.297, 0.561, 0.841, 1.41, 1.86]
This curve is to be crossed at least once by a line (defined by a function, in code called y_of_yield). My desired output is the first intersect point I encounter in a specific range. To solve this question I was using shapley, wich is working quite well in theory. However I have problems defining the IF statement.
for i in range(8, len(true_strain)-1):
line1 = LineString([(true_strain[i], true_stress_GPa[i]), (true_strain[i+1], true_stress_GPa[i+1])])
line2 = LineString([(true_strain[i], y_of_yield(true_strain[i])), (true_strain[i+1], y_of_yield(true_strain[i+1]))])
int_pt = line1.intersection(line2)
print(int_pt)
if int_pt != 'LINESTRING EMPTY':
point_of_intersection = int_pt.x, int_pt.y
print(point_of_intersection)
break
More specifically, the problem is the following: If an intersection between line segment 1 and 2 is detected, the output will be POINT (x,y). If no intersection is encountered the output will be LINESTRING EMPTY. So I thougt I could ask:
If the output is not LINESTRING EMPTY, than extract the intersection point and stop, otherwise keep iterating until an intersection is found.
However, the program doesn´t seem to recognize LINESTRING EMPTY and always goes on to extract the (non-existent) interesection point, thus raising an error (the error for int_pt.xis: int_pt has no attribute x). Does anyone know how to fix the If statement? Sorry if this is a very easy / obvious question, I am a beginner!
Thanks a lot! :)
Aucun commentaire:
Enregistrer un commentaire