在 Mathematica 中将点从 4d 空间投影到 3d 空间

发布于 2024-09-15 07:27:56 字数 1367 浏览 4 评论 0原文

假设我们有一组点,其限制是每个点的所有坐标都是非负的,并且坐标之和等于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜还是长夜 2024-09-22 07:27:56

你想要

   (1,0,0,0) -> (0,0,0)
   (0,1,0,0) -> (1,0,0)
   (0,0,1,0) -> (1/2,sqrt(3)/2,0)
   (0,0,0,1) -> (1/2,sqrt(3)/6,sqrt(6)/3))

这是一个线性变换,所以你变换

   (x,y,z,w) - > (y + 1/2 * (z + w), sqrt(3) * (z / 2 + w / 6), sqrt(6) * w / 3)

编辑 你想要中心在原点 - 只需减去四个点的平均值。对不起

(1/2, sqrt(3)/6, sqrt(6) / 12)

You want

   (1,0,0,0) -> (0,0,0)
   (0,1,0,0) -> (1,0,0)
   (0,0,1,0) -> (1/2,sqrt(3)/2,0)
   (0,0,0,1) -> (1/2,sqrt(3)/6,sqrt(6)/3))

And it is a linear transformation so you transform

   (x,y,z,w) - > (y + 1/2 * (z + w), sqrt(3) * (z / 2 + w / 6), sqrt(6) * w / 3)

Edit You want the center at the origin -- just subtract the average of the four points. Sorry

(1/2, sqrt(3)/6, sqrt(6) / 12)
溇涏 2024-09-22 07:27:56

一种可能性:

  1. 生成四个(非正交)3 向量,从四面体中心到每个顶点的 \vec{v}_i
  2. 对于每四个位置 x = (x_1 .. x_4) 形成向量和 \Sum_i x_i*\vec{v}_i

当然,这种映射一般来说并不是唯一的,但您的条件是 x_i 的总和为 1,这会限制一些事情。

One possibility:

  1. Generate four (non-orthoganal) 3-vectors, \vec{v}_i from the center of the tetrahedron toward each vertex.
  2. For each four position 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文