---------------------
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
def draw_sports_car():
fig = plt.figure(figsize=(12, 8))
ax = fig.add_subplot(111, projection='3d')
ax.set_title("3D Részletes Sportautó", fontsize=16, pad=20)
# 1. Alváz és alsó test (X, Y, Z koordináták)
chassis_x = np.array([[-1.5, 1.5, 1.5, -1.5, -1.5],
[-1.5, 1.5, 1.5, -1.5, -1.5]])
chassis_y = np.array([[-0.8, -0.8, 0.8, 0.8, -0.8],
[-0.8, -0.8, 0.8, 0.8, -0.8]])
chassis_z = np.array([[0.2, 0.2, 0.2, 0.2, 0.2],
[0.6, 0.6, 0.6, 0.6, 0.6]])
ax.plot_wireframe(chassis_x, chassis_y, chassis_z, color='crimson', linewidth=2)
# 2. Tető és ablakok
roof_x = np.array([[-0.6, 0.8, 0.8, -0.6, -0.6],
[-0.6, 0.8, 0.8, -0.6, -0.6]])
roof_y = np.array([[-0.6, -0.6, 0.6, 0.6, -0.6],
[-0.6, -0.6, 0.6, 0.6, -0.6]])
roof_z = np.array([[0.6, 0.6, 0.6, 0.6, 0.6],
[1.3, 1.3, 1.1, 1.1, 1.3]])
ax.plot_wireframe(roof_x, roof_y, roof_z, color='darkred', linewidth=2)
# Első és hátsó szélvédő összekötése
windshield_x = np.array([[-0.6, -0.6], [0.8, 0.8]])
windshield_y = np.array([[-0.6, 0.6], [-0.6, 0.6]])
windshield_z = np.array([[0.6, 0.6], [0.6, 0.6]])
ax.plot_wireframe(windshield_x, windshield_y, windshield_z, color='darkred', linewidth=2)
# 3. Első és hátsó lökhárító / spoiler
bumper_x = np.array([[-1.5, -1.8, -1.8, -1.5], [-1.5, -1.8, -1.8, -1.5]])
bumper_y = np.array([[-0.6, -0.6, 0.6, 0.6], [-0.6, -0.6, 0.6, 0.6]])
bumper_z = np.array([[0.3, 0.3, 0.3, 0.3], [0.5, 0.5, 0.5, 0.5]])
ax.plot_wireframe(bumper_x, bumper_y, bumper_z, color='lightcoral', linewidth=2)
# Hátsó spoiler
spoiler_x = np.array([[1.5, 1.8, 1.8, 1.5], [1.5, 1.8, 1.8, 1.5]])
spoiler_y = np.array([[-0.8, -0.8, 0.8, 0.8], [-0.8, -0.8, 0.8, 0.8]])
spoiler_z = np.array([[0.6, 0.6, 0.6, 0.6], [0.9, 0.9, 0.9, 0.9]])
ax.plot_wireframe(spoiler_x, spoiler_y, spoiler_z, color='black', linewidth=2)
# 4. Kerekek kirajzolása (Hengerek paraméteres egyenleteivel)
theta = np.linspace(0, 2 * np.pi, 20)
wheel_r = 0.35
wheel_w = 0.2
wheel_centers = [(-1.0, -0.85, 0.3), (1.0, -0.85, 0.3),
(-1.0, 0.85, 0.3), (1.0, 0.85, 0.3)]
for cx, cy, cz in wheel_centers:
x = cx + wheel_r * np.cos(theta)
y = cy + np.zeros_like(theta)
z = cz + wheel_r * np.sin(theta)
ax.plot3D(x, y, z, color='dimgray', linewidth=4)
# Keréktárcsák (felnik)
fenni_x = cx + (wheel_r * 0.5) * np.cos(theta)
fenni_z = cz + (wheel_r * 0.5) * np.sin(theta)
ax.plot3D(fenni_x, y, fenni_z, color='silver', linewidth=2)
# 5. Fényszórók
headlight_x = np.array([[-1.5, -1.6], [-1.5, -1.6]])
headlight_y = np.array([[-0.6, -0.6], [0.6, 0.6]])
headlight_z = np.array([[0.4, 0.4], [0.4, 0.4]])
ax.plot_wireframe(headlight_x, headlight_y, headlight_z, color='gold', linewidth=4)
# 6. Tengelyek beállítása és formázás
ax.set_xlim([-2.0, 2.0])
ax.set_ylim([-2.0, 2.0])
ax.set_zlim([0, 1.5])
ax.set_xlabel('Hosszúság (X)')
ax.set_ylabel('Szélesség (Y)')
ax.set_zlabel('Magasság (Z)')
# Háttérszín és rács beállítások a látványosabb 3D élményért
ax.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
ax.w_yaxis.set_pane_color((0.9, 0.9, 0.9, 1.0))
ax.w_zaxis.set_pane_color((0.95, 0.95, 0.95, 1.0))
plt.show()
if __name__ == "__main__":
draw_sports_car()
------------
https://colab.research.google.com/drive/1WwvRJhJxCHYK_qG3Ybiz4fqpmEkurgEf
--------------------
Nincsenek megjegyzések:
Megjegyzés küldése