pointtopoint() - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: pointtopoint() (
/showthread.php?tid=188161)
pointtopoint() -
legodude - 06.11.2010
is there a function to calculate the distance between points?
if there's not can someone create one please?
Re: pointtopoint() -
Mauzen - 06.11.2010
There are loads of them, i prefer using a fast plugin-based.
But this one should do its job too
pawn Код:
stock Float:PointToPoint(Float:x, Float:y, Float:z, Float:xx, Float:yy, Float:zz)
{
return floatsqroot( (x - xx) * (x - xx) + (y - yy) * (y - yy) + (z - zz) * (z - zz) );
}
(untested)
Re: pointtopoint() -
legodude - 06.11.2010
isnt that pythagoras?
Re: pointtopoint() -
DeathOnaStick - 06.11.2010
Quote:
Originally Posted by legodude
isnt that pythagoras?
|
Pythagoras:
aІ+bІ=cІ
We've got:
xІ+yІ+zІ=aІ
It has it's origin from Pythagoras, but we just added another dimension.
Proof that it works:
Imagine the world would be a coordination system. We've got a triangle, so we first use Pythagoras to get the distance of the points on the ground level:
xІ+yІ=d(xy)І
d(xy) means the distance, from X to Y.
Now, when we've got the ground level, we add the altitude, Z. We get this:
d(xy)І+zІ=d(xyz)І
Now we can easily replace d(xy)І with xІ+yІ. What we get looks like this:
xІ+yІ+zІ=d(xyz)І
We want d(xyz), not d(xyz)І, so we use the squareroot. Now we've got:
√(xІ+yІ+zІ) = √d(xyz)І = d(xyz)
I don't know if this was necessary for you, but it might help some people to understand the background of the code.
Re: pointtopoint() -
legodude - 06.11.2010
so its 3 dimensional pythagoras?
kewl xd