Map a point within a triangle from low dimensions to high

The work I have been doing recently is to explore a mapping from a low dimensional space(10d) to a high dimensional space(160d). Although is not a particularly common problem is something that requires a little thinking.

The obvious solution is to measure the distance, from the point to the three, triangle points. This of course is difficult to rationalise to a ratio that sums to 1.


This problem becomes more obvious when a point lies on one of the points on the triangle. For example, this could result in a distance of [0, 50 50]. This distance means that if you project this using this information even if normalised, the point will not lie on the triangle coordinate in the higher dimensional space.

To be able to map between two triangles accurately the best solution is to utilise Barycentric coordinates. This turns the 3 points of the triangle into three vertices. Using this information you are then able to solve to find the ratios to accurately map between the two spaces.


Therefore to generate a new point in 2D, you have:

To get to this point we need to solve the equations for lambda, resulting in n equations for each of the different dimensions.

This can be solved relatively easily using a linear solver.

So now using this information it is easy to project the point from one triangle to the other. We have provided a Matlab solution to be able to easily map using two triangles.

1 A = []; 2 B = [] ; 3 for i=1:size(ntA,1) 4 line = [(ntA(i,1) - ntA(i,3)) (ntA(i,2) - ntA(i,3)) ]; 5 B = [ B ; (ntA(i,3) - Qn(i)) ] ; 6 A = [A ; line]; 7 end 8 Lambda = linsolve(A,-B);

Therefore you can map the new point using

1 Lambda = [Lambda ; ( 1 - Lambda(1) - Lambda(2) )]; 2 3 pB = sum(tB .* repmat(Lambda',[],size(tB,1)),2);


You can view a complete version of this code, as well as a test case Files.

See: Files –>  Barycentric Coordinates

Equations thanks to the ever wonderful Wikipedia

Saturday, April 21, 2012 3:19:00 PM Categories: Articles HowTo
Stuart James