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
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With