Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / how do you find the distance between two objects?

Author
Message
kfoong
23
Years of Service
User Offline
Joined: 28th Jan 2003
Location: Australia
Posted: 12th Jun 2003 13:49
The question above. My mathematics are not working at the moment, I cant think. Does any one else know how to find the distance between two objects?
Heh heh... Mule...
http://www.stellarblue.vze.com/
Beta1
23
Years of Service
User Offline
Joined: 28th Dec 2002
Location:
Posted: 12th Jun 2003 14:46
In how many dimensions.

If you just want 2 then its pythagorus distance=sqrt((x1-x2)^2+(y1-y2)^2)

In 3D its a little more complicated and I cant remember off the top of my head how to do it.

Dr OcCuLt
23
Years of Service
User Offline
Joined: 27th Nov 2002
Location: a Dark Deep Dark pit, it dark in here
Posted: 12th Jun 2003 14:49
in 3D it just distance=sqrt((x1-x2)^2+(y1-y2)^2+(z1-z2)^2)

You mean like a book?
Justin Timberlake N Sync.
On what he read this year that he most liked.
kfoong
23
Years of Service
User Offline
Joined: 28th Jan 2003
Location: Australia
Posted: 12th Jun 2003 15:17 Edited at: 12th Jun 2003 15:25
I know the 2d one easily but how about 3D?

[EDIT] Oops didnt see the second post , thanks DR occult

Heh heh... Mule...
http://www.stellarblue.vze.com/
OzBot
23
Years of Service
User Offline
Joined: 24th Feb 2003
Location: Sweden
Posted: 12th Jun 2003 21:40
here is how I do it:

bx#=object position x(Object1)
by#=object position y(Object1)
bz#=object position z(Object1)
dx#=object position x(Object2)-bx#
dy#=object position y(Object2)-by#
dz#=object position z(Object2)-bz#
distance#=sqrt(abs(dx#*dx#)+abs(dy#*dy#)+abs(dz#*dz#))

regards,
OzBot
Rye
23
Years of Service
User Offline
Joined: 30th May 2003
Location: United Kingdom, Blackrod
Posted: 12th Jun 2003 22:33
Here is a simple function that i use all the time hope you can use it.



He who keeps his work in disorder gives home to chaos. Let him be struck with stone and iron to forge away his flaws
Attreid
23
Years of Service
User Offline
Joined: 27th Nov 2002
Location:
Posted: 12th Jun 2003 22:53
I've a better one, Ryan
you just have to write the number of the objects ^_^

"He will come...the voice from the outer world,
bringing the holy war, the Jihad, which will cleanse the Universe and bring us out of darkness."
Rye
23
Years of Service
User Offline
Joined: 30th May 2003
Location: United Kingdom, Blackrod
Posted: 12th Jun 2003 22:58
maybe but mine doent need two object numbers. What if you want the distance between particles or an object and a particle. or even a matrix etc...

He who keeps his work in disorder gives home to chaos. Let him be struck with stone and iron to forge away his flaws
Attreid
23
Years of Service
User Offline
Joined: 27th Nov 2002
Location:
Posted: 12th Jun 2003 23:10
yeah, but when you want the distance between two objects, you have a lot of things to input ^^
the best would be to use the two codes

"He will come...the voice from the outer world,
bringing the holy war, the Jihad, which will cleanse the Universe and bring us out of darkness."
The Darthster
23
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 12th Jun 2003 23:47
Sqrt is fairly time consuming, so if you want to compare distances it is quicker to omit the sqrt, and just square the distance to be compared.

Once I was but the learner,
now, I am the Master.
kfoong
23
Years of Service
User Offline
Joined: 28th Jan 2003
Location: Australia
Posted: 13th Jun 2003 03:49
attried, I dont think your piece of code works just by looking at it. I'm quite sure that you cannot start a variable with a number.

anyway peoples I know how to put it in, thanks fo everyones help.

P.S. Im not that much of a newb am i?

Heh heh... Mule...
http://www.stellarblue.vze.com/
Andy Igoe
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: United Kingdom
Posted: 13th Jun 2003 04:05
Here are my range checking functions for comparing 1D, 2D and 3D.

The line null=make vector3(1) should be at the start of the program, the functions at the end.

Use just like any DBPro command

=range1D(pointA,pointB)
=range2D(aX,aZ,bX,bZ)
=fastRange2D(aX,aZ,bX,bZ)
=range3D(aX,aY,aZ,bX,bY,bZ)



Pneumatic Dryll
Viper
23
Years of Service
User Offline
Joined: 31st May 2003
Location:
Posted: 13th Jun 2003 07:26
Here is another formula to find the distance in 3D:
Its basicly pathareans Theorum done twice:

sqrt(x^2 + y^2 )= a `this finds the 2D distance
sqrt(a^2 + z^2 )= b `this finds the final 3D distance

this is the basis to find the answer.

Login to post a reply

Server time is: 2026-07-20 05:20:45
Your offset time is: 2026-07-20 05:20:45