We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › How does dist() work
Page Index Toggle Pages: 1
How does dist() work ? (Read 471 times)
How does dist() work ?
Apr 3rd, 2006, 3:37am
 
I'm currently working on a C++ port of a Processing color tracker.
So I had to write the Euclidian distance function to compare colors. But I don't know If I did it well. With the processing version, everything was ok. But mine seems to be  hazardous :/

Here's my code :
double nsPerform::Distance(int x1, int y1, int z1,
int x2, int y2, int z2)
{
double pol;
//v(x2-x1)² + (y2-y1)² + (z2-z1)²
pol = ((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1)) + ((z2-z1)*(z2-z1));
return (sqrt(pol));
}

Could someone post the processing version source ?
Thanks
Re: How does dist() work ?
Reply #1 - Apr 3rd, 2006, 4:13am
 
float distance(int x1, int y1, int z1, int x2, int y2, int z2)
{
float pol = sq(x2-x1) + sq(y2-y1) + sq(z2-z1);
return sqrt(pol);
}

or

you can use the processing method
http://processing.org/reference/dist_.html
Re: How does dist() work ?
Reply #2 - Apr 3rd, 2006, 10:29am
 
Basically, Pythagorean theorem
http://en.wikipedia.org/wiki/Pythagorean_Theorem

Pythagoras would be proud.
Page Index Toggle Pages: 1