Shakeel1979 commited on
Commit
869830c
·
verified ·
1 Parent(s): 6372af3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -11
app.py CHANGED
@@ -99,51 +99,78 @@ def main():
99
  st.title("Advanced Triangle Solver")
100
 
101
  st.sidebar.header("Enter the coordinates of the three points:")
102
- x1 = st.sidebar.number_input("X1", -100.0, 100.0, step=0.1, format="%.3f")
103
- y1 = st.sidebar.number_input("Y1", -100.0, 100.0, step=0.1, format="%.3f")
104
- x2 = st.sidebar.number_input("X2", -100.0, 100.0, step=0.1, format="%.3f")
105
- y2 = st.sidebar.number_input("Y2", -100.0, 100.0, step=0.1, format="%.3f")
106
- x3 = st.sidebar.number_input("X3", -100.0, 100.0, step=0.1, format="%.3f")
107
- y3 = st.sidebar.number_input("Y3", -100.0, 100.0, step=0.1, format="%.3f")
 
 
108
 
109
  if st.sidebar.button("Calculate"):
 
110
  a = calculate_distance(x2, y2, x3, y3)
111
  b = calculate_distance(x1, y1, x3, y3)
112
  c = calculate_distance(x1, y1, x2, y2)
113
 
 
114
  A = calculate_angle(a, b, c)
115
  B = calculate_angle(b, a, c)
116
  C = calculate_angle(c, a, b)
117
 
 
118
  area = calculate_area(a, b, c)
119
  perimeter = calculate_perimeter(a, b, c)
120
  radius_in = calculate_radius_inscribed_circle(a, b, c)
121
  radius_circum = calculate_radius_circumscribed_circle(a, b, c)
122
 
 
123
  G_x, G_y = calculate_centroid(x1, y1, x2, y2, x3, y3)
124
  I_x, I_y = calculate_incenter(x1, y1, x2, y2, x3, y3, a, b, c)
125
  Ux, Uy = calculate_circumcenter(x1, y1, x2, y2, x3, y3, a, b, c)
126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  col1, col2, col3 = st.columns(3)
128
 
129
  with col1:
130
- st.subheader("Incenter of Triangle (Inscribed Circle):")
131
  st.markdown(f"Coordinates: **({format_zero(I_x):.3f}, {format_zero(I_y):.3f})**")
132
  st.markdown(f"Radius: **{radius_in:.3f}** units")
133
-
134
  with col2:
135
- st.subheader("Circumcenter of Triangle (Circumscribed Circle):")
136
  st.markdown(f"Coordinates: **({format_zero(Ux):.3f}, {format_zero(Uy):.3f})**")
137
  st.markdown(f"Radius: **{radius_circum:.3f}** units")
138
-
139
  with col3:
140
  st.subheader("Other Properties:")
141
  st.markdown(f"Area: **{area:.3f}** square units")
142
  st.markdown(f"Perimeter: **{perimeter:.3f}** units")
143
  st.markdown(f"Centroid Coordinates: **({G_x:.3f}, {G_y:.3f})**")
144
 
 
145
  plot_triangle(x1, y1, x2, y2, x3, y3, I_x, I_y, Ux, Uy, G_x, G_y)
146
 
147
- # Run the app
148
  if __name__ == "__main__":
149
  main()
 
99
  st.title("Advanced Triangle Solver")
100
 
101
  st.sidebar.header("Enter the coordinates of the three points:")
102
+
103
+ # Coordinates input (X1, Y1), (X2, Y2), (X3, Y3)
104
+ x1 = st.sidebar.number_input("X1", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
105
+ y1 = st.sidebar.number_input("Y1", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
106
+ x2 = st.sidebar.number_input("X2", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
107
+ y2 = st.sidebar.number_input("Y2", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
108
+ x3 = st.sidebar.number_input("X3", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
109
+ y3 = st.sidebar.number_input("Y3", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
110
 
111
  if st.sidebar.button("Calculate"):
112
+ # Calculate the lengths of the sides of the triangle using Euclidean distance
113
  a = calculate_distance(x2, y2, x3, y3)
114
  b = calculate_distance(x1, y1, x3, y3)
115
  c = calculate_distance(x1, y1, x2, y2)
116
 
117
+ # Calculate angles using the Law of Cosines
118
  A = calculate_angle(a, b, c)
119
  B = calculate_angle(b, a, c)
120
  C = calculate_angle(c, a, b)
121
 
122
+ # Calculate area, perimeter, and radius of inscribed and circumscribed circles
123
  area = calculate_area(a, b, c)
124
  perimeter = calculate_perimeter(a, b, c)
125
  radius_in = calculate_radius_inscribed_circle(a, b, c)
126
  radius_circum = calculate_radius_circumscribed_circle(a, b, c)
127
 
128
+ # Calculate centroid, incenter, and circumcenter coordinates
129
  G_x, G_y = calculate_centroid(x1, y1, x2, y2, x3, y3)
130
  I_x, I_y = calculate_incenter(x1, y1, x2, y2, x3, y3, a, b, c)
131
  Ux, Uy = calculate_circumcenter(x1, y1, x2, y2, x3, y3, a, b, c)
132
 
133
+ # Display results in columns
134
+ col1, col2, col3 = st.columns(3)
135
+
136
+ with col1:
137
+ st.subheader("Coordinates of Triangle:")
138
+ st.markdown(f"Vertex A: **({x1:.3f}, {y1:.3f})**")
139
+ st.markdown(f"Vertex B: **({x2:.3f}, {y2:.3f})**")
140
+ st.markdown(f"Vertex C: **({x3:.3f}, {y3:.3f})**")
141
+
142
+ with col2:
143
+ st.subheader("Sides of Triangle:")
144
+ st.markdown(f"Side a: **{a:.3f}** units")
145
+ st.markdown(f"Side b: **{b:.3f}** units")
146
+ st.markdown(f"Side c: **{c:.3f}** units")
147
+
148
+ with col3:
149
+ st.subheader("Angles of Triangle:")
150
+ st.markdown(f"Angle A: **{A:.3f}°**")
151
+ st.markdown(f"Angle B: **{B:.3f}°**")
152
+ st.markdown(f"Angle C: **{C:.3f}°**")
153
+
154
  col1, col2, col3 = st.columns(3)
155
 
156
  with col1:
157
+ st.subheader("Incenter of Triangle:")
158
  st.markdown(f"Coordinates: **({format_zero(I_x):.3f}, {format_zero(I_y):.3f})**")
159
  st.markdown(f"Radius: **{radius_in:.3f}** units")
160
+
161
  with col2:
162
+ st.subheader("Circumcenter of Triangle:")
163
  st.markdown(f"Coordinates: **({format_zero(Ux):.3f}, {format_zero(Uy):.3f})**")
164
  st.markdown(f"Radius: **{radius_circum:.3f}** units")
165
+
166
  with col3:
167
  st.subheader("Other Properties:")
168
  st.markdown(f"Area: **{area:.3f}** square units")
169
  st.markdown(f"Perimeter: **{perimeter:.3f}** units")
170
  st.markdown(f"Centroid Coordinates: **({G_x:.3f}, {G_y:.3f})**")
171
 
172
+ # Display triangle graph with incenter, circumcenter, and centroid
173
  plot_triangle(x1, y1, x2, y2, x3, y3, I_x, I_y, Ux, Uy, G_x, G_y)
174
 
 
175
  if __name__ == "__main__":
176
  main()