首页 > 解决方案 > 为什么八面体和立方体的表面积与体积比之比是一个常数,却没有反映在我的程序中?

问题描述

由于我正在为他们的 SA:V 编码的两个柏拉图立体问题:立方体和八面体,我在发表我的论文时遇到了障碍。

通常,当推导立方体和八面体的 SA:V 比时,它将分别为 6/a 和 (3*sqrt(6))/a。

当您将这些比率作为比率时,您会得到所有尺寸方案的恒定非 1:1 比率,那么,我的输出如何成为 1:1 关系?

输出(点击链接):

比率图:

桌子

用户请求、制表和绘图的所有实例中两种形状的相关代码(忽略二十面体代码): 第一实例:

    elif name_of_polyhedron == 'Octahedron':
        a = d/math.sqrt(2)
        SA_vex_octa = ((2*math.sqrt(3))*a**2)
        V_vex_octa = (((math.sqrt(2))/(3))*a**3)
        ratio_vex_octa = (SA_vex_octa/V_vex_octa)
        print('The surface area of your octahedron is as follows:' +str(SA_vex_octa)+ 'm^2')
        print('The volume of your octahedron is as follows:' +str(V_vex_octa)+ 'm^3')
        print('The surface area to volume ratio of your octahedron is as follows:' 
        +str(ratio_vex_octa))
        print('See how your ratio compares below!')
    elif name_of_polyhedron == 'Icosahedron':
        a = 4*(1/(math.sqrt(10+2*math.sqrt(5))))*((1/2)*d)
        SA_vex_icosa = 5*(a**2)*math.sqrt(3)
        V_vex_icosa = (5/12)*(a**3)*(3+sqrt(5))
        ratio_vex_icosa = SA_vex_icosa/V_vex_icosa
        print('The surface area of your icosahedron is as follows:' +str(SA_vex_icosa)+ 'm^2')
        print('The volume of your icosahedron is as follows:' +str(V_vex_icosa)+ 'm^3')
        print('The surface area to volume ratio of your icosahedron is as follows:' 
        +str(ratio_vex_icosa))
        print('See how your ratio compares below!')
    elif name_of_polyhedron == 'Cube':
        a = d/math.sqrt(3)
        SA_vex_cube = 6*a**2
        V_vex_cube = a**3
        ratio_vex_cube = SA_vex_cube/V_vex_cube
        print('The surface area of your cube is as follows:' +str(SA_vex_cube)+ 'm^2')
        print('The volume of your cube is as follows:' +str(V_vex_cube)+ 'm^3')
        print('The surface area to volume ratio of your cube is as follows:' +str(ratio_vex_cube))
        print('See how your ratio compares below!')

#Second Instance

a_4 = d/math.sqrt(2)
SA_vex_octa = (2*math.sqrt(3))*(a_4)**2
V_vex_octa = ((math.sqrt(2))/(3))*(a_4)**3
ratio_vex_octa = SA_vex_octa/V_vex_octa

a_5 = 4*(1/(math.sqrt(10+2*math.sqrt(5))))*((1/2)*d)
SA_vex_icosa = 5*((a_5)**2)*math.sqrt(3)
V_vex_icosa = (5/12)*((a_5)**3)*(3+math.sqrt(5))
ratio_vex_icosa = SA_vex_icosa/V_vex_icosa

a_6 = d/math.sqrt(3)
SA_vex_cube = 6*(a_6)**2
V_vex_cube = (a_6)**3
ratio_vex_cube = SA_vex_cube/V_vex_cube

#Third Instance

a_3 = (2/math.sqrt(6))*d
a_4 = d/math.sqrt(2)
a_5 = (2/(math.sqrt(10+2*math.sqrt(5))))*d
a_6 = d/math.sqrt(3)
a_7 = (2/(math.sqrt(3)*(1+math.sqrt(5)))*d)
a_8 = ((2/(math.sqrt(10+2*math.sqrt(5))))*d)
a_9 = ((2/(math.sqrt(50+22*math.sqrt(5))))*d)
a_10 = ((3/(math.sqrt(3)*(3+math.sqrt(5))))*d)
a_11 = ((2/(math.sqrt(50+22*math.sqrt(5))))*d)
SA_vex_tetra = (((a_3)**2)*math.sqrt(3))
V_vex_tetra = ((((a_3)**3)/12)*math.sqrt(2))
ratio_vex_tetra = [SA_vex_tetra/V_vex_tetra]
SA_vex_octa = (2*math.sqrt(3))*(a_4)**2
V_vex_octa = ((math.sqrt(2))/(3))*(a_4)**3
ratio_vex_octa = SA_vex_octa/V_vex_octa
SA_vex_icosa = 5*((a_5)**2)*math.sqrt(3)
V_vex_icosa = (5/12)*(a_5)**3*(3+math.sqrt(5))
ratio_vex_icosa = SA_vex_icosa/V_vex_icosa
SA_vex_cube = 6*(a_6)**2
V_vex_cube = (a_6)**3
ratio_vex_cube = SA_vex_cube/V_vex_cube

它们出现的表格/图表:

import matplotlib.pyplot as plt
from tabulate import tabulate
z = [('Tetrahedon',a_2,'Platonic',d,SA_vex_tetra,V_vex_tetra,ratio_vex_tetra),
   ('Octahedron',a_2,'Platonic',d,SA_vex_octa,V_vex_octa,ratio_vex_octa),
   ('Icosahedron',a_2,'Platonic',d,SA_vex_icosa,V_vex_icosa,ratio_vex_icosa),
   ('Cube',a_2,'Platonic',d,SA_vex_cube,V_vex_cube,ratio_vex_cube),
   ('Dodecahedron',a_2,'Platonic',d,SA_vex_dodeca,V_vex_dodeca,ratio_vex_dodeca),
   ('Cuboctahedron',a_2,'Archimedes',d,SA_vex_cubocta,V_vex_cubocta,ratio_vex_cubocta),
   ('Rhombicuboctahedron',a_2,'Archimedes',d,SA_vex_rhocubocta,V_vex_rhocubocta,ratio_vex_X), 
   ('Snub Cube',a_2,'Archimedes',d,SA_vex_scube,V_vex_scube,ratio_vex_scube),
   ('Snub Dodecahedron',a_2,'Archimedes',d,SA_vex_sndodeca,V_vex_sndodeca,ratio_vex_sndodeca),
   ('Rhombicosidodecahedron',a_2,'Archimedes',d,SA_vex_ridodeca,V_vex_ridodeca,ratio_vex_ridodeca),
   ('Truncated Octahedron',a_2,'Archimedes',d,SA_vex_ridodeca,V_vex_ridodeca,ratio_vex_sndodeca),
   ('Deltoidal Icositetrahedron','Catalan',a_2,d,SA_vex_delicotetra,V_vex_delicotetra,ratio_vex_X),
   ('Great Dodecahedron',a_1,'Kepler-Poinsot',d,SA_cav_gdodeca,V_cav_gdodeca,ratio_cav_gdodeca),
   ('Great Icosahedron',a_1,'Kepler-Poinsot',d,SA_cav_gicosa,V_cav_gicosa,ratio_cav_gicosa),
   ('Great-Stellated Dodecahedron',a_1,'Kepler-Poinsot',d,SA_cav_gsdodeca,V_cav_gsdodeca,ratio_X_X),
   ('Small-Stellated Dodecahedron',a_1,'Kepler Poinsot',d,SA_cav_ssdodeca,V_cav_ssdodeca,X),
   ('Stellated Octahedron',a_1,'Da Vinci',d,SA_cav_stocta,V_cav_stocta,ratio_cav_stocta),
   ('Medial Rhombic Triacontahedron',a_1,'A-R',(Wenninger)',d,SA_cav_mrtria,V_cav_mrtria,X),
   ('Dodecadodecahedron',a_1,'A-R (Wenninger)',d,SA_cav_ddodeca,V_cav_ddodeca,ratio_cav_ddodeca),
   ('Medial Triambic Icosahedron',a_1,'A-R', (Wenninger)',d,SA_cav_mticosa,V_cav_mticosa,X),
   ('Small Ditrigonal Icosidodecahedron',a_1,'A-R',(Wenninger)',d,SA_cav_sdicosi,V_cav_sdicosi,X),
   ('Excavated Dodecahedron',a_1,'A-R',(Wenninger)',d,SA_cav_exdodeca,V_cav_exdodeca,X),
   ('Sphere',a_12,a_12,d,SA_sphere,V_sphere,ratio_sphere)]
   table_1 = tabulate(z, headers=['Shape','Type','Subtype','C.D. (m)',
         'SA (m^2)','V(m^3)','SA:V'], tablefmt='fancy_grid') #orgtbl or f or pretty
   print(table_1)

Platonic_Array_Ratios = [ratio_vex_tetra,ratio_vex_octa,
                         ratio_vex_icosa,ratio_vex_cube,
                         ratio_vex_dodeca,ratio_sphere]



plt.title('Surface Area to Volume Ratio of Platonic Polyhedra Against Referential Sphere for 
Given 
Diameter')
plt.barh(['Tetrahedron', 'Octahedron', 
        'Icosahedron', 'Cube', 
        'Dodecahedron', 'Sphere'], Platonic_Array_Ratios)
plt.show()

# Platonic
plt.scatter(d,ratio_vex_tetra,label='Tetrahedron', color='b')
plt.scatter(d,ratio_vex_octa,label='Octahedron', color='g')
plt.scatter(d,ratio_vex_icosa,label='Icosahedron', color='y')
plt.scatter(d,ratio_vex_cube,label='Cube', color='m')
plt.scatter(d,ratio_vex_dodeca,label='Dodecahedron', color='c')

plt.scatter(d,ratio_sphere,label='Referential Sphere', color='r')
plt.axvline(x=d_vertical_slash, color='k')

plt.title('Comparison of SA:V of Platonic polyhedra against Referential Sphere with D(m)')
plt.xlabel('Circumspherical Diameter/Diagonal (m)')
plt.ylabel('Ratio Index')

plt.grid(alpha=.4,linestyle='--')

plt.xscale("log")

plt.legend(loc = 1)
plt.show()

我已经通过手动和在线小部件仔细检查了四次计算......它们都是正确的并且在程序输出的所有计算中都相互匹配,但它仍然是错误的。似乎一个正在覆盖另一个,但在哪里?

注意:此代码中没有错误消息。我也为长代码道歉。在某些情况下,我不得不将所有内容复制并粘贴在一起以实现可重复性或只是为了提供更多的上下文。X 只是格式化的占位符。

标签: pythondebuggingmathgeometryoutput

解决方案


您正在计算“给定直径的柏拉图多面体与参考球体的表面积与体积比” [添加粗体]

因此,在将立方体与八面体进行比较之前,将立方体与立方体直径的球体进行比较,将八面体与八面体直径的球体进行比较。

(我认为这意味着外接球体;我不打算检查内接球体。)

球体的 SA/V 比为 6/d,其中 d 是直径。

边长为 a 的立方体的最大直径为 sqrt(3)a,因此立方体/球体比为 (6/a)/(6/(sqrt(3)a)) = sqrt(3)

边长为 a 的八面体的最大直径为 sqrt(2)a,因此八面体/球比为 (3sqrt(6)/a)/(6/(sqrt(2)a)) = sqrt(3)

因此,由于与球体进行比较,该比率为 1:1。


推荐阅读