calculating distance

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Acki

calculating distance

Post by Acki »

Hi,
my problem is, that I have two 3d-vectors and whant to calculate the distance between them!

With an 2d-vector it's no problem
(Phytagoras: SQR((X2-X1)^2 + (Y2-Y1)^2) = distance

But what about two 3d-vectors ???

Maybe there is a function in Irrlich, that I can use ???

CU, Acki
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

irr::core::vector3df difference = vector1 - vector2;
return difference.getLength();

or even simply

return vector1.getDistanceFrom(vector2);
a screen cap is worth 0x100000 DWORDS
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

Oh man i've forgotten about some of the functions of vectors :oops: . But thanks for the reminder keless :wink: (seems my block of code is alittle longer than it should be)
Programmer of the Irrlicht Scene Editor:
Homepage - Forum Thread
Version 2 on its way!!
SuryIIID_

Post by SuryIIID_ »

With an 2d-vector it's no problem
(Phytagoras: SQR((X2-X1)^2 + (Y2-Y1)^2) = distance
Well you can just add the third element of a 2D vector and make it a 3D vector :D

SQR((X2-X1)^2 + (Y2-Y1)^2+ (Z2-Z1)^2) = distance ;

PS : No kidding it works :wink:
Acki

Post by Acki »

Thanks !!! :)

I'll try both methods...

CU
Post Reply