import numpy as np
import matplotlib.pyplot as plt
# Parámetros
L = 0.9 # Longitud de los lados del triángulo (m) - Ampliado a 0.5
d_circulo = 0.45 # Diámetro del círculo (m)
r_circulo = d_circulo / 2 # Radio del círculo (m)
# Cálculo de la altura del triángulo
h_triangulo = (np.sqrt(3) / 2) * L # Altura total del triángulo
# Desplazamiento vertical para mover la base del triángulo a y = 1.0
vertical_shift = 1.0 # Base del triángulo en y = 1.0
# Coordenadas del triángulo invertido y desplazado
triangle_vertices = np.array([
[0, vertical_shift], # Vértice izquierdo
[L, vertical_shift], # Vértice derecho
[L / 2, -h_triangulo + vertical_shift] # Vértice inferior (inversión)
])
# Baricentro del triángulo
baricentro = np.array([L / 2, vertical_shift - h_triangulo / 3])
# Crear la figura y el eje con un tamaño más grande
fig, ax = plt.subplots(figsize=(8, 6)) # Tamaño de la figura
# Dibujar el triángulo
ax.plot([triangle_vertices[0][0], triangle_vertices[2][0]],
[triangle_vertices[0][1], triangle_vertices[2][1]],
'k-', lw=2)
ax.plot([triangle_vertices[1][0], triangle_vertices[2][0]],
[triangle_vertices[1][1], triangle_vertices[2][1]],
'k-', lw=2)
ax.plot([triangle_vertices[0][0], triangle_vertices[1][0]],
[triangle_vertices[0][1], triangle_vertices[1][1]],
'k-', lw=2, label="Aristas del triángulo")
# Dibujar los vértices
ax.plot(triangle_vertices[:, 0], triangle_vertices[:, 1], 'ro', markersize=8, label="Vértices del triángulo")
# Dibujar el baricentro
ax.plot(baricentro[0], baricentro[1], 'bo', markersize=8, label="Baricentro")
# Dibujar las alturas
ax.plot([baricentro[0], (triangle_vertices[0][0] + triangle_vertices[1][0]) / 2],
[baricentro[1], (triangle_vertices[0][1] + triangle_vertices[1][1]) / 2],
'b--', lw=2, label="Distancia del baricentro al punto medio de una arista")
ax.plot([baricentro[0], triangle_vertices[0][0]],
[baricentro[1], triangle_vertices[0][1]],
'g--', lw=2, label="Distancia del baricentro al vértice")
# Dibujar el círculo inscrito
circulo = plt.Circle((baricentro[0], baricentro[1]), r_circulo, color='orange', fill=False, lw=2)
ax.add_patch(circulo)
ax.plot([], [], color='orange', lw=2, label="Círculo inscrito") # Línea en la leyenda
# Configuración del gráfico
ax.set_aspect('equal')
ax.set_xlim(-0.03, 0.95) # Límites del eje x ajustados para L = 0.5
ax.set_ylim(-0.1, 1.1) # Límites del eje y ajustados para el nuevo tamaño
ax.set_xlabel('x (m)')
ax.set_ylabel('y (m)')
ax.set_title('Elementos del Triángulo: Lados, Alturas y Círculo Inscrito')
# Leyenda fuera del gráfico y más a la derecha
legend = ax.legend(loc='upper left', bbox_to_anchor=(0.7, 0.3), frameon=True)
# Ajustes finales
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.tick_params(axis='both', which='both', direction='out', length=5)
ax.grid(False)
# Mostrar la figura
plt.tight_layout() # Ajusta el layout para que la leyenda no se solape
plt.show()
To embed this program on your website, copy the following code and paste it into your website's HTML: