# Maths function

• 09-24-2004
ozzy34
Maths function
Hi guys,

I have two points in space at: x,y,z & x1, y1,z1 and need to know how far apart they are from each other.

I know I could work this out manually but I was wondering if there is an inbuilt function in c++ that will do this for me.

Any ideas? I've tried to look in the doc but being fairly new not had any luck.

Thanks
• 09-24-2004
Hermitsky
en ... .... .....
i think there is not ........
• 09-24-2004
Sang-drax
No, there's no built-in function for this.

If you stretch it, you could use valarrays:
Code:

```valarray<double> v  =  ... (x,y,z) valarray<double> u  = ... (x1,x2,x3) //Distance vector between points valarray v0 = v-u; //Raise each element to the power of two, add the elements //and take the square root from the result double distance = sqrt( pow(v0,2).sum() );```
Even though abs() is overloaded for valarraysy, one cannot do:
Code:

`double distance = abs(v0); //abs returns a valarray`
• 09-24-2004
ozzy34
Thanks for that...