% Find the vertex of a triangle at the given distances, from the given
% other vertices, such that the cross product from the new vertex to the
% first vertex, with the vector from the new vertex to the second vertex
% is pointing in +Z
function c = triVertex(a,ac,b,bc)
dv = b-a      % vector from a to b
d = norm(dv) % dist between a and b
d2 = d*d;
dv = dv / d; % convert vector a->b to normalized direction from a to b

% dist along (dx,dy) to the line connecting the two points on both
%    circle radius ac about a and
%    circle radius ab about b
da = (ac*ac - bc*bc + d2)/(2*d)

% perp distance from midpoint between a and b to intersection
dp = sqrt(ac*ac - da*da)

cv = da * dv  % vector from a to mid-point between solution points
pv = dp * [-dv(2),dv(1)] % vector from a+(cx,cy) to solution points

c = cv+pv  % c-a

% we want the solution where cross(b-a,c-a)>0
cz = dv(1)*cv(2) - dv(2)*cv(1) % cross product, in Z direction
if (cz > 0)
  c = c + a
else
  % re-compute position c, using -pv, not +pv as initial computation for c
  c = a + cv - pv
end
end

