function [r,s] = xytors(x,y)

% from (x,y) in equilateral triangle to (r,s) coordinates in standard triangle

lambda2 = (-3 * x - sqrt(3) * y + 2) / 6; % from Wikipedia
lambda3 = (3 * x - sqrt(3) * y + 2) / 6; % from Wikipedia
lambda1 = 1 - lambda2 - lambda3; % from definition

r = -lambda2 + lambda3 - lambda1;
s = -lambda2 - lambda3 + lambda1;

end