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 / Finding 3d distance

Author
Message
Philip
23
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 11th Nov 2003 17:00
Tonight I have been playing about a bit with some great snippets in Codebase such as IanM's "filledcircle()" - we like! we like!

Anyway, I noticed RobK's snippet to find 3d distance. It works beautifully and uses the Pythagorean theorem. We like! We like!

My question is this. Is it better/quicker to use the Pythagorean theorem or the bespoke 3d Maths routines that come with DBPro? See attached for an example of how to calculate the distance between two points in 3d in two commands.

Thoughts?

Philip

What do you mean, bears aren't supposed to wear hats and a tie?
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th Nov 2003 19:56
It's marginally quicker to use 3d vectors to find the distance

Use something like this:

Philip
23
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 12th Nov 2003 13:09
Er ... thanks IanM. Your code is to all intents and purposes identical to my code in the attachment!

Great minds!

Philip

What do you mean, bears aren't supposed to wear hats and a tie?
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 12th Nov 2003 14:36
Oops - missed that
Philip
23
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 12th Nov 2003 17:16
Heh heh.

Philip

What do you mean, bears aren't supposed to wear hats and a tie?
Xander
23
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 13th Nov 2003 20:05
So using vectors for distance is faster than:

dist#=sqrt((x1-x2)^2+(y1-y2)^2+(z1-z2)^2)

?

Xander - Bolt Software

Why do the antagonists always have to look so cool?
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Nov 2003 20:07
Yep
Philip
23
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 14th Nov 2003 16:47
Theoretically it should be. There are less mathematical calculations involved. Mind you, on most programmes, the difference will be very very very very very very very very very very very very very very very small.

Yep, thats very very very very very very very very very very very very very very very very very very very very VERY very very small.

*Cough*

Now, onto important matters. Who here likes jam?

Philip

What do you mean, bears aren't supposed to wear hats and a tie?
Xander
23
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 14th Nov 2003 19:31
I like jam. Strawberry is good.

Xander - Bolt Software

Why do the antagonists always have to look so cool?
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Nov 2003 19:52
There's no 'theoretical' about it ... I tested it - the only way to know for sure

Now, back to those important things ... what's your view on honey or marmalade?
Philip
23
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 15th Nov 2003 11:13
I'm biased in favour of honey. Marmalade is ok, but only with butter and toast.

What do you mean, bears aren't supposed to wear hats and a tie?
ZomBfied
23
Years of Service
User Offline
Joined: 2nd Oct 2002
Location:
Posted: 15th Nov 2003 21:39
You can make it a whole lot faster if you don't need an exact 3d distance, or there's anything constant like height.
One thing that will make it a little faster is instead of saying

(x2-x1)^2

say

d1=x2-x1
d1*d1

In other words don't use x^2 use x*x instead.

Login to post a reply

Server time is: 2026-07-26 14:31:08
Your offset time is: 2026-07-26 14:31:08