Shakeel1979 commited on
Commit
18ca239
·
verified ·
1 Parent(s): e71e4e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -34
app.py CHANGED
@@ -94,6 +94,34 @@ def plot_triangle(x1, y1, x2, y2, x3, y3, I_x, I_y, U_x, U_y, G_x, G_y, midpoint
94
  triangle = Polygon([(x1, y1), (x2, y2), (x3, y3)], closed=True, edgecolor='b', facecolor='lightblue')
95
  ax.add_patch(triangle)
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  # Define colors for different points
98
  vertex_color = 'blue'
99
  midpoint_color = 'green'
@@ -127,7 +155,7 @@ def plot_triangle(x1, y1, x2, y2, x3, y3, I_x, I_y, U_x, U_y, G_x, G_y, midpoint
127
  midpoint_name = ["M1", "M2", "M3"]
128
  for i, (mx, my) in enumerate(midpoints):
129
  ax.scatter(mx, my, color=midpoint_color, zorder=3)
130
- ax.text(mx, my, midpoint_name[i], fontsize=10, ha="left", va="bottom", color=midpoint_color)
131
 
132
 
133
  # Draw the inscribed circle (incircle)
@@ -140,32 +168,6 @@ def plot_triangle(x1, y1, x2, y2, x3, y3, I_x, I_y, U_x, U_y, G_x, G_y, midpoint
140
  circumcircle = Circle((U_x, U_y), radius_circum, color=circumcenter_color, fill=False, linestyle='--', linewidth=2, label="Circumscribed Circle")
141
  ax.add_patch(circumcircle)
142
 
143
- # Add legend
144
- handles = [
145
- plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=vertex_color, markersize=8, label=vertex_labels[0]),
146
- plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=vertex_color, markersize=8, label=vertex_labels[1]),
147
- plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=vertex_color, markersize=8, label=vertex_labels[2]),
148
- plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=midpoint_color, markersize=8, label=midpoints_labels[0]),
149
- plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=midpoint_color, markersize=8, label=midpoints_labels[1]),
150
- plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=midpoint_color, markersize=8, label=midpoints_labels[2]),
151
- plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=incenter_color, markersize=8, label=key_points_labels[0]),
152
- plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=circumcenter_color, markersize=8, label=key_points_labels[1]),
153
- plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=centroid_color, markersize=8, label=key_points_labels[2])
154
- ]
155
- ax.legend(handles=handles, loc='upper left', fontsize=12)
156
-
157
- # Adjust the plot limits and aspect ratio
158
- padding = 3
159
- ax.set_xlim([min(x1, x2, x3) - padding, max(x1, x2, x3) + padding])
160
- ax.set_ylim([min(y1, y2, y3) - padding, max(y1, y2, y3) + padding])
161
- ax.set_aspect('equal', adjustable='datalim')
162
-
163
- ax.set_title('Solved Triangle', fontsize=18)
164
- ax.set_xlabel('X-axis', fontsize=12)
165
- ax.set_ylabel('Y-axis', fontsize=12)
166
-
167
- plt.grid(True)
168
- st.pyplot(fig)
169
 
170
  # Function to check if the sides form a valid triangle
171
  def is_valid_triangle(a, b, c):
@@ -176,7 +178,7 @@ def is_valid_triangle(a, b, c):
176
  def main():
177
  st.title("Advanced Triangle Solver")
178
 
179
- st.sidebar.header("Enter the coordinates of the three points:")
180
 
181
  # Coordinates input (X1, Y1), (X2, Y2), (X3, Y3)
182
  x1 = st.sidebar.number_input("X1", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
@@ -252,7 +254,7 @@ def main():
252
  st.markdown(f"Side c: **{format_zero(c):.3f}** units")
253
 
254
 
255
- col1, col2, col3 = st.columns(3)
256
 
257
  with col1:
258
  st.subheader("Incenter of Triangle:")
@@ -264,11 +266,10 @@ def main():
264
  st.markdown(f"Coordinates: **({format_zero(U_x):.3f}, {format_zero(U_y):.3f})**")
265
  st.markdown(f"Radius: **{radius_circum:.3f}** units")
266
 
267
- with col3:
268
- st.subheader("Other Properties:")
269
- st.markdown(f"Area: **{format_zero(area):.3f}** square units")
270
- st.markdown(f"Perimeter: **{format_zero(perimeter):.3f}** units")
271
- st.markdown(f"Centroid: **({format_zero(G_x):.3f}, {format_zero(G_y):.3f})**")
272
 
273
  # Display triangle graph with midpoints and colored points
274
  plot_triangle(x1, y1, x2, y2, x3, y3, I_x, I_y, U_x, U_y, G_x, G_y, midpoints, a, b, c)
 
94
  triangle = Polygon([(x1, y1), (x2, y2), (x3, y3)], closed=True, edgecolor='b', facecolor='lightblue')
95
  ax.add_patch(triangle)
96
 
97
+ # Adjust the plot limits and aspect ratio
98
+ padding = 3
99
+ ax.set_xlim([min(x1, x2, x3) - padding, max(x1, x2, x3) + padding])
100
+ ax.set_ylim([min(y1, y2, y3) - padding, max(y1, y2, y3) + padding])
101
+ ax.set_aspect('equal', adjustable='datalim')
102
+
103
+ ax.set_title('Solved Triangle', fontsize=18)
104
+ ax.set_xlabel('X-axis', fontsize=12)
105
+ ax.set_ylabel('Y-axis', fontsize=12)
106
+
107
+ # Add a light grid
108
+ plt.grid(color='gray', linestyle='--', linewidth=0.5, alpha=0.5)
109
+ st.pyplot(fig)
110
+
111
+ # Add legend
112
+ handles = [
113
+ plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=vertex_color, markersize=7, label=vertex_labels[0]),
114
+ plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=vertex_color, markersize=7, label=vertex_labels[1]),
115
+ plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=vertex_color, markersize=7, label=vertex_labels[2]),
116
+ plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=midpoint_color, markersize=7, label=midpoints_labels[0]),
117
+ plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=midpoint_color, markersize=7, label=midpoints_labels[1]),
118
+ plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=midpoint_color, markersize=7, label=midpoints_labels[2]),
119
+ plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=incenter_color, markersize=7, label=key_points_labels[0]),
120
+ plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=circumcenter_color, markersize=7, label=key_points_labels[1]),
121
+ plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=centroid_color, markersize=7, label=key_points_labels[2])
122
+ ]
123
+ ax.legend(handles=handles, loc='upper left', fontsize=12)
124
+
125
  # Define colors for different points
126
  vertex_color = 'blue'
127
  midpoint_color = 'green'
 
155
  midpoint_name = ["M1", "M2", "M3"]
156
  for i, (mx, my) in enumerate(midpoints):
157
  ax.scatter(mx, my, color=midpoint_color, zorder=3)
158
+ ax.text(mx*1.003, my*1.003, midpoint_name[i], fontsize=10, ha="left", va="bottom", color=midpoint_color)
159
 
160
 
161
  # Draw the inscribed circle (incircle)
 
168
  circumcircle = Circle((U_x, U_y), radius_circum, color=circumcenter_color, fill=False, linestyle='--', linewidth=2, label="Circumscribed Circle")
169
  ax.add_patch(circumcircle)
170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
 
172
  # Function to check if the sides form a valid triangle
173
  def is_valid_triangle(a, b, c):
 
178
  def main():
179
  st.title("Advanced Triangle Solver")
180
 
181
+ st.sidebar.header("Enter the cartesion coordinates for the three points of a triangle:")
182
 
183
  # Coordinates input (X1, Y1), (X2, Y2), (X3, Y3)
184
  x1 = st.sidebar.number_input("X1", min_value=-100.0, max_value=100.0, step=0.1, format="%.3f")
 
254
  st.markdown(f"Side c: **{format_zero(c):.3f}** units")
255
 
256
 
257
+ col1, col2 = st.columns(2)
258
 
259
  with col1:
260
  st.subheader("Incenter of Triangle:")
 
266
  st.markdown(f"Coordinates: **({format_zero(U_x):.3f}, {format_zero(U_y):.3f})**")
267
  st.markdown(f"Radius: **{radius_circum:.3f}** units")
268
 
269
+ st.subheader("Other Properties:")
270
+ st.markdown(f"Area: **{format_zero(area):.3f}** square units")
271
+ st.markdown(f"Perimeter: **{format_zero(perimeter):.3f}** units")
272
+ st.markdown(f"Centroid: **({format_zero(G_x):.3f}, {format_zero(G_y):.3f})**")
 
273
 
274
  # Display triangle graph with midpoints and colored points
275
  plot_triangle(x1, y1, x2, y2, x3, y3, I_x, I_y, U_x, U_y, G_x, G_y, midpoints, a, b, c)