import streamlit as st import numpy as np import matplotlib.pyplot as plt from matplotlib.patches import Polygon, Circle # Functions (including calculate_distance) are properly defined here # Function to calculate the distance between two points def calculate_distance(x1, y1, x2, y2): return np.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) # Function to calculate angles using the Law of Cosines def calculate_angle(a, b, c): try: angle = np.degrees(np.acos((b ** 2 + c ** 2 - a ** 2) / (2 * b * c))) except ValueError: angle = 0 # Handle possible domain error in acos return angle # Additional helper functions remain here... def main(): st.set_page_config( page_title="Advanced Triangle Solver", layout="wide", initial_sidebar_state="expanded", ) # Enhanced Aesthetic Style st.markdown( """ """, unsafe_allow_html=True, ) st.title("🔺 Advanced Triangle Solver") st.sidebar.header("📌 Input Coordinates") # Collect user input x1 = st.sidebar.number_input("X1", min_value=-100.0, max_value=100.0, step=0.1, format="%.2f") y1 = st.sidebar.number_input("Y1", min_value=-100.0, max_value=100.0, step=0.1, format="%.2f") x2 = st.sidebar.number_input("X2", min_value=-100.0, max_value=100.0, step=0.1, format="%.2f") y2 = st.sidebar.number_input("Y2", min_value=-100.0, max_value=100.0, step=0.1, format="%.2f") x3 = st.sidebar.number_input("X3", min_value=-100.0, max_value=100.0, step=0.1, format="%.2f") y3 = st.sidebar.number_input("Y3", min_value=-100.0, max_value=100.0, step=0.1, format="%.2f") if st.sidebar.button("Calculate 🔍"): # Logic to calculate triangle properties and display them try: a = calculate_distance(x2, y2, x3, y3) b = calculate_distance(x1, y1, x3, y3) c = calculate_distance(x1, y1, x2, y2) # Add calculations for angles, area, perimeter, etc. # Plot the triangle st.success("Triangle successfully solved!") except Exception as e: st.error(f"An error occurred: {e}") if __name__ == "__main__": main()