# Triangular Metric

Given a point inside a unit equilateral triangle, how does one rotate it across the triangle perimeter? I.e. the triangle outline serving the same purpose as circle's circumference. That is actually a question of practical importance - it is required for a seamless hue-shift inside spaces like CIE XYZ.

As I understand some distorted versions of sin and cos functions are required, so that they give points on a unit equilateral triangle, instead of a unit circle. But sin and cos themselves were inferred from the euclidean space metric X^2 + Y^2 = R^2. Obviously triangular sin and cos define non-euclidean space. But what is it's metric?

I've found an article speaking about this thing https://ncatlab.org/nlab/show/p-norm but I don't understand 95% of the terminology they use. They also refer to metric as "norm" for some reason. Guess "norm" is some specific subtype of metric. And they don't tell how to generate it from triangle either.

• I believe you would want to use barycentric coordinates. gamedev.stackexchange.com/questions/23743/… Jul 28, 2019 at 21:39
• I'm unsure how barycentric coordinates would help with hue rotation in say CIE XYZ triangle. I want to simulate the usual HSV, but without the inherent HSV blending problems. Jul 28, 2019 at 22:17

A simple linear interpolation should be enough here, since the sides are straight. For just one side, the equation is

$$p(t) = \vec a + (\vec b - \vec a)\cdot t$$

Where $$\t\$$ is a value between 0 and 1, $$\\vec a \$$ is one of the vertices of the side and $$\\vec b\$$ is the other. For $$\t = 0\$$ the returned position is $$\\vec a\$$, for $$\t = 1\$$ it's $$\\vec b\$$. Animation to make it clearer: Now if you divide the $$\[0,1]\$$ interval into three equal parts, the first for the first side, second for the second part and the third for the third one, then you can create a function, that returns the positions of an equilateral triangle. If we have a triangle $$\ABC\$$ and the vectors pointing to the three vectors are $$\\vec a\$$, $$\\vec b\$$ and $$\\vec c\$$ respectively, then this function is

$$p(t) = \begin{cases} \vec a + (\vec b - \vec a) \cdot (t \cdot 3) &\quad\text{if } 0 < t < \frac{1}{3}\\ \vec b + (\vec c - \vec b) \cdot (t \cdot 3 - 1) &\quad\text{if } \frac{1}{3} < t < \frac{2}{3}\\ \vec c + (\vec a - \vec c) \cdot (t \cdot 3 - 2) &\quad\text{if } \frac{2}{3} < t < 1\\ \end{cases}$$

• Thanks! It works! I was trying to start from normal sin/cos and then project arcs to the sides. But it gave some weird non-linear results Jul 29, 2019 at 10:09
• @SmugLispWeenie if this answer solved your question, please mark it as correct Jul 29, 2019 at 20:21