-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtolerance_analysis.py
More file actions
103 lines (82 loc) · 3.25 KB
/
Copy pathtolerance_analysis.py
File metadata and controls
103 lines (82 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# # tolerance_analysis.py
# import numpy as np
# import matplotlib.pyplot as plt
# from config import *
# def simulate_tolerances():
# np.random.seed(42)
# tailgate_tol = np.random.normal(0, TAILGATE_TOL, NUM_SAMPLES)
# window_tol = np.random.normal(0, WINDOW_TOL, NUM_SAMPLES)
# final_tailgate_w = TAILGATE_WIDTH + tailgate_tol
# final_window_w = WINDOW_WIDTH + window_tol
# final_tailgate_h = TAILGATE_HEIGHT + tailgate_tol
# final_window_h = WINDOW_HEIGHT + window_tol
# gap_w = final_tailgate_w - final_window_w
# gap_h = final_tailgate_h - final_window_h
# return gap_w, gap_h
# def plot_gap_histograms(gap_w, gap_h):
# plt.figure(figsize=(10, 5))
# plt.subplot(1, 2, 1)
# plt.hist(gap_w, bins=30, alpha=0.7, color='blue', edgecolor='black')
# plt.axvline(x=2*NOMINAL_GAP, color='red', linestyle='dashed', label="Nominal Gap (20 mm)")
# plt.xlabel("Gap in Width (mm)")
# plt.ylabel("Frequency")
# plt.title("Tolerance Analysis - Width Gap")
# plt.legend()
# plt.subplot(1, 2, 2)
# plt.hist(gap_h, bins=30, alpha=0.7, color='green', edgecolor='black')
# plt.axvline(x=2*NOMINAL_GAP, color='red', linestyle='dashed', label="Nominal Gap (20 mm)")
# plt.xlabel("Gap in Height (mm)")
# plt.ylabel("Frequency")
# plt.title("Tolerance Analysis - Height Gap")
# plt.legend()
# plt.tight_layout()
# plt.show()
# ===========================
# tolerance_analysis.py
# ===========================
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from config import *
def simulate_tolerances():
np.random.seed(42)
tailgate_tol = np.random.normal(0, TAILGATE_TOL, NUM_SAMPLES)
window_tol = np.random.normal(0, WINDOW_TOL, NUM_SAMPLES)
final_tailgate_w = TAILGATE_WIDTH + tailgate_tol
final_window_w = WINDOW_WIDTH + window_tol
final_tailgate_h = TAILGATE_HEIGHT + tailgate_tol
final_window_h = WINDOW_HEIGHT + window_tol
gap_w = final_tailgate_w - final_window_w
gap_h = final_tailgate_h - final_window_h
# Print sample data
print("Tailgate Tolerances (sample):", tailgate_tol[:10])
print("Window Tolerances (sample):", window_tol[:10])
print("Gap Width (sample):", gap_w[:10])
print("Gap Height (sample):", gap_h[:10])
# Save to CSV
df = pd.DataFrame({
'tailgate_tol': tailgate_tol,
'window_tol': window_tol,
'gap_width': gap_w,
'gap_height': gap_h
})
df.to_csv("tolerance_data.csv", index=False)
return gap_w, gap_h
def plot_gap_histograms(gap_w, gap_h):
plt.figure(figsize=(10, 5))
plt.subplot(1, 2, 1)
plt.hist(gap_w, bins=30, alpha=0.7, color='blue', edgecolor='black')
plt.axvline(x=2*NOMINAL_GAP, color='red', linestyle='dashed', label="Nominal Gap (20 mm)")
plt.xlabel("Gap in Width (mm)")
plt.ylabel("Frequency")
plt.title("Tolerance Analysis - Width Gap")
plt.legend()
plt.subplot(1, 2, 2)
plt.hist(gap_h, bins=30, alpha=0.7, color='green', edgecolor='black')
plt.axvline(x=2*NOMINAL_GAP, color='red', linestyle='dashed', label="Nominal Gap (20 mm)")
plt.xlabel("Gap in Height (mm)")
plt.ylabel("Frequency")
plt.title("Tolerance Analysis - Height Gap")
plt.legend()
plt.tight_layout()
plt.show()