If $X=(1,0,0)$ , $Y=(0,1,0)$ and $Z=(0,0,1)$ (the standard basis) then given two points

$\displaystyle p = Xp_1 + Yp_2 + Zp_3$

and

$\displaystyle q = Xq_1 + Yq_2 + Zq_3$

So in standard coordinates $p=(p_1 , p_2, p_3)$ and $q=(q_1 , q_2, q_3)$

The distance between $p$ and $q$ is

$\displaystyle d(p,q) = \sqrt{(q_1 - p_1)^2 + (q_2 - p_2)^2 + (q_3 - p_3)^2 }$

And for larger dimensions, given the standard basis $\beta = \{v_1 \dots v_n\} \subset \mathbb{R}^n$

$\displaystyle p = \sum_{i=1}^{n}p_{i} v_{i}$

$\displaystyle q = \sum_{i=1}^{n}q_{i} v_{i}$

$\displaystyle d(p,q) = \sqrt{\sum_{i=1}^{n}(q_{i}-p_{i})^{2}}$

If $\beta=\{X,Y,Z\}$ is not the standard basis, then you would need to perform a change of basis to the standard basis.

Let

$\displaystyle p_{\beta} = Xp_1 + Yp_2 + Zp_3$

then a change of basis can be performed by the multiplication (where $X,Y,Z$ are columns of the matrix)

$(X \; Y \; Z)\left(\begin{matrix}p_1\\

p_2\\

p_3\end{matrix}\right)=p$

$p$ will be a coordinate vector with respect to the standard basis. Do the same with $q$ and apply $d(p,q)$ as written above.