Shakeel1979 commited on
Commit
168dae3
·
verified ·
1 Parent(s): df2b0fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -11
app.py CHANGED
@@ -61,27 +61,45 @@ def format_zero(val):
61
  return 0.0
62
  return val
63
 
64
- # Function to plot the triangle
65
  def plot_triangle(x1, y1, x2, y2, x3, y3, I_x, I_y, Ux, Uy, G_x, G_y):
66
  fig, ax = plt.subplots(figsize=(8, 6))
67
  triangle = Polygon([(x1, y1), (x2, y2), (x3, y3)], closed=True, edgecolor='b', facecolor='lightblue')
68
  ax.add_patch(triangle)
69
 
 
 
 
 
 
 
 
70
  vertices = [(x1, y1), (x2, y2), (x3, y3)]
71
  for i, (vx, vy) in enumerate(vertices):
72
- ax.scatter(vx, vy, color="blue", zorder=5)
73
- ax.text(vx, vy, f"P{i+1} ({vx:.1f}, {vy:.1f})", fontsize=10, ha="left", va="bottom", color="blue")
74
 
 
75
  key_points = [
76
- (I_x, I_y, "Incenter"),
77
- (Ux, Uy, "Circumcenter"),
78
- (G_x, G_y, "Centroid")
79
  ]
80
 
81
- for x, y, label in key_points:
82
- ax.scatter(x, y, color="red", zorder=5)
83
- ax.text(x, y, f"{label}\n({x:.1f}, {y:.1f})", fontsize=10, ha="right", va="top", color="red")
 
 
 
 
 
 
 
 
 
84
 
 
85
  padding = 3
86
  ax.set_xlim([min(x1, x2, x3) - padding, max(x1, x2, x3) + padding])
87
  ax.set_ylim([min(y1, y2, y3) - padding, max(y1, y2, y3) + padding])
@@ -169,8 +187,8 @@ def main():
169
  st.markdown(f"Perimeter: **{perimeter:.3f}** units")
170
  st.markdown(f"Centroid: **({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()
 
61
  return 0.0
62
  return val
63
 
64
+ # Function to plot the triangle with all points in different colors and a legend
65
  def plot_triangle(x1, y1, x2, y2, x3, y3, I_x, I_y, Ux, Uy, G_x, G_y):
66
  fig, ax = plt.subplots(figsize=(8, 6))
67
  triangle = Polygon([(x1, y1), (x2, y2), (x3, y3)], closed=True, edgecolor='b', facecolor='lightblue')
68
  ax.add_patch(triangle)
69
 
70
+ # Define colors for different points
71
+ vertex_color = 'blue'
72
+ centroid_color = 'green'
73
+ incenter_color = 'red'
74
+ circumcenter_color = 'purple'
75
+
76
+ # Plot the triangle vertices
77
  vertices = [(x1, y1), (x2, y2), (x3, y3)]
78
  for i, (vx, vy) in enumerate(vertices):
79
+ ax.scatter(vx, vy, color=vertex_color, zorder=5)
80
+ ax.text(vx, vy, f"P{i+1} ({vx:.1f}, {vy:.1f})", fontsize=10, ha="left", va="bottom", color=vertex_color)
81
 
82
+ # Plot key points with their corresponding colors
83
  key_points = [
84
+ (I_x, I_y, incenter_color, "Incenter"),
85
+ (Ux, Uy, circumcenter_color, "Circumcenter"),
86
+ (G_x, G_y, centroid_color, "Centroid")
87
  ]
88
 
89
+ for x, y, color, label in key_points:
90
+ ax.scatter(x, y, color=color, zorder=5)
91
+ ax.text(x, y, f"{label}\n({x:.1f}, {y:.1f})", fontsize=10, ha="right", va="top", color=color)
92
+
93
+ # Add legend
94
+ handles = [
95
+ plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=vertex_color, markersize=10, label="Vertices"),
96
+ plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=centroid_color, markersize=10, label="Centroid"),
97
+ plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=incenter_color, markersize=10, label="Incenter"),
98
+ plt.Line2D([0], [0], marker='o', color='w', markerfacecolor=circumcenter_color, markersize=10, label="Circumcenter")
99
+ ]
100
+ ax.legend(handles=handles, loc='upper left', fontsize=12)
101
 
102
+ # Adjust the plot limits and aspect ratio
103
  padding = 3
104
  ax.set_xlim([min(x1, x2, x3) - padding, max(x1, x2, x3) + padding])
105
  ax.set_ylim([min(y1, y2, y3) - padding, max(y1, y2, y3) + padding])
 
187
  st.markdown(f"Perimeter: **{perimeter:.3f}** units")
188
  st.markdown(f"Centroid: **({G_x:.3f}, {G_y:.3f})**")
189
 
190
+ # Display triangle graph with colored points and legend
191
  plot_triangle(x1, y1, x2, y2, x3, y3, I_x, I_y, Ux, Uy, G_x, G_y)
192
 
193
  if __name__ == "__main__":
194
+ main()