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 Discussion / Why is this calculation used this way in DB?

Author
Message
Epsilon
21
Years of Service
User Offline
Joined: 30th Jul 2003
Location: North West, UK
Posted: 27th Oct 2003 21:41
I know im missing something here but i dont know what it is.

Why is this code used in this way.

PDist = Sqrt((mX# - X#)^2 + (mY#+25 - Y#)^2 + (mZ# - Z#)^2)

Maybe its just me but isnt the square root counter acting the whole point of the square.

Why is this used Argh is so weird.
heartbone
22
Years of Service
User Offline
Joined: 9th Nov 2002
Location:
Posted: 27th Oct 2003 21:58 Edited at: 27th Oct 2003 22:01
Assume for a moment that
(mX# - X#) = X = 2
(mY#+25 - Y#) = Y = 3
(mZ# - Z#) = Z= 4

Using the formula for PDist

PDist = Sqrt(X^2 + Y^2 + Z^2) = Sqrt(4+9+16) = Sqrt(29) ~ 5.5

Without the squares and sqrt you'd have

PDist = (X + Y + Z) = (2 + 3 + 4) = 9

Big difference, agreed?

The more you see, the more you know.
The more you know, the more you see.
Epsilon
21
Years of Service
User Offline
Joined: 30th Jul 2003
Location: North West, UK
Posted: 28th Oct 2003 00:51
sorry the question wasnt clear, thanks for the explanation, but i meant why is such a confusing calculation used for finding a distance between two objects? Is it just because its a more compact code.
Epsilon
21
Years of Service
User Offline
Joined: 30th Jul 2003
Location: North West, UK
Posted: 28th Oct 2003 00:55
Sorry again it was all me seeing the wrong thing thought ^2 was squaring it, but its multiplying it by 2 makes more sense thnx a bunch heartbone.

Still dont know how they thought that up for calculating distance.
Anyone actually figured it out?
post a message if u know why.
heartbone
22
Years of Service
User Offline
Joined: 9th Nov 2002
Location:
Posted: 28th Oct 2003 02:25 Edited at: 28th Oct 2003 02:28
You were right originally. X^2 does mean X squared.

Let's back off to just two dimensions.
Take this right triangle the horizontal side is 3 long, the vertical side is 4 long, the hypotenuse length is then defined by

SQRT( 3^2 + 4^2) = SQRT(9+16) = SQRT(25) = 5

This is based on the Pythagorean Theorem.
http://www.cut-the-knot.org/pythagoras/index.shtml

The more you see, the more you know.
The more you know, the more you see.
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 28th Oct 2003 12:43
Mate, that's the distance formula, If you got anywhere near to passing Math in School, then you'd know what the formula is and why it is used and where it comes from...


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Epsilon
21
Years of Service
User Offline
Joined: 30th Jul 2003
Location: North West, UK
Posted: 29th Oct 2003 00:19
yeah sorry my fault, just saw it in code didnt know what it was but then found out later it was for distance only just realised now that it is pythgarus' theorem. Also that it is worked with the vertices of the triangle to work out the distance. I do know this was just being ignorant and not noticing what straight infront of me.
Epsilon
21
Years of Service
User Offline
Joined: 30th Jul 2003
Location: North West, UK
Posted: 29th Oct 2003 00:22
also good if i checked my spelling too pythagarus
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 30th Oct 2003 03:26 Edited at: 30th Oct 2003 03:27
yeah


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy

Login to post a reply

Server time is: 2025-05-21 09:26:57
Your offset time is: 2025-05-21 09:26:57