Extending the Law of Cosines formula to quadrilaterals (and even polygon?) Let's take a look back at this familiar "Law of cosines":

‎Consider‎ the ‎triangle ‎$\triangle‎‎ ABC$. Let $a = BC, b = AC, c = AB$; $\angle A, \angle B, \angle C$ are the angles of the triangle opposite to side $a, b, c,$ respectively. By the Law of Cosines:
  $$a^{2‎} = b^{2‎} + c^{2‎} - 2bc \cdot \cos \angle A$$

This formula can apply for any triangle.
But what about quadrilaterals? Is there a formula, which shows the relationship between sides and angles, similar to the Law of Cosines? Can we extend the Law of Cosines???
This is the way to approach the formula for quadrilaterals (It's not (really) a proof):

Given the quadrilateral ABCD. Let $a = BC, b = CD, c = AB, d = AD$. Let $E = AB \cap CD$ and $G = AC \cap BD$

Let consider $\triangle ABC$ as a "special quadrilateral" (where $d=0$). Then by the Law of Cosines:
$$a^{2‎} = b^{2‎} + c^{2‎} - 2bc \cdot \cos \angle BEC = b^{2‎} + c^{2‎} - 2bc \cdot \cos \angle BGC$$
(because when $d=0$, $E \equiv G \equiv A \Rightarrow \angle BEC = \angle BGC$)
Notice that when $d=0$ then $CA = CD = CE = b$; $BD = BE = BA = c$. So we can guess the general formula for a quadrilateral will be one of these two formulas:

$$ a^{2‎} + Kd^{2‎} = b^{2‎} + c^{2‎} - 2 \cdot BE \cdot CE \cdot \cos \angle BEC \text{ (1)}$$
$$ a^{2‎} + Kd^{2‎} = b^{2‎} + c^{2‎} - 2 \cdot BD \cdot CA \cdot \cos \angle BGC \text{ (2)}$$

(where $K$ is a constant)
The reason we add $Kd^{2‎}$ is to make the formula homogeneous (since the Law of Cosines is also homogeneous), and when $d=0$, the $Kd^{2‎}$ term is gone. Moreover, from our intuition, if the formula contains $\angle BEC$, then two sides, which multiply to its cosines, have to be $BE$ and $CE$. Otherwise, those two sides will be $BD$ and $CA$ multiplied by $\cos \angle BGC$
To see which one is possibly correct, we can try to apply the formula to a special quadrilateral: square. In a square, $a=b=c=d$, "$BE = CE = \infty$", "$\angle BEC = \infty$", $\angle BGC = 90^{\circ}$. Apply $(1)$ and $(2)$:
$$(1): a^{2‎} + Ka^{2‎} = a^{2‎} + a^{2‎} - \infty$$
$$(2): a^{2‎} + Ka^{2‎} = a^{2‎} + a^{2‎}$$
$(1)$ is definitely wrong. The formula $(2)$ can be true if $K=1$, so let re-written it:
$$a^{2‎} + d^{2‎} = b^{2‎} + c^{2‎} - 2 \cdot BD \cdot CA \cdot \cos \angle BGC$$
To be sure that this formula is correct, let's apply this in another quadrilateral. This time is a rectangle, where $\angle BGC = 60^{\circ}$. We have $a=d, b=c=a\sqrt{3}$, $BD = AC = 2a$. Apply the formula that we've just found, we get:
$$a^{2‎} + a^{2‎} = 3a^{2‎} + 3a^{2‎} - 2 \cdot 4a^{2‎} \cdot \frac{1}{2}$$
And this is true. You can verify it with some other quadrilaterals, and it'll also true. So, our new extended "Law of Cosines" is:

$$a^{2‎} + d^{2‎} = b^{2‎} + c^{2‎} - 2 \cdot BD \cdot CA \cdot \cos \angle BGC$$

So that seems fine. But

Is there a proof of the formula above?

Now, my main question (and my main focus) is:

Can we extend the formula (find a general formula) for polygons with n sides?

This question is what I'm looking for (This isn't a homework question). I'm really curious about this. If you have an answer (or just an idea) to approach, please provide it. 
Thank you a lot and have a nice day :D
 A: In quadrilateral $ABCD$, in addition to $a = BC$, $b = CD$, $c = AB$, $d = AD$,
also set:
$$
AG=e,\quad CG=f,\quad BG=g,\quad DG=h,\quad \angle BGC=\alpha,
$$
where $G$ is the intersection point of diagonals $AC$ and $BD$.
By the cosine law we get then:
$$
\begin{align}
a^2 &=f^2+g^2-2fg\cos\alpha \\
d^2 &=e^2+h^2-2eh\cos\alpha \\
b^2 &=f^2+h^2+2fh\cos\alpha \\
c^2 &=e^2+g^2+2eg\cos\alpha \\
\end{align}
$$
and from that we obtain:
$$
b^2+c^2-a^2-d^2 = 2(fh+eg+fg+eh)\cos\alpha=2(e+f)(g+h)\cos\alpha,
$$
which is precisely your formula.
A: Let $\vec{BC}=\vec{a},$ $\vec{CD}=\vec{b},$ $\vec{DA}=\vec{d}$ and $\vec{AB}=\vec{c}.$
Thus, since $$\vec{a}+\vec{c}=-\vec{b}-\vec{d},$$ we obtain: $$(\vec{a}+\vec{c})^2=(\vec{b}+\vec{d})^2,$$ which gives
$$\vec{a}\vec{c}-\vec{b}\vec{d}=\frac{1}{2}(b^2+d^2-a^2-c^2).$$
In another hand, $$BD\cdot AC\cos\measuredangle BGC=\vec{DB}\cdot\vec{AC}=(\vec{c}+\vec{d})(\vec{c}+\vec{a})=$$
$$=c^2+\vec{a}\vec{c}+\vec{d}(\vec{a}+\vec{c})=c^2+\vec{a}\vec{c}-\vec{d}(\vec{b}+\vec{d})=c^2-d^2+\vec{a}\vec{c}-\vec{b}\vec{d}=$$
$$=c^2-d^2+\frac{1}{2}(b^2+d^2-a^2-c^2)=\frac{1}{2}(b^2-d^2+c^2-a^2)$$ and we are done!
