Update app.py
Browse files
app.py
CHANGED
@@ -3,85 +3,90 @@ import numpy as np
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
from matplotlib.patches import Polygon, Circle
|
5 |
|
6 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
def main():
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
<style>
|
12 |
body {
|
13 |
-
background-color: #
|
14 |
color: #333333;
|
15 |
-
font-family: '
|
|
|
|
|
|
|
|
|
16 |
}
|
17 |
.stSidebar {
|
18 |
-
background-color: #
|
|
|
19 |
}
|
20 |
-
|
21 |
-
|
22 |
-
font-family: 'Georgia', serif;
|
23 |
}
|
24 |
-
.stButton>button {
|
25 |
-
background-color: #
|
26 |
color: white;
|
|
|
27 |
border-radius: 5px;
|
28 |
-
font-size: 16px;
|
29 |
padding: 10px 20px;
|
30 |
-
}
|
31 |
-
.stButton>button:hover {
|
32 |
-
background-color: #0d2a45;
|
33 |
-
}
|
34 |
-
.stMarkdown {
|
35 |
font-size: 16px;
|
|
|
|
|
|
|
|
|
36 |
}
|
37 |
</style>
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
st.sidebar.header("π’ Enter Triangle Coordinates:")
|
42 |
-
|
43 |
-
# Sidebar inputs
|
44 |
-
x1 = st.sidebar.number_input("X1", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
|
45 |
-
y1 = st.sidebar.number_input("Y1", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
|
46 |
-
x2 = st.sidebar.number_input("X2", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
|
47 |
-
y2 = st.sidebar.number_input("Y2", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
|
48 |
-
x3 = st.sidebar.number_input("X3", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
|
49 |
-
y3 = st.sidebar.number_input("Y3", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
|
50 |
-
|
51 |
-
if st.sidebar.button("π Calculate"):
|
52 |
-
a = calculate_distance(x2, y2, x3, y3)
|
53 |
-
b = calculate_distance(x1, y1, x3, y3)
|
54 |
-
c = calculate_distance(x1, y1, x2, y2)
|
55 |
-
|
56 |
-
if not is_valid_triangle(a, b, c):
|
57 |
-
st.error("β The entered points do not form a valid triangle.")
|
58 |
-
return
|
59 |
-
|
60 |
-
# Calculate angles, area, etc.
|
61 |
-
A, B, C = calculate_angle(a, b, c), calculate_angle(b, a, c), calculate_angle(c, a, b)
|
62 |
-
area = calculate_area(a, b, c)
|
63 |
-
perimeter = calculate_perimeter(a, b, c)
|
64 |
-
radius_in = calculate_radius_inscribed_circle(a, b, c)
|
65 |
-
radius_circum = calculate_radius_circumscribed_circle(a, b, c)
|
66 |
-
G_x, G_y = calculate_centroid(x1, y1, x2, y2, x3, y3)
|
67 |
-
I_x, I_y = calculate_incenter(x1, y1, x2, y2, x3, y3, a, b, c)
|
68 |
-
U_x, U_y = calculate_circumcenter(x1, y1, x2, y2, x3, y3, a, b, c)
|
69 |
-
midpoints = calculate_midpoints(x1, y1, x2, y2, x3, y3)
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
col1.metric("π Angle A (Β°)", f"{A:.2f}")
|
74 |
-
col2.metric("π Side a (units)", f"{a:.2f}")
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
-
|
|
|
|
|
|
|
85 |
|
86 |
if __name__ == "__main__":
|
87 |
main()
|
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
from matplotlib.patches import Polygon, Circle
|
5 |
|
6 |
+
# Functions (including calculate_distance) are properly defined here
|
7 |
+
|
8 |
+
# Function to calculate the distance between two points
|
9 |
+
def calculate_distance(x1, y1, x2, y2):
|
10 |
+
return np.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
|
11 |
+
|
12 |
+
# Function to calculate angles using the Law of Cosines
|
13 |
+
def calculate_angle(a, b, c):
|
14 |
+
try:
|
15 |
+
angle = np.degrees(np.acos((b ** 2 + c ** 2 - a ** 2) / (2 * b * c)))
|
16 |
+
except ValueError:
|
17 |
+
angle = 0 # Handle possible domain error in acos
|
18 |
+
return angle
|
19 |
+
|
20 |
+
# Additional helper functions remain here...
|
21 |
|
22 |
def main():
|
23 |
+
st.set_page_config(
|
24 |
+
page_title="Advanced Triangle Solver",
|
25 |
+
layout="wide",
|
26 |
+
initial_sidebar_state="expanded",
|
27 |
+
)
|
28 |
+
|
29 |
+
# Enhanced Aesthetic Style
|
30 |
+
st.markdown(
|
31 |
+
"""
|
32 |
<style>
|
33 |
body {
|
34 |
+
background-color: #f7f9fc;
|
35 |
color: #333333;
|
36 |
+
font-family: 'Open Sans', sans-serif;
|
37 |
+
}
|
38 |
+
.stTitle, .stHeader, .stSubheader {
|
39 |
+
color: #1a73e8;
|
40 |
+
font-weight: bold;
|
41 |
}
|
42 |
.stSidebar {
|
43 |
+
background-color: #f0f4f8;
|
44 |
+
color: #333333;
|
45 |
}
|
46 |
+
.stMarkdown {
|
47 |
+
font-size: 16px;
|
|
|
48 |
}
|
49 |
+
.stButton > button {
|
50 |
+
background-color: #1a73e8;
|
51 |
color: white;
|
52 |
+
border: none;
|
53 |
border-radius: 5px;
|
|
|
54 |
padding: 10px 20px;
|
|
|
|
|
|
|
|
|
|
|
55 |
font-size: 16px;
|
56 |
+
cursor: pointer;
|
57 |
+
}
|
58 |
+
.stButton > button:hover {
|
59 |
+
background-color: #155ab3;
|
60 |
}
|
61 |
</style>
|
62 |
+
""",
|
63 |
+
unsafe_allow_html=True,
|
64 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
+
st.title("πΊ Advanced Triangle Solver")
|
67 |
+
st.sidebar.header("π Input Coordinates")
|
|
|
|
|
68 |
|
69 |
+
# Collect user input
|
70 |
+
x1 = st.sidebar.number_input("X1", min_value=-100.0, max_value=100.0, step=0.1, format="%.2f")
|
71 |
+
y1 = st.sidebar.number_input("Y1", min_value=-100.0, max_value=100.0, step=0.1, format="%.2f")
|
72 |
+
x2 = st.sidebar.number_input("X2", min_value=-100.0, max_value=100.0, step=0.1, format="%.2f")
|
73 |
+
y2 = st.sidebar.number_input("Y2", min_value=-100.0, max_value=100.0, step=0.1, format="%.2f")
|
74 |
+
x3 = st.sidebar.number_input("X3", min_value=-100.0, max_value=100.0, step=0.1, format="%.2f")
|
75 |
+
y3 = st.sidebar.number_input("Y3", min_value=-100.0, max_value=100.0, step=0.1, format="%.2f")
|
76 |
|
77 |
+
if st.sidebar.button("Calculate π"):
|
78 |
+
# Logic to calculate triangle properties and display them
|
79 |
+
try:
|
80 |
+
a = calculate_distance(x2, y2, x3, y3)
|
81 |
+
b = calculate_distance(x1, y1, x3, y3)
|
82 |
+
c = calculate_distance(x1, y1, x2, y2)
|
83 |
+
|
84 |
+
# Add calculations for angles, area, perimeter, etc.
|
85 |
|
86 |
+
# Plot the triangle
|
87 |
+
st.success("Triangle successfully solved!")
|
88 |
+
except Exception as e:
|
89 |
+
st.error(f"An error occurred: {e}")
|
90 |
|
91 |
if __name__ == "__main__":
|
92 |
main()
|