ritchie46 / anaStruct

2D structural analysis in Python
GNU General Public License v3.0
365 stars 104 forks source link

Spring/hinge visual in plots #339

Open AsgerKrllAnd opened 3 weeks ago

AsgerKrllAnd commented 3 weeks ago

Hi

I have been looking through the code/documentation to see if i am correct in assuming there is no way to see hinges added in the structure. And i have found nothing.

With hinges i mean something like: ss.add_element(location=[[0, 0],[0, height]], spring={2:0}, g=column_self_weight)

and a plot like this: image

Is this intentional, or a feature that might be added later?

Am considering adding it myself via pull request, but i fear i might be in over my head.

Has anyone solved it "outside" anastruct with just matplotlib maybe?

Edit:

I solved it for my case with adding a spring parameter to a node counter i already had in place.

Node counter:

def _add_node(self, x, y, node_id, node_ids, spring=False):
        node_id += 1
        node_ids.append({'id': node_id, 'node': x, 'y': y, 'spring': spring})
        return node_id, node_ids

Hinge visual:

for node in node_ids:
    if node['spring']:
        x, y = node['node'], node['y']
        plt.scatter(x, y, s=100, color='white', edgecolors='black', linewidths=2, zorder=5)

# Get the current figure object
fig = plt.gcf()

# Convert the figure to SVG and return it
return ImageResult(file_to_svg(fig))

Result is: image