Skip to content

Commit

Permalink
Shear wall simplification and spring rendering fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JWock82 authored and JWock82 committed Dec 17, 2024
1 parent eb3ba40 commit c92cb9a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
42 changes: 29 additions & 13 deletions PyNite/Rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,8 @@ def plot_member(self, member, theme='default'):

def plot_spring(self, spring, color='grey', deformed=False):
"""
Adds a spring to the plotter. This method generates a zig-zag line representing a spring between two nodes, and adds it to the plotter with specified theme settings."""
Adds a spring to the plotter. This method generates a zig-zag line representing a spring between two nodes, and adds it to the plotter with specified theme settings.
"""

# Scale the spring's zigzags
size = self.annotation_size
Expand All @@ -532,10 +533,10 @@ def plot_spring(self, spring, color='grey', deformed=False):

# Calculate the spring direction vector and length
direction = np.array([Xj, Yj, Zj]) - np.array([Xi, Yi, Zi])
length = ((Xj-Xi)**2 + (Yj-Yi)**2 - (Zj-Zi)**2)**0.5
length = np.linalg.norm(direction)

# Normalize the direction vector
direction = direction/length
direction = direction / length

# Calculate perpendicular vectors for zig-zag plane
arbitrary_vector = np.array([1, 0, 0])
Expand All @@ -545,33 +546,48 @@ def plot_spring(self, spring, color='grey', deformed=False):
perp_vector1 /= np.linalg.norm(perp_vector1)
perp_vector2 = np.cross(direction, perp_vector1)
perp_vector2 /= np.linalg.norm(perp_vector2)


# Define the length of the straight segments
straight_segment_length = length / 10
zigzag_length = length - 2 * straight_segment_length

# Generate points for the zig-zag line
num_zigs = 4
num_points = num_zigs * 2
amplitude = size
t = np.linspace(0, length, num_points)
t = np.linspace(0, zigzag_length, num_points)
zigzag_pattern = amplitude * np.tile([1, -1], num_zigs)
zigzag_points = np.outer(t, direction) + np.outer(zigzag_pattern, perp_vector1)

# Adjust the zigzag points to start position
zigzag_points += np.array([Xi, Yi, Zi])


# Add the straight segments to the start and end
start_point = np.array([Xi, Yi, Zi])
end_point = np.array([Xj, Yj, Zj])
start_segment = start_point + direction * straight_segment_length
end_segment = end_point - direction * straight_segment_length

# Adjust the zigzag points to the correct position
zigzag_points += start_segment

# Combine the points
points = np.vstack([start_point, start_segment, zigzag_points, end_segment, end_point])

# Add lines connecting the points
num_points = len(points)
lines = np.zeros((num_points - 1, 3), dtype=int)
lines[:, 0] = np.full((num_points - 1), 2, dtype=int)
lines[:, 0] = 2
lines[:, 1] = np.arange(num_points - 1, dtype=int)
lines[:, 2] = np.arange(1, num_points, dtype=int)

# Create a PolyData object for the zig-zag line
zigzag_line = pv.PolyData(zigzag_points, lines=lines)
zigzag_line = pv.PolyData(points, lines=lines)

# Create a plotter and add the zig-zag line
self.plotter.add_mesh(zigzag_line, color=color, line_width=2)

# Add the spring label to the list of labels
self._spring_labels.append(spring.name)
self._spring_label_points.append([(Xi+Xj)/2, (Yi+Yj)/2, (Zi+Zj)/2])
self._spring_label_points.append([(Xi + Xj) / 2, (Yi + Yj) / 2, (Zi + Zj) / 2])


def plot_plates(self, deformed_shape, deformed_scale, color_map, combo_name):

Expand Down
16 changes: 1 addition & 15 deletions PyNite/ShearWall.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from math import isclose
from numpy import average
import io

from PyNite.FEModel3D import FEModel3D
from prettytable import PrettyTable
Expand Down Expand Up @@ -564,21 +565,6 @@ def print_piers(self, combo_name='Combo 1'):
print('+-------------------+')
print(table)

def report(self):

from reporting import render_report, convert_image_to_html

image_stream = io.BytesIO()
self.draw_piers(show=False).savefig(image_stream, format='png')
image_data = image_stream.getvalue()

pier_sketch_html = convert_image_to_html(image_data)

kwargs = {}
kwargs['pier_sketch'] = pier_sketch_html

return render_report('report_SRMSW.html', kwargs)

#%%
class Pier():

Expand Down

0 comments on commit c92cb9a

Please sign in to comment.