# Calculate reactions
reactions = K_global @ U
# Display results
print("\nAnalysis Results:")
print("Node Displacements:")
for node_id in [Link]:
ux = U[2*(node_id-1)]
uy = U[2*(node_id-1)+1]
print(f"Node {node_id}: ux = {ux:.6f} m, uy = {uy:.6f} m")
print("\nReactions:")
for node_id in [Link]:
rx = reactions[2*(node_id-1)]
ry = reactions[2*(node_id-1)+1]
print(f"Node {node_id}: Rx = {rx:.2f} N, Ry = {ry:.2f} N")
# Visualize deformed shape
scale_factor = 10 # Scale factor for visualization
deformed_nodes = {}
for node_id, node in [Link]():
deformed_nodes[node_id] = {
'x': node['x'] + scale_factor * U[2*(node_id-1)],
'y': node['y'] + scale_factor * U[2*(node_id-1)+1]
}
# Draw deformed shape
for elem_id, elem in [Link]():
node1 = deformed_nodes[elem['nodes'][0]]
node2 = deformed_nodes[elem['nodes'][1]]
[Link]([node1['x'], node2['x']], [node1['y'], node2['y']],
'r--', alpha=0.5)
[Link]()
def add_node_interactive(self, event):
"""Interactive method to add a node"""
print("Click on the plot to add a node")
[Link].mpl_connect('button_press_event',
self.on_click_add_node)
def on_click_add_node(self, event):
"""Handle node addition click"""
if [Link] != [Link]:
return
node_id = len([Link]) + 1
self.add_node(node_id, [Link], [Link])
[Link].mpl_disconnect([Link].button_press_event)
print(f"Added Node {node_id} at ({[Link]:.2f},
{[Link]:.2f})")
def add_element_interactive(self, event):
"""Interactive method to add an element"""
if len([Link]) < 2:
print("Need at least 2 nodes to create an element")
P a g e 5 | 62