Thread: Maths function

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    36

    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

  2. #2
    Never Exist Hermitsky's Avatar
    Join Date
    Jul 2004
    Posts
    149
    en ... .... .....
    i think there is not ........

    blow me ... ...

  3. #3
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    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
    Last edited by Sang-drax; 09-24-2004 at 09:27 AM.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  4. #4
    Registered User
    Join Date
    May 2004
    Posts
    36
    Thanks for that...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM