math / app.py
engrharis's picture
Update app.py
765e25a verified
raw
history blame
3.25 kB
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon, Circle
# Function definitions remain the same
def main():
# Custom styles for the app
st.markdown("""
<style>
body {
background-color: #f0f2f6;
color: #333333;
font-family: 'Arial', sans-serif;
}
.stSidebar {
background-color: #1e3a56;
}
h1, h2, h3, h4, h5, h6 {
color: #1e3a56;
font-family: 'Georgia', serif;
}
.stButton>button {
background-color: #1e3a56;
color: white;
border-radius: 5px;
font-size: 16px;
padding: 10px 20px;
}
.stButton>button:hover {
background-color: #0d2a45;
}
.stMarkdown {
font-size: 16px;
}
</style>
""", unsafe_allow_html=True)
st.title("🎨 Advanced Triangle Solver")
st.sidebar.header("πŸ”’ Enter Triangle Coordinates:")
# Sidebar inputs
x1 = st.sidebar.number_input("X1", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
y1 = st.sidebar.number_input("Y1", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
x2 = st.sidebar.number_input("X2", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
y2 = st.sidebar.number_input("Y2", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
x3 = st.sidebar.number_input("X3", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
y3 = st.sidebar.number_input("Y3", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
if st.sidebar.button("πŸ” Calculate"):
a = calculate_distance(x2, y2, x3, y3)
b = calculate_distance(x1, y1, x3, y3)
c = calculate_distance(x1, y1, x2, y2)
if not is_valid_triangle(a, b, c):
st.error("❌ The entered points do not form a valid triangle.")
return
# Calculate angles, area, etc.
A, B, C = calculate_angle(a, b, c), calculate_angle(b, a, c), calculate_angle(c, a, b)
area = calculate_area(a, b, c)
perimeter = calculate_perimeter(a, b, c)
radius_in = calculate_radius_inscribed_circle(a, b, c)
radius_circum = calculate_radius_circumscribed_circle(a, b, c)
G_x, G_y = calculate_centroid(x1, y1, x2, y2, x3, y3)
I_x, I_y = calculate_incenter(x1, y1, x2, y2, x3, y3, a, b, c)
U_x, U_y = calculate_circumcenter(x1, y1, x2, y2, x3, y3, a, b, c)
midpoints = calculate_midpoints(x1, y1, x2, y2, x3, y3)
# Display results
col1, col2 = st.columns(2)
col1.metric("πŸ“ Angle A (Β°)", f"{A:.2f}")
col2.metric("πŸ“ Side a (units)", f"{a:.2f}")
# Additional metrics for better organization
col1.metric("πŸ“ Angle B (Β°)", f"{B:.2f}")
col2.metric("πŸ“ Side b (units)", f"{b:.2f}")
st.subheader("πŸ“Š Properties")
st.write(f"**Area:** {area:.2f} sq. units")
st.write(f"**Perimeter:** {perimeter:.2f} units")
plot_triangle(x1, y1, x2, y2, x3, y3, I_x, I_y, U_x, U_y, G_x, G_y, midpoints, a, b, c)
if __name__ == "__main__":
main()