2D/3D Distance DLL

Blitz3D Forums/Blitz3D Userlibs/2D/3D Distance DLL

Xzider(Posted 2007) [#1]
You can do this easily with just Blitz commands, but I dont know, maybe its faster in C++. Probably not. You can also find this in DLL Toolbox.

http://xelevgames.servegame.com/Site/Downloads/DLL/DistanceDLL.zip

This is a distance formula for 2D x,y coords and 3D x,y,z coords. Post at forums at http://xelevgames.servegame.com/forums/BloodBane/ for comments/suggestions

Example - after putting Distance.dll and Distance.decls in Blitz3D\userlibs folder, open blitz basic and type

Print "2D Distance Example 1: " + dist2d(10,10,10,10) ;Should be 0
Print "2D Distance Example 2: " + dist2d(10,10,10,11) ;Should be 1, changed second y coord

Print "3D Distance Example 1: " + dist3d(50,2,100,50,2,100) ;Should be 0
Print "3D Distance Example 1: " + dist3d(50,2,100,159,5,255) ;Should be 189

WaitKey
End

This DLL was made in C++ and was very simple, took me around 5 minutes to make in C++.

Revisions:

December 15 2007:

Changed return type of dist2d/dist3d functions to float, I made them integers by accident.


puki(Posted 2007) [#2]
Interesting - anyone tried it?


Subirenihil(Posted 2007) [#3]



Wings(Posted 2008) [#4]
Thanks greeks


i forgott hits Equation :D
'


Xzider(Posted 2008) [#5]
Indeed Subirenihil, or to be more specific


float dist2d(float x1,float y1,float x2,float y2)
{

	float distance;
	float dx;
	float dy;

	dx = x2 - x1;
	dy = y2 - y1;

	dx = (dx*dx);
	dy = (dy*dy);

	distance = sqrt(dx + dy);

	return distance;
}

////////////////////////////

float dist3d(float x1,float y1,float z1,float x2,float y2,float z2)
{

	float distance;
	float dx;
	float dy;
	float dz;

	dx = x2 - x1;
	dy = y2 - y1;
	dz = z2 - z1;

	dx = (dx*dx);
	dy = (dy*dy);
	dz = (dz*dz);

	distance = sqrt(dx + dy + dz);

	return distance;
}




bytecode77(Posted 2008) [#6]
whats this good for anyway? if you want this, just type the 10 lines of code in bb. its not even faster that you can say it's worth using. no offence ;)
my opinion: why dont you expand this dll with some more or with a lot more math functions and call it "math dll" or somethin... this would be a better solution!


Xzider(Posted 2008) [#7]
"You can do this easily with just Blitz commands, but I dont know, maybe its faster in C++. Probably not"

None taken, but please read the first post of a topic before posting on it.