0% found this document useful (0 votes)
1 views1 page

GRASP Python (16)

The document describes a class for managing a structural analysis system, including methods for adding nodes, elements, forces, and supports to a structure. It includes functionality to redraw the structure visually, displaying nodes, forces, and supports. The methods utilize parameters such as Young's modulus and cross-sectional area for elements, and support types for nodes.

Uploaded by

Le Fondateur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views1 page

GRASP Python (16)

The document describes a class for managing a structural analysis system, including methods for adding nodes, elements, forces, and supports to a structure. It includes functionality to redraw the structure visually, displaying nodes, forces, and supports. The methods utilize parameters such as Young's modulus and cross-sectional area for elements, and support types for nodes.

Uploaded by

Le Fondateur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

self.btn_analyze.on_clicked(self.

analyze_structure)

def add_node(self, node_id, x, y):


"""Add a node to the structure"""
self.nodes[node_id] = {'x': x, 'y': y}
self.redraw_structure()

def add_element(self, element_id, node1, node2, E=200e9, A=0.01):


"""Add an element between two nodes"""
self.elements[element_id] = {
'nodes': (node1, node2),
'E': E, # Young's modulus (Pa)
'A': A # Cross-sectional area (m^2)
}
self.redraw_structure()

def add_force(self, node_id, fx, fy):


"""Add a force to a node"""
self.forces[node_id] = {'fx': fx, 'fy': fy}
self.redraw_structure()

def add_support(self, node_id, support_type):


"""Add a support to a node (fixed, pinned, roller)"""
self.supports[node_id] = support_type
self.redraw_structure()

def redraw_structure(self):
"""Redraw the structure with all components"""
self.ax.clear()

# Draw nodes
for node_id, node in self.nodes.items():
self.ax.plot(node['x'], node['y'], 'bo')
self.ax.text(node['x'], node['y'], f'N{node_id}', color='blue')

# Draw forces
if node_id in self.forces:
fx = self.forces[node_id]['fx']
fy = self.forces[node_id]['fy']
self.ax.arrow(node['x'], node['y'], fx/1000, fy/1000,
head_width=0.2, head_length=0.3, fc='red',
ec='red')

# Draw supports
if node_id in self.supports:
support_type = self.supports[node_id]
if support_type == 'fixed':
self.draw_fixed_support(node['x'], node['y'])
elif support_type == 'pinned':
self.draw_pinned_support(node['x'], node['y'])
elif support_type == 'roller':
self.draw_roller_support(node['x'], node['y'])

# Draw elements
for elem_id, elem in self.elements.items():
node1 = self.nodes[elem['nodes'][0]]
node2 = self.nodes[elem['nodes'][1]]

P a g e 2 | 62

You might also like