在 Mathematica 中将点从 4d 空间投影到 3d 空间
假设我们有一组点,其限制是每个点的所有坐标都是非负的,并且坐标之和等于 1。这限制点位于 3 维单纯形中,因此尝试映射是有意义的它回到 3 维空间以进行可视化。
我正在寻找的地图将采用极值点 (1,0,0,0),(0,1,0,0),(0,0,1,0) 和 (0,0,0,1)到“位置良好”的正四面体的顶点。特别地,四面体的中心位于原点,一个顶点位于 z 轴上,一个面平行于 x,y 平面,一条边平行于 x 轴。
下面的代码对 3 维中的点执行类似的操作,但如何将其扩展到 4 似乎并不明显。基本上,我正在寻找 4 维函数 tosimplex 的等效项(它将 4 维变成 3 维),并且它是逆的fromsimplex
A = Sqrt[2/3] {Cos[#], Sin[#], Sqrt[1/2]} & /@ Table[Pi/2 + 2 Pi/3 + 2 k Pi/3, {k, 0, 2}] // Transpose; B = Inverse[A]; tosimplex[{x_, y_, z_}] := Most[A.{x, y, z}]; fromsimplex[{u_, v_}] := B.{u, v, Sqrt[1/3]}; (* checks *) extreme = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; Graphics[Polygon[tosimplex /@ extreme]] fromsimplex[tosimplex[#]] == # & /@ extreme
答案:
用矩阵直接重新表述 deinst 的答案给出以下结果。 (1/sqrt[4] 出现为第四个坐标,因为它是到单纯形中心的距离)
A = Transpose[{{-(1/2), -(1/(2 Sqrt[3])), -(1/(2 Sqrt[6])), 1/Sqrt[4]}, {1/2, -(1/(2 Sqrt[3])), -(1/(2 Sqrt[6])), 1/Sqrt[4]}, {0, -(1/(2 Sqrt[3])) + Sqrt[3]/2, -(1/(2 Sqrt[6])), 1/Sqrt[4]}, {0, 0, Sqrt[2/3] - 1/(2 Sqrt[6]), 1/Sqrt[4]}}]; B = Inverse[A]; tosimplex[{x_, y_, z_, w_}] := Most[A.{x, y, z, w}]; fromsimplex[{t_, u_, v_}] := B.{t, u, v, 1/Sqrt[4]}; (* Checks *) extreme = Table[Array[Boole[# == i] &, 4], {i, 1, 4}]; Graphics3D[Sphere[tosimplex[#], .1] & /@ extreme] fromsimplex[tosimplex[#]] == # & /@ extreme
Suppose we have a set of points with the restriction that for each point all coordinates are non-negative, and the sum of coordinates is equal to 1. This restricts points to lie in a 3-dimensional simplex so it makes sense to try to map it back into 3 dimensional space for visualization.
The map I'm looking for would take extreme points (1,0,0,0),(0,1,0,0),(0,0,1,0) and (0,0,0,1) to vertices of "nicely positioned" regular tetrahedron. In particular, center of the tetrahedron will be at the origin, one vertex would lie on the z axis, one face to parallel to x,y plane, and one edge to be parallel to x axis.
Here's code that does similar thing for points in 3 dimensions, but it doesn't seem obvious how to extend it to 4. Basically I'm looking for 4-d equivalents of functions tosimplex (which takes 4 dimensions into 3) and it's inverse fromsimplex
A = Sqrt[2/3] {Cos[#], Sin[#], Sqrt[1/2]} & /@ Table[Pi/2 + 2 Pi/3 + 2 k Pi/3, {k, 0, 2}] // Transpose; B = Inverse[A]; tosimplex[{x_, y_, z_}] := Most[A.{x, y, z}]; fromsimplex[{u_, v_}] := B.{u, v, Sqrt[1/3]}; (* checks *) extreme = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; Graphics[Polygon[tosimplex /@ extreme]] fromsimplex[tosimplex[#]] == # & /@ extreme
Answer:
straightforward reformulation of deinst's answer in terms of matrices gives following. (1/sqrt[4] comes up as 4th coordinate because it's the distance to simplex center)
A = Transpose[{{-(1/2), -(1/(2 Sqrt[3])), -(1/(2 Sqrt[6])), 1/Sqrt[4]}, {1/2, -(1/(2 Sqrt[3])), -(1/(2 Sqrt[6])), 1/Sqrt[4]}, {0, -(1/(2 Sqrt[3])) + Sqrt[3]/2, -(1/(2 Sqrt[6])), 1/Sqrt[4]}, {0, 0, Sqrt[2/3] - 1/(2 Sqrt[6]), 1/Sqrt[4]}}]; B = Inverse[A]; tosimplex[{x_, y_, z_, w_}] := Most[A.{x, y, z, w}]; fromsimplex[{t_, u_, v_}] := B.{t, u, v, 1/Sqrt[4]}; (* Checks *) extreme = Table[Array[Boole[# == i] &, 4], {i, 1, 4}]; Graphics3D[Sphere[tosimplex[#], .1] & /@ extreme] fromsimplex[tosimplex[#]] == # & /@ extreme
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你想要
这是一个线性变换,所以你变换
编辑 你想要中心在原点 - 只需减去四个点的平均值。对不起
You want
And it is a linear transformation so you transform
Edit You want the center at the origin -- just subtract the average of the four points. Sorry
一种可能性:
\vec{v}_i
。x = (x_1 .. x_4)
形成向量和\Sum_i x_i*\vec{v}_i
。当然,这种映射一般来说并不是唯一的,但您的条件是 x_i 的总和为 1,这会限制一些事情。
One possibility:
\vec{v}_i
from the center of the tetrahedron toward each vertex.x = (x_1 .. x_4)
form the vector sum\Sum_i x_i*\vec{v}_i
.Of course this mapping is not unique in general, but you condition that the
x_i
's sum to 1 constrains things.