Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,22 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
from matplotlib.patches import Polygon, Circle
|
|
@@ -169,7 +187,7 @@ def is_valid_triangle(a, b, c):
|
|
| 169 |
|
| 170 |
# Main function to interact with the user
|
| 171 |
def main():
|
| 172 |
-
st.title("Advanced Triangle Solver"
|
| 173 |
|
| 174 |
st.sidebar.header("Enter the coordinates of the three points:")
|
| 175 |
|
|
@@ -181,51 +199,92 @@ def main():
|
|
| 181 |
x3 = st.sidebar.number_input("X3", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
|
| 182 |
y3 = st.sidebar.number_input("Y3", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
|
| 183 |
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
|
|
|
| 198 |
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
|
|
|
| 202 |
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
radius_circumscribed_circle = calculate_radius_circumscribed_circle(a, b, c)
|
| 206 |
|
| 207 |
-
|
| 208 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
|
| 210 |
-
|
| 211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
-
|
| 214 |
-
|
|
|
|
|
|
|
|
|
|
| 215 |
|
| 216 |
-
|
| 217 |
-
|
| 218 |
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
|
| 228 |
-
|
|
|
|
| 229 |
|
| 230 |
if __name__ == "__main__":
|
| 231 |
-
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from io import BytesIO
|
| 3 |
+
|
| 4 |
+
# Display video as background
|
| 5 |
+
def set_background_video():
|
| 6 |
+
video_file = open("numbers moving background.mp4", "rb")
|
| 7 |
+
video_bytes = video_file.read()
|
| 8 |
+
|
| 9 |
+
video = BytesIO(video_bytes)
|
| 10 |
+
st.markdown(
|
| 11 |
+
f'<video autoplay loop muted style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover;">'
|
| 12 |
+
f'<source src="data:video/mp4;base64,{video_bytes.encode("base64")}" type="video/mp4">'
|
| 13 |
+
f'</video>',
|
| 14 |
+
unsafe_allow_html=True
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
set_background_video()
|
| 18 |
+
|
| 19 |
+
|
| 20 |
import numpy as np
|
| 21 |
import matplotlib.pyplot as plt
|
| 22 |
from matplotlib.patches import Polygon, Circle
|
|
|
|
| 187 |
|
| 188 |
# Main function to interact with the user
|
| 189 |
def main():
|
| 190 |
+
st.title("Advanced Triangle Solver")
|
| 191 |
|
| 192 |
st.sidebar.header("Enter the coordinates of the three points:")
|
| 193 |
|
|
|
|
| 199 |
x3 = st.sidebar.number_input("X3", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
|
| 200 |
y3 = st.sidebar.number_input("Y3", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
|
| 201 |
|
| 202 |
+
if st.sidebar.button("Calculate"):
|
| 203 |
+
# Calculate the lengths of the sides of the triangle using Euclidean distance
|
| 204 |
+
a = calculate_distance(x2, y2, x3, y3)
|
| 205 |
+
b = calculate_distance(x1, y1, x3, y3)
|
| 206 |
+
c = calculate_distance(x1, y1, x2, y2)
|
| 207 |
+
|
| 208 |
+
# Validate if it's a valid triangle
|
| 209 |
+
if not is_valid_triangle(a, b, c):
|
| 210 |
+
st.error("The entered points do not form a valid triangle.")
|
| 211 |
+
return
|
| 212 |
+
|
| 213 |
+
# Calculate angles using the Law of Cosines
|
| 214 |
+
A = calculate_angle(a, b, c)
|
| 215 |
+
B = calculate_angle(b, a, c)
|
| 216 |
+
C = calculate_angle(c, a, b)
|
| 217 |
|
| 218 |
+
# Check if angles sum up to 180 degrees
|
| 219 |
+
if abs(A + B + C - 180) > 1e-2:
|
| 220 |
+
st.error("The sum of the angles is not 180 degrees.")
|
| 221 |
+
return
|
| 222 |
|
| 223 |
+
# Calculate area, perimeter, and radius of inscribed and circumscribed circles
|
| 224 |
+
area = calculate_area(a, b, c)
|
| 225 |
+
perimeter = calculate_perimeter(a, b, c)
|
| 226 |
+
radius_in = calculate_radius_inscribed_circle(a, b, c)
|
| 227 |
+
radius_circum = calculate_radius_circumscribed_circle(a, b, c)
|
| 228 |
|
| 229 |
+
# Calculate centroid, incenter, and circumcenter coordinates
|
| 230 |
+
G_x, G_y = calculate_centroid(x1, y1, x2, y2, x3, y3)
|
| 231 |
+
I_x, I_y = calculate_incenter(x1, y1, x2, y2, x3, y3, a, b, c)
|
| 232 |
+
U_x, U_y = calculate_circumcenter(x1, y1, x2, y2, x3, y3, a, b, c)
|
| 233 |
|
| 234 |
+
# Calculate midpoints of the sides
|
| 235 |
+
midpoints = calculate_midpoints(x1, y1, x2, y2, x3, y3)
|
|
|
|
| 236 |
|
| 237 |
+
# Display results in columns
|
| 238 |
+
col1, col2 = st.columns(2)
|
| 239 |
+
|
| 240 |
+
with col1:
|
| 241 |
+
st.subheader("Coordinates of Triangle:")
|
| 242 |
+
st.markdown(f"Vertex A: **({x1:.3f}, {y1:.3f})**")
|
| 243 |
+
st.markdown(f"Vertex B: **({x2:.3f}, {y2:.3f})**")
|
| 244 |
+
st.markdown(f"Vertex C: **({x3:.3f}, {y3:.3f})**")
|
| 245 |
+
|
| 246 |
+
with col2:
|
| 247 |
+
st.subheader("Mid-Points of Triangle:")
|
| 248 |
+
st.markdown(f"Midpoint of AB: ({midpoints[0][0]:.3f}, {midpoints[0][1]:.3f})")
|
| 249 |
+
st.markdown(f"Midpoint of BC: ({midpoints[1][0]:.3f}, {midpoints[1][1]:.3f})")
|
| 250 |
+
st.markdown(f"Midpoint of CA: ({midpoints[2][0]:.3f}, {midpoints[2][1]:.3f})")
|
| 251 |
|
| 252 |
+
|
| 253 |
+
col1, col2 = st.columns(2)
|
| 254 |
+
|
| 255 |
+
with col1:
|
| 256 |
+
st.subheader("Angles of Triangle:")
|
| 257 |
+
st.markdown(f"Angle A: **{format_zero(A):.3f}°**")
|
| 258 |
+
st.markdown(f"Angle B: **{format_zero(B):.3f}°**")
|
| 259 |
+
st.markdown(f"Angle C: **{format_zero(C):.3f}°**")
|
| 260 |
|
| 261 |
+
with col2:
|
| 262 |
+
st.subheader("Sides of Triangle:")
|
| 263 |
+
st.markdown(f"Side a: **{format_zero(a):.3f}** units")
|
| 264 |
+
st.markdown(f"Side b: **{format_zero(b):.3f}** units")
|
| 265 |
+
st.markdown(f"Side c: **{format_zero(c):.3f}** units")
|
| 266 |
|
| 267 |
+
|
| 268 |
+
col1, col2, col3 = st.columns(3)
|
| 269 |
|
| 270 |
+
with col1:
|
| 271 |
+
st.subheader("Incenter of Triangle:")
|
| 272 |
+
st.markdown(f"Coordinates: **({format_zero(I_x):.3f}, {format_zero(I_y):.3f})**")
|
| 273 |
+
st.markdown(f"Radius: **{radius_in:.3f}** units")
|
| 274 |
+
|
| 275 |
+
with col2:
|
| 276 |
+
st.subheader("Circumcenter of Triangle:")
|
| 277 |
+
st.markdown(f"Coordinates: **({format_zero(U_x):.3f}, {format_zero(U_y):.3f})**")
|
| 278 |
+
st.markdown(f"Radius: **{radius_circum:.3f}** units")
|
| 279 |
+
|
| 280 |
+
with col3:
|
| 281 |
+
st.subheader("Other Properties:")
|
| 282 |
+
st.markdown(f"Area: **{format_zero(area):.3f}** square units")
|
| 283 |
+
st.markdown(f"Perimeter: **{format_zero(perimeter):.3f}** units")
|
| 284 |
+
st.markdown(f"Centroid: **({format_zero(G_x):.3f}, {format_zero(G_y):.3f})**")
|
| 285 |
|
| 286 |
+
# Display triangle graph with midpoints and colored points
|
| 287 |
+
plot_triangle(x1, y1, x2, y2, x3, y3, I_x, I_y, U_x, U_y, G_x, G_y, midpoints, a, b, c)
|
| 288 |
|
| 289 |
if __name__ == "__main__":
|
| 290 |
+
main()
|