Shakeel1979 commited on
Commit
df2b0fb
·
verified ·
1 Parent(s): 0ed798a

Delete Old_app_py.txt

Browse files
Files changed (1) hide show
  1. Old_app_py.txt +0 -188
Old_app_py.txt DELETED
@@ -1,188 +0,0 @@
1
- import streamlit as st
2
- import math
3
- import matplotlib.pyplot as plt
4
- import numpy as np
5
- from matplotlib.patches import Polygon
6
-
7
- # Function to calculate the distance between two points
8
- def calculate_distance(x1, y1, x2, y2):
9
- return math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
10
-
11
- # Function to calculate angles using Law of Cosines
12
- def calculate_angle(a, b, c):
13
- # a, b, c are sides of the triangle
14
- angle = math.degrees(math.acos((b**2 + c**2 - a**2) / (2 * b * c)))
15
- return angle
16
-
17
- # Function to calculate area using Heron's formula
18
- def calculate_area(a, b, c):
19
- s = (a + b + c) / 2
20
- area = math.sqrt(s * (s - a) * (s - b) * (s - c))
21
- return area
22
-
23
- # Function to calculate the perimeter
24
- def calculate_perimeter(a, b, c):
25
- return a + b + c
26
-
27
- # Function to calculate the radius of the inscribed circle
28
- def calculate_radius_inscribed_circle(a, b, c):
29
- s = (a + b + c) / 2
30
- area = calculate_area(a, b, c)
31
- radius = area / s
32
- return radius
33
-
34
- # Function to calculate the radius of the circumscribed circle
35
- def calculate_radius_circumscribed_circle(a, b, c):
36
- area = calculate_area(a, b, c)
37
- radius = (a * b * c) / (4 * area)
38
- return radius
39
-
40
- # Function to calculate the centroid coordinates
41
- def calculate_centroid(x1, y1, x2, y2, x3, y3):
42
- G_x = (x1 + x2 + x3) / 3
43
- G_y = (y1 + y2 + y3) / 3
44
- return G_x, G_y
45
-
46
- # Function to calculate the incenter coordinates
47
- def calculate_incenter(x1, y1, x2, y2, x3, y3, a, b, c):
48
- I_x = (a * x1 + b * x2 + c * x3) / (a + b + c)
49
- I_y = (a * y1 + b * y2 + c * y3) / (a + b + c)
50
- return I_x, I_y
51
-
52
- # Function to calculate the circumcenter coordinates
53
- def calculate_circumcenter(x1, y1, x2, y2, x3, y3, a, b, c):
54
- D = 2 * (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2))
55
- Ux = ((x1**2 + y1**2) * (y2 - y3) + (x2**2 + y2**2) * (y3 - y1) + (x3**2 + y3**2) * (y1 - y2)) / D
56
- Uy = ((x1**2 + y1**2) * (x3 - x2) + (x2**2 + y2**2) * (x1 - x3) + (x3**2 + y3**2) * (x2 - x1)) / D
57
- return Ux, Uy
58
-
59
- # Function to format values close to zero as 0
60
- def format_zero(val):
61
- if abs(val) < 1e-6: # Tolerance to consider as zero
62
- return 0.0 # or return 0 for integer precision
63
- return val
64
-
65
- # Function to plot the triangle
66
- def plot_triangle(x1, y1, x2, y2, x3, y3, I_x, I_y, Ux, Uy, G_x, G_y):
67
- fig, ax = plt.subplots()
68
- triangle = Polygon([(x1, y1), (x2, y2), (x3, y3)], closed=True, edgecolor='b', facecolor='lightblue')
69
- ax.add_patch(triangle)
70
-
71
- # Plot the incenter, circumcenter, and centroid
72
- ax.scatter([I_x, Ux, G_x], [I_y, Uy, G_y], color="red", zorder=5)
73
- ax.text(I_x, I_y, "Incenter", fontsize=12, color="red")
74
- ax.text(Ux, Uy, "Circumcenter", fontsize=12, color="red")
75
- ax.text(G_x, G_y, "Centroid", fontsize=12, color="red")
76
-
77
- ax.set_xlim([min(x1, x2, x3) - 1, max(x1, x2, x3) + 1])
78
- ax.set_ylim([min(y1, y2, y3) - 1, max(y1, y2, y3) + 1])
79
- ax.set_aspect('equal', 'box')
80
- ax.set_title('Triangle with Circles and Centroids')
81
- ax.set_xlabel('X')
82
- ax.set_ylabel('Y')
83
-
84
- plt.grid(True)
85
- st.pyplot(fig) # Use st.pyplot() to display the plot in Streamlit
86
-
87
- # # Function to plot the triangle
88
- # def plot_triangle(x1, y1, x2, y2, x3, y3, I_x, I_y, Ux, Uy, G_x, G_y):
89
- # fig, ax = plt.subplots()
90
- # triangle = Polygon([(x1, y1), (x2, y2), (x3, y3)], closed=True, edgecolor='b', facecolor='lightblue')
91
- # ax.add_patch(triangle)
92
-
93
- # # Plot the incenter, circumcenter, and centroid
94
- # ax.scatter([I_x, Ux, G_x], [I_y, Uy, G_y], color="red", zorder=5)
95
- # ax.text(I_x, I_y, "Incenter", fontsize=12, color="red")
96
- # ax.text(Ux, Uy, "Circumcenter", fontsize=12, color="red")
97
- # ax.text(G_x, G_y, "Centroid", fontsize=12, color="red")
98
-
99
- # ax.set_xlim([min(x1, x2, x3) - 1, max(x1, x2, x3) + 1])
100
- # ax.set_ylim([min(y1, y2, y3) - 1, max(y1, y2, y3) + 1])
101
- # ax.set_aspect('equal', 'box')
102
- # ax.set_title('Triangle with Circles and Centroids')
103
- # ax.set_xlabel('X')
104
- # ax.set_ylabel('Y')
105
-
106
- # plt.grid(True)
107
- # plt.show()
108
-
109
- # Main function to interact with the user
110
- def main():
111
- st.title("Advanced Triangle Solver")
112
-
113
- st.sidebar.header("Enter the coordinates of the three points:")
114
-
115
- # Coordinates input (X1, Y1), (X2, Y2), (X3, Y3)
116
- x1 = st.sidebar.number_input("X1", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
117
- y1 = st.sidebar.number_input("Y1", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
118
- x2 = st.sidebar.number_input("X2", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
119
- y2 = st.sidebar.number_input("Y2", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
120
- x3 = st.sidebar.number_input("X3", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
121
- y3 = st.sidebar.number_input("Y3", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
122
-
123
- if st.sidebar.button("Calculate"):
124
- # Calculate the lengths of the sides of the triangle using Euclidean distance
125
- a = calculate_distance(x2, y2, x3, y3)
126
- b = calculate_distance(x1, y1, x3, y3)
127
- c = calculate_distance(x1, y1, x2, y2)
128
-
129
- # Calculate angles using the Law of Cosines
130
- A = calculate_angle(a, b, c)
131
- B = calculate_angle(b, a, c)
132
- C = calculate_angle(c, a, b)
133
-
134
- # Calculate area, perimeter, and radius of inscribed and circumscribed circles
135
- area = calculate_area(a, b, c)
136
- perimeter = calculate_perimeter(a, b, c)
137
- radius_in = calculate_radius_inscribed_circle(a, b, c)
138
- radius_circum = calculate_radius_circumscribed_circle(a, b, c)
139
-
140
- # Calculate centroid, incenter, and circumcenter coordinates
141
- G_x, G_y = calculate_centroid(x1, y1, x2, y2, x3, y3)
142
- I_x, I_y = calculate_incenter(x1, y1, x2, y2, x3, y3, a, b, c)
143
- Ux, Uy = calculate_circumcenter(x1, y1, x2, y2, x3, y3, a, b, c)
144
-
145
- # Display results in columns
146
- col1, col2, col3 = st.columns(3)
147
-
148
- with col1:
149
- st.subheader("Coordinates of Triangle:")
150
- st.markdown(f"Vertex A: **({x1:.3f}, {y1:.3f})**")
151
- st.markdown(f"Vertex B: **({x2:.3f}, {y2:.3f})**")
152
- st.markdown(f"Vertex C: **({x3:.3f}, {y3:.3f})**")
153
-
154
- with col2:
155
- st.subheader("Sides of Triangle:")
156
- st.markdown(f"Side a: **{a:.3f}** units")
157
- st.markdown(f"Side b: **{b:.3f}** units")
158
- st.markdown(f"Side c: **{c:.3f}** units")
159
-
160
- with col3:
161
- st.subheader("Angles of Triangle:")
162
- st.markdown(f"Angle A: **{A:.3f}°**")
163
- st.markdown(f"Angle B: **{B:.3f}°**")
164
- st.markdown(f"Angle C: **{C:.3f}°**")
165
-
166
- col1, col2, col3 = st.columns(3)
167
-
168
- with col1:
169
- st.subheader("Incenter of Triangle (Inscribed Circle):")
170
- st.markdown(f"Coordinates: **({format_zero(I_x):.3f}, {format_zero(I_y):.3f})**")
171
- st.markdown(f"Radius: **{radius_in:.3f}** units")
172
-
173
- with col2:
174
- st.subheader("Circumcenter of Triangle (Circumscribed Circle):")
175
- st.markdown(f"Coordinates: **({format_zero(Ux):.3f}, {format_zero(Uy):.3f})**")
176
- st.markdown(f"Radius: **{radius_circum:.3f}** units")
177
-
178
- with col3:
179
- st.subheader("Other Properties:")
180
- st.markdown(f"Area: **{area:.3f}** square units")
181
- st.markdown(f"Perimeter: **{perimeter:.3f}** units")
182
- st.markdown(f"Centroid Coordinates: **({G_x:.3f}, {G_y:.3f})**")
183
-
184
- # Display triangle graph with incenter, circumcenter, and centroid
185
- plot_triangle(x1, y1, x2, y2, x3, y3, I_x, I_y, Ux, Uy, G_x, G_y)
186
-
187
- if __name__ == "__main__":
188
- main()