How to define a (linear, invertible) mapping from a square to a triangle

169 Views Asked by At

This problem has come up when analyzing one type of HSV color selector:

Note: h,s,v are in 0...1 range.

For the given hue (i.e. red) on the three vertices of the triangle we have:

  • W: white, when s=0, v=1;
  • R: red, when s=1, v=1;
  • B: black otherwise.

and we have three sides: going from one vertex to another we see a linear change of either s or v. We can observe a similar fact on the square SxV=[0,1]x[0,1] below. The B vertex is however "special" as it is the projection of the fourth side v=0 of this square.

(S on the horizontal axis, V on the vertical axis upwards)

it looks like the mapping (s,v) --> (x,y) on triangle, it has been defined as:

(x, y, ...) = f(s, v) = (1 - v) * B + v * ((1 - s) * W + s * R)

and again all the points (s, 0) go into the same vertex B.

But B is the only non-invertible point.

For any line (s, vk) where vk is a constant value in (0,1], there is a corresponding line in the triangle, parallel to the WR segment.

How to invert this mapping, i.e. compute (s, v) given (x, y)?

1

There are 1 best solutions below

0
On BEST ANSWER

There is no linear mapping between a triangle and a square, but the map described is reminiscent of blowing up the origin in the plane. There we send $(s, v) \mapsto (sv, v) = (x, y)$ and the inverse is $(x, y) \mapsto (x/y, y) = (s, v)$.

The image of the unit square $0 \leq s \leq 1$ and $0 \leq v \leq 1$ is the right isosceles triangle $0 \leq y \leq 1$ and $0 \leq x \leq y$, which can be mapped to an equilateral triangle by a linear transformation.

Blowing up a point of color space