Show that there is an isometry $f:\mathbb{R}^n\to \mathbb{R}^n$ such that $f|_X$ is $g$ where $g :X \to X$ is isometric on subset $X$. Here's the problem.

If $X \subset \mathbb{R}^n$ is any subset and $g:X\to X$ is an isometric map, show that there is a unique isometry $f:\mathbb{R}^n\to \mathbb{R}^n$ such that $f|_X$ is $g$.

I wrote my answer as follows.
Since $g$ is an isometry, $g(x)=Ax+a$ for some $A \in \text{O}(n)$ and some $a \in \mathbb{R}^n$.
Define $f: \mathbb{R}^n\to \mathbb{R}^n$ s.t $f(y)=Ay+a$ for all $y \in \mathbb{R}^n$.
Then, it is clear to see that $f$ is an isometry because $A \in \text{O}(n)$ and $a \in \mathbb{R}^n$.
Also, clearly $f|_X=g$.
Is this the right approach? I have some doubts because I am not sure if I could let $g(x)=Ax+a$ (which we usually do when $g : \mathbb{R}^n\to \mathbb{R}^n$).
Theorems that might be useful:

*

*An isometry $f : \mathbb{R}^n\to \mathbb{R}^n$ is uniquely determined by the images $fa_0,fa_1,...,fa_n$ of a set $a_0,a_1,...,a_n$ of $(n+1)$ independent points.


*If $\{a_0,a_1,...,a_n\}$ and $\{b_0,b_1,...,b_n\}$ are two sets of independent points in $\mathbb{R}^n$, then there is an isometry $f:\mathbb{R}^n\to \mathbb{R}^n$ with $fa_i=b_i$ for $0 \leq i \leq n$
 A: As was noted in the comments, the extending isometry will not be unique if the subset $X$ is contained in a hyperplane, because an isometry defined on a hyperplane can be extended in many different ways to the whole $\mathbb{R}^n$.
So, assuming the subset $X$ is not contained in any hyperplane, we can choose $(n+1)$ independent points in $X$. We'll do it explicitly. Take any collection of $n$ points in $X$ and consider the hyperplane $H$ they span (if they don't span a hyperplane, add more independent points until they do, which is possible due to the hypothesis). Then choose $n$ independent points $x_1,\dots, x_n$ in $H$. Since $X$ isn't contained in $H$, there is at least one $x\in X$ which doesn't belong to $H$, so that $x_1,\dots, x_n, x$ are $(n+1)$ independent points in $X$.
Now, there's obviously only one isometry $f: \mathbb{R}^n \rightarrow \mathbb{R}^n$ with $f(x_1) = g(x_1)$, $\dots$, $f(x_n) = g(x_n)$, $f(x) = g(x)$. This isometry also coincides with $g$ at any other point in $X$, because $g$ is also completely determined by how it transforms the $(n+1)$ chosen points.
