你知道三维空间,那你见过四维嘛?Python实现四维空间!
作为三维的生物,我们的眼睛只能看到这个世界的二维投影,即这个世界的影子,三维的立体感,是在大脑中根据经验想象出来的。而四维的生物,便能看到他们世界的三维投影。例如,他们可以同时看到三维空间中正方体的所有六面,以及正方体中所有点,就像我们可以同时看到二维平面上正方形的四条边以及正方形内部所有点一样。
想象一下,一个三维的物体在我们眼前移动,投影虽然在变,我们尚可以想象他不变的体型,而假如一个不规则四维生物来到我们的世界,在你的眼前移动,由于我们只能看到二维的投影,所以你将看到一个形状一直变化,想象不出体型的怪物。在此,降维打击就很好理解了,
<bi style="box-sizing: border-box; display: block;">你完全看不清对方,而对方可以不碰到你的皮肤直接取你的心脏。</bi>
Python学习交流群:1004391443,这里有资源共享,技术解答,还有小编从最基础的Python资料到项目实战的学习资料都有整理,希望能帮助你更了解python,学习python。
下面我们用 Python-matplotlib 来想象一下思维空间到底啥样?
我们无法真正看到三维空间,更无法看到四维空间,要‘看到’四维空间,只能另辟蹊径了。
<bi style="box-sizing: border-box; display: block;">用类推法,插上想象的翅膀,走进四维世界。</bi>
一维空间是这样的:
<pre spellcheck="false" style="box-sizing: border-box; margin: 5px 0px; padding: 5px 10px; border: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-weight: 400; font-stretch: inherit; font-size: 16px; line-height: inherit; font-family: inherit; vertical-align: baseline; cursor: text; counter-reset: list-1 0 list-2 0 list-3 0 list-4 0 list-5 0 list-6 0 list-7 0 list-8 0 list-9 0; background-color: rgb(240, 240, 240); border-radius: 3px; white-space: pre-wrap; color: rgb(34, 34, 34); letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.gca(projection='3d')
a1, a2, a3 = [0, 4], [0, 4], [0, 4]
figure = ax.plot(a1, a2, a3, c= 'r', linestyle="-")
for i in range(len(a1)):
ax.text(a1[i],a2[i],a3[i],i,color='r')
plt.xticks([])
plt.yticks([])
plt.axis('off')
plt.show()
</pre>
<input class="pgc-img-caption-ipt" placeholder="图片描述(最多50字)" value="" style="box-sizing: border-box; outline: 0px; color: rgb(102, 102, 102); position: absolute; left: 187.5px; transform: translateX(-50%); padding: 6px 7px; max-width: 100%; width: 375px; text-align: center; cursor: text; font-size: 12px; line-height: 1.5; background-color: rgb(255, 255, 255); background-image: none; border: 0px solid rgb(217, 217, 217); border-radius: 4px; transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1) 0s;"></tt-image>
他是一条被两端的两个点包围的线段。
二维空间是这样的:
<pre spellcheck="false" style="box-sizing: border-box; margin: 5px 0px; padding: 5px 10px; border: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-weight: 400; font-stretch: inherit; font-size: 16px; line-height: inherit; font-family: inherit; vertical-align: baseline; cursor: text; counter-reset: list-1 0 list-2 0 list-3 0 list-4 0 list-5 0 list-6 0 list-7 0 list-8 0 list-9 0; background-color: rgb(240, 240, 240); border-radius: 3px; white-space: pre-wrap; color: rgb(34, 34, 34); letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.gca(projection='3d')
h1, h2, h3 = [4, 4], [0, 4], [4, 0]
i1, i2, i3 = [4, 0], [0, 4], [4, 4]
j1, j2, j3 = [4, 0], [4, 4], [0, 4]
figure = ax.plot(h1, h2, h3, c= 'silver')
figure = ax.plot(i1, i2, i3, c= 'silver')
figure = ax.plot(j1, j2, j3, c= 'silver')
plt.xticks([])
plt.yticks([])
plt.axis('off')
plt.show()
</pre>
<input class="pgc-img-caption-ipt" placeholder="图片描述(最多50字)" value="" style="box-sizing: border-box; outline: 0px; color: rgb(102, 102, 102); position: absolute; left: 187.5px; transform: translateX(-50%); padding: 6px 7px; max-width: 100%; width: 375px; text-align: center; cursor: text; font-size: 12px; line-height: 1.5; background-color: rgb(255, 255, 255); background-image: none; border: 0px solid rgb(217, 217, 217); border-radius: 4px; transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1) 0s;"></tt-image>
他是一个被三条线段包围的三角形平面。
三维空间是这样的:
<pre spellcheck="false" style="box-sizing: border-box; margin: 5px 0px; padding: 5px 10px; border: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-weight: 400; font-stretch: inherit; font-size: 16px; line-height: inherit; font-family: inherit; vertical-align: baseline; cursor: text; counter-reset: list-1 0 list-2 0 list-3 0 list-4 0 list-5 0 list-6 0 list-7 0 list-8 0 list-9 0; background-color: rgb(240, 240, 240); border-radius: 3px; white-space: pre-wrap; color: rgb(34, 34, 34); letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.gca(projection='3d')
b1, b2, b3 = [0, 4], [0, 4], [0, 0]
c1, c2, c3 = [0, 0], [0, 4], [0, 4]
d1, d2, d3 = [0, 4], [0, 0], [0, 4]
h1, h2, h3 = [4, 4], [0, 4], [4, 0]
i1, i2, i3 = [4, 0], [0, 4], [4, 4]
j1, j2, j3 = [4, 0], [4, 4], [0, 4]
figure = ax.plot(b1, b2, b3, c= 'r')
figure = ax.plot(c1, c2, c3, c= 'k')
figure = ax.plot(d1, d2, d3, c= 'b')
figure = ax.plot(h1, h2, h3, c= 'tan')
figure = ax.plot(i1, i2, i3, c= 'pink')
figure = ax.plot(j1, j2, j3, c= 'gold', linestyle="--")
plt.xticks([])
plt.yticks([])
plt.axis('off')
plt.show()
</pre>
<input class="pgc-img-caption-ipt" placeholder="图片描述(最多50字)" value="" style="box-sizing: border-box; outline: 0px; color: rgb(102, 102, 102); position: absolute; left: 187.5px; transform: translateX(-50%); padding: 6px 7px; max-width: 100%; width: 375px; text-align: center; cursor: text; font-size: 12px; line-height: 1.5; background-color: rgb(255, 255, 255); background-image: none; border: 0px solid rgb(217, 217, 217); border-radius: 4px; transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1) 0s;"></tt-image>
他是一个被四个三角形平面包围的三维四面体。其中虚线代表我们看不见的那条菱,但是通过旋转,看不见的那条菱,我们也可以看到。
<tt-image data-tteditor-tag="tteditorTag" contenteditable="false" class="syl1557646184035 ql-align-center" data-render-status="finished" data-syl-blot="image" style="box-sizing: border-box; cursor: text; text-align: left; color: rgb(34, 34, 34); font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; display: block;"> image<input class="pgc-img-caption-ipt" placeholder="图片描述(最多50字)" value="" style="box-sizing: border-box; outline: 0px; color: rgb(102, 102, 102); position: absolute; left: 187.5px; transform: translateX(-50%); padding: 6px 7px; max-width: 100%; width: 375px; text-align: center; cursor: text; font-size: 12px; line-height: 1.5; background-color: rgb(255, 255, 255); background-image: none; border: 0px solid rgb(217, 217, 217); border-radius: 4px; transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1) 0s;"></tt-image>
直观地看,他其实就是一个四边形中间交叉两条对角线,一个三维的二维投影。
四维空间是这样的:
<pre spellcheck="false" style="box-sizing: border-box; margin: 5px 0px; padding: 5px 10px; border: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-weight: 400; font-stretch: inherit; font-size: 16px; line-height: inherit; font-family: inherit; vertical-align: baseline; cursor: text; counter-reset: list-1 0 list-2 0 list-3 0 list-4 0 list-5 0 list-6 0 list-7 0 list-8 0 list-9 0; background-color: rgb(240, 240, 240); border-radius: 3px; white-space: pre-wrap; color: rgb(34, 34, 34); letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.gca(projection='3d')
a1, a2, a3 = [0, 4], [0, 4], [0, 4]
b1, b2, b3 = [0, 4], [0, 4], [0, 0]
c1, c2, c3 = [0, 0], [0, 4], [0, 4]
d1, d2, d3 = [0, 4], [0, 0], [0, 4]
e1, e2, e3 = [4, 4], [4, 4], [4, 0]
f1, f2, f3 = [4, 0], [4, 4], [4, 4]
g1, g2, g3 = [4, 4], [4, 0], [4, 4]
h1, h2, h3 = [4, 4], [0, 4], [4, 0]
i1, i2, i3 = [4, 0], [0, 4], [4, 4]
j1, j2, j3 = [4, 0], [4, 4], [0, 4]
figure = ax.plot(a1, a2, a3, c= 'silver', linestyle="--")
figure = ax.plot(b1, b2, b3, c= 'silver')
figure = ax.plot(c1, c2, c3, c= 'silver')
figure = ax.plot(d1, d2, d3, c= 'silver')
figure = ax.plot(e1, e2, e3, c= 'silver')
figure = ax.plot(f1, f2, f3, c= 'silver')
figure = ax.plot(g1, g2, g3, c= 'silver')
figure = ax.plot(h1, h2, h3, c= 'silver')
figure = ax.plot(i1, i2, i3, c= 'silver')
figure = ax.plot(j1, j2, j3, c= 'silver')
for i in range(len(a1)):
ax.text(a1[i],a2[i],a3[i],i,color='r')
plt.xticks([])
plt.yticks([])
plt.axis('off')
plt.show()
</pre>
<input class="pgc-img-caption-ipt" placeholder="图片描述(最多50字)" value="" style="box-sizing: border-box; outline: 0px; color: rgb(102, 102, 102); position: absolute; left: 187.5px; transform: translateX(-50%); padding: 6px 7px; max-width: 100%; width: 375px; text-align: center; cursor: text; font-size: 12px; line-height: 1.5; background-color: rgb(255, 255, 255); background-image: none; border: 0px solid rgb(217, 217, 217); border-radius: 4px; transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1) 0s;"></tt-image>
在此,已经超出了我们的经验范围,打开脑洞,充分想象,他是一个被五个三维四面体包围的四维超四面体。其中的虚线代表我们无论如何旋转,都看不见,而四维生物旋转之后能看见的那条菱。
<tt-image data-tteditor-tag="tteditorTag" contenteditable="false" class="syl1557646184055 ql-align-center" data-render-status="finished" data-syl-blot="image" style="box-sizing: border-box; cursor: text; text-align: left; color: rgb(34, 34, 34); font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; display: block;"> image <input class="pgc-img-caption-ipt" placeholder="图片描述(最多50字)" value="" style="box-sizing: border-box; outline: 0px; color: rgb(102, 102, 102); position: absolute; left: 187.5px; transform: translateX(-50%); padding: 6px 7px; max-width: 100%; width: 375px; text-align: center; cursor: text; font-size: 12px; line-height: 1.5; background-color: rgb(255, 255, 255); background-image: none; border: 0px solid rgb(217, 217, 217); border-radius: 4px; transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1) 0s;"></tt-image> <tt-image data-tteditor-tag="tteditorTag" contenteditable="false" class="syl1557646184061 ql-align-center" data-render-status="finished" data-syl-blot="image" style="box-sizing: border-box; cursor: text; text-align: left; color: rgb(34, 34, 34); font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; display: block;"> image<input class="pgc-img-caption-ipt" placeholder="图片描述(最多50字)" value="" style="box-sizing: border-box; outline: 0px; color: rgb(102, 102, 102); position: absolute; left: 187.5px; transform: translateX(-50%); padding: 6px 7px; max-width: 100%; width: 375px; text-align: center; cursor: text; font-size: 12px; line-height: 1.5; background-color: rgb(255, 255, 255); background-image: none; border: 0px solid rgb(217, 217, 217); border-radius: 4px; transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1) 0s;"></tt-image>
想象地看,他其实是一个六面体,一个四维的三维投影。