Home   Help Search Login Register  

Author Topic: Distance command  (Read 555 times)

0 Members and 1 Guest are viewing this topic.

BigBonga

  • Guest
Distance command
« on: 27 Oct 2004, 11:10:56 »
Hi there.
Does the distance command return a 2d or a 3d distance?
I have read in some places that it returns the 2d distance (ignoring z-axis) but in other places i read that it returns a 3d distance!
Which is correct?!
Thanks! :)

Offline C0LDSt33L

  • Members
  • *
  • Member of the SotM Team
Re:Distance command
« Reply #1 on: 27 Oct 2004, 11:19:32 »
It takes the z-axis into account

Offline Raptorsaurus

  • Editors Depot Staff
  • *****
Re:Distance command
« Reply #2 on: 27 Oct 2004, 22:06:21 »
Yup, 3D. X,Y and Z coordinates are all used.  If you want 2D position only there are a few functions that have been writen that can be useful.  Here is one that I did, called DisOverGnd which finds the 2D distance between two objects using only the X and Y coordinates.  You call the function like so:

_dis = [_obj1, _obj2] call DisOverGnd

The function is attached.
« Last Edit: 27 Oct 2004, 22:08:10 by Raptorsaurus »

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Distance command
« Reply #3 on: 28 Oct 2004, 10:19:19 »
This is interetsing.  I understand that the z coordinate returned by getPos is the height above gound level, so for distance function to return the true 3D distance it must work with a different z coordinate.

I will have a play around withthis when I get the time.

The 2D distance is not complicated it is just:

Sqrt((x1-x2)^2 +(y1-y2)^2)

using whatever OFP uses for square root and power
« Last Edit: 28 Oct 2004, 10:19:49 by THobson »

BigBonga

  • Guest
Re:Distance command
« Reply #4 on: 28 Oct 2004, 10:23:04 »
Right, so does the distance command return a distance based in heights above sealevel or a (rather useless) distance between two objects based upon their height above, the non uniform, ground level?
Glad it does 3d though - calculating it in 2d is simple pythagoras, as thobson suggests :)

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Distance command
« Reply #5 on: 28 Oct 2004, 11:33:06 »
3D is also simple pythagoras, just include the z component

3D distance = Sqrt((x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2)


BigBonga

  • Guest
Re:Distance command
« Reply #6 on: 28 Oct 2004, 12:18:26 »
YEs, that is obvious - however the mathematics to calculate the distance in 3d is much harder by hand - as OFP doesnt take height above sealevel in the getpos function - so you haev to factor in the height of the object from a reference source.
Then it gets complicated - as i am sure you know.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Distance command
« Reply #7 on: 28 Oct 2004, 12:23:44 »
Lol ;D - which takes us back to my first post

BigBonga

  • Guest
Re:Distance command
« Reply #8 on: 28 Oct 2004, 13:06:12 »
Nicely done, i feel - full circle!