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(""" """, 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()