|
|
import numpy as np |
|
|
import streamlit as st |
|
|
import plotly.graph_objects as go |
|
|
import matplotlib.pyplot as plt |
|
|
from matplotlib.patches import Polygon |
|
|
from matplotlib.collections import PatchCollection |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
st.title("Тетраэдр и его развёртка") |
|
|
|
|
|
|
|
|
vertices = np.array([ |
|
|
[1, 1, 1], |
|
|
[-1, -1, 1], |
|
|
[-1, 1, -1], |
|
|
[1, -1, -1] |
|
|
]) |
|
|
|
|
|
|
|
|
faces = [ |
|
|
[0, 1, 2], |
|
|
[0, 1, 3], |
|
|
[0, 2, 3], |
|
|
[1, 2, 3] |
|
|
] |
|
|
|
|
|
|
|
|
fig_3d = go.Figure() |
|
|
|
|
|
|
|
|
fig_3d.add_trace(go.Scatter3d( |
|
|
x=vertices[:, 0], |
|
|
y=vertices[:, 1], |
|
|
z=vertices[:, 2], |
|
|
mode='markers+text', |
|
|
marker=dict(size=5, color='red'), |
|
|
text=['1', '2', '3', '4'], |
|
|
textposition="top center" |
|
|
)) |
|
|
|
|
|
|
|
|
for face in faces: |
|
|
x = vertices[face, 0] |
|
|
y = vertices[face, 1] |
|
|
z = vertices[face, 2] |
|
|
fig_3d.add_trace(go.Mesh3d( |
|
|
x=x, y=y, z=z, |
|
|
opacity=0.3, |
|
|
color='lightblue' |
|
|
)) |
|
|
|
|
|
|
|
|
fig_3d.add_trace(go.Scatter3d( |
|
|
x=[vertices[1, 0], vertices[2, 0]], |
|
|
y=[vertices[1, 1], vertices[2, 1]], |
|
|
z=[vertices[1, 2], vertices[2, 2]], |
|
|
mode='lines', |
|
|
line=dict(color='blue', dash='dot') |
|
|
)) |
|
|
|
|
|
fig_3d.update_layout( |
|
|
scene=dict(xaxis_title='X', yaxis_title='Y', zaxis_title='Z'), |
|
|
title="3D-тетраэдр", |
|
|
margin=dict(l=0, r=0, b=0, t=40) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fig_2d, ax = plt.subplots(figsize=(6, 6)) |
|
|
|
|
|
|
|
|
points = np.array([ |
|
|
[0, 0], |
|
|
[2, 0], |
|
|
[1, np.sqrt(3)], |
|
|
[0.5, np.sqrt(3)/2], |
|
|
[1.5, np.sqrt(3)/2] |
|
|
]) |
|
|
|
|
|
|
|
|
triangles = [ |
|
|
Polygon([points[0], points[1], points[2]], closed=True, fill=False, edgecolor='blue', linewidth=2), |
|
|
Polygon([points[0], points[2], points[3]], closed=True, fill=False, edgecolor='blue', linewidth=2), |
|
|
Polygon([points[1], points[2], points[4]], closed=True, fill=False, edgecolor='blue', linewidth=2), |
|
|
Polygon([points[1], points[4], points[0]], closed=True, fill=False, edgecolor='blue', linewidth=2) |
|
|
] |
|
|
|
|
|
|
|
|
labels = ['1', '2', '3', '4', '4'] |
|
|
for i, point in enumerate(points): |
|
|
ax.text(point[0], point[1], labels[i], ha='center', va='center', fontsize=12, color='red') |
|
|
|
|
|
|
|
|
ax.set_aspect('equal') |
|
|
ax.axis('off') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
col1, col2 = st.columns(2) |
|
|
|
|
|
with col1: |
|
|
st.subheader("3D-тетраэдр") |
|
|
st.plotly_chart(fig_3d) |
|
|
|
|
|
with col2: |
|
|
st.subheader("Развёртка тетраэдра") |
|
|
st.pyplot(fig_2d) |