File size: 3,739 Bytes
01b44ac
0742a4e
 
 
8d2aac4
0742a4e
 
 
8d2aac4
0742a4e
 
 
 
 
 
 
 
 
 
 
8d2aac4
37c899c
fb2e9b3
0773e01
 
 
 
 
fb2e9b3
0773e01
fb2e9b3
0773e01
 
fb2e9b3
 
 
c8bc3b1
 
fb2e9b3
c8bc3b1
 
 
 
fb2e9b3
c8bc3b1
37c899c
c8bc3b1
 
 
 
 
 
 
 
 
37c899c
 
 
 
 
 
 
 
fb2e9b3
37c899c
 
 
c8bc3b1
37c899c
 
 
c8bc3b1
fb2e9b3
37c899c
 
 
 
 
 
 
 
c8bc3b1
fb2e9b3
 
c8bc3b1
fb2e9b3
37c899c
01b44ac
765e25a
37c899c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import streamlit as st
def set_background_video():
    video_path = 'numbers moving background.mp4'
    with open(video_path, 'rb') as video_file:
        video_bytes = video_file.read()
    video_base64 = base64.b64encode(video_bytes).decode('utf-8')

    # Adjust the video HTML
    video_html = f"""
    <video 
        style="position: fixed; right: 0; bottom: 0; min-width: 100%; min-height: 100%; width: auto; height: auto; z-index: -1;"
        preload="auto" 
        autoplay 
        loop 
        muted
    >
    <source src="data:video/mp4;base64,{video_base64}" type="video/mp4">
    Your browser does not support the video tag.
    </video>
    """
    st.markdown(video_html, unsafe_allow_html=True)

# --- Triangle Calculation and Plotting Functions ---
def calculate_distance(x1, y1, x2, y2):
    return np.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)

def calculate_angle(a, b, c):
    try:
        angle = np.degrees(np.arccos((b ** 2 + c ** 2 - a ** 2) / (2 * b * c)))
    except ValueError:
        angle = 0
    return angle

# ... (rest of your calculation functions: calculate_area, calculate_perimeter,
# calculate_radius_inscribed_circle, calculate_radius_circumscribed_circle,
# calculate_centroid, calculate_incenter, calculate_circumcenter, calculate_midpoints, format_zero)

def plot_triangle(x1, y1, x2, y2, x3, y3, I_x, I_y, U_x, U_y, G_x, G_y, midpoints, a, b, c):
    # ... (your plot_triangle function - no changes needed here)

def is_valid_triangle(a, b, c):
    return a + b > c and b + c > a and c + a > b

# --- Main Streamlit App ---
def main():
    st.title("Advanced Triangle Solver")

    st.sidebar.header("Enter the coordinates of the three points:")
    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

        A = calculate_angle(a, b, c)
        B = calculate_angle(b, a, c)
        C = calculate_angle(c, a, b)

        if abs(A + B + C - 180) > 1e-2:
            st.error("The sum of the angles is not 180 degrees.")
            return

        # ... (rest of your calculations for area, perimeter, radii, centroid, incenter, circumcenter)
        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 (no changes needed here)
        # ... (your existing display code using st.columns, st.subheader, st.markdown)

        # Plot the triangle
        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()