math / app.py
engrharis's picture
Update app.py
0773e01 verified
raw
history blame
2.99 kB
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(
"""
<style>
body {
background-color: #f7f9fc;
color: #333333;
font-family: 'Open Sans', sans-serif;
}
.stTitle, .stHeader, .stSubheader {
color: #1a73e8;
font-weight: bold;
}
.stSidebar {
background-color: #f0f4f8;
color: #333333;
}
.stMarkdown {
font-size: 16px;
}
.stButton > button {
background-color: #1a73e8;
color: white;
border: none;
border-radius: 5px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
.stButton > button:hover {
background-color: #155ab3;
}
</style>
""",
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()