top of page

Creating a 2d load envelope with python

  • Admin
  • Apr 25
  • 2 min read

Acting loads on a part or an aircraft component could be huge numbers. Therefore in initaial sizing process the load cases with low magnitudes would not size any parts. In order to detect these low load cases 2d load envelopes help to reduce load cases.


In pyhton ConvexHull method helps you in a way below to detect critical loads in envelope.


import pandas as pd
import matplotlib.pyplot as plt
from scipy.spatial import ConvexHull
from tkinter import Tk, filedialog
# === Use file dialog to select CSV file ===
Tk().withdraw()  # Hide the root Tkinter window
file_path = filedialog.askopenfilename(title="Select your CSV file", filetypes=[("CSV files", "*.csv")])
# === Load CSV ===
df = pd.read_csv(file_path)
# === Helper function to plot and get convex hull points ===
def plot_and_get_boundary(x_col, y_col):
    points = df[[x_col, y_col]].values
    # Convex Hull
    hull = ConvexHull(points)
    boundary_indices = hull.vertices
    boundary_points = df.iloc[boundary_indices][['Case ID', x_col, y_col]]
    # Plot
    plt.figure()
    plt.scatter(df[x_col], df[y_col], label='All Points', color='blue')
    plt.plot(points[hull.vertices, 0], points[hull.vertices, 1], 'r--', lw=2, label='Convex Hull')
    plt.fill(points[hull.vertices, 0], points[hull.vertices, 1], 'r', alpha=0.1)
    plt.scatter(boundary_points[x_col], boundary_points[y_col], color='red', label='Boundary Points')
    plt.xlabel(x_col)
    plt.ylabel(y_col)
    plt.title(f'{x_col} vs {y_col} with Convex Hull')
    plt.legend()
    plt.grid(True)
    plt.show()
    return boundary_points
# === Plot 1: Nx vs Ny ===
boundary_nx_ny = plot_and_get_boundary('Nx', 'Ny')
print("\nBoundary Points (Nx vs Ny):")
print(boundary_nx_ny)
# === Plot 2: Nx vs Nz ===
boundary_nx_nz = plot_and_get_boundary('Nx', 'Nz')
print("\nBoundary Points (Nx vs Nz):")
print(boundary_nx_nz)
# === Plot 3: Ny vs Nz ===
boundary_ny_nz = plot_and_get_boundary('Ny', 'Nz')
print("\nBoundary Points (Ny vs Nz):")
print(boundary_ny_nz)


Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating

© 2023

 
bottom of page