Perhaps this should be cross-posted on Math Stackexchange, but it came up in the context of some research mathematics (quaternion orders, etc.) In this context, I have three angles $\alpha, \beta, \gamma$ of a triangle, and three cosines $a = \cos(\alpha)$ and $b = \cos(\beta)$ and $c = \cos(\gamma)$. Out of some magic popped the following quantity: $$D = a^2 + b^2 + c^2 + 2 abc - 1.$$ Well, ok, it's not magic, it's related to the discriminant of something. But who doesn't like such a cubic equation?
Lo and behold, wikipedia tells me there's a family of "conditional trig identities," among which one finds $$\cos^2(\alpha) + \cos^2(\beta) + \cos^2(\gamma) = 1 - 2 \cos(\alpha) \cos(\beta) \cos(\gamma),$$ IF $\alpha + \beta + \gamma = 180^\circ$. In other words, the identity above is conditional on the angles being those of a Euclidean triangle.
Now my questions...
What's the history of this identity? There's no references in this section of Wikipedia, and just a few odd youtube videos because such identities are useful for contest problems. Does it have a nice name? It's not too far from some ratio-sum identities of Euler (E749 at the Euler Archive), but it doesn't match them either.
Does this identity have a known interpretation in terms of curvature, comparison triangles, etc.? I mean $D = 0$ occurs if the triangle is Euclidean. I suspect this is an "if and only if" and can check whether $D < 0$ and $D > 0$ correspond to hyperbolic/spherical triangles. But does $D$ match something that metric geometry people know?
Does this identity have a direct geometric proof? I've seen proofs of related identities, and one can just hack it out. But is there something nice going on behind the scenes?