Hi,

Can someone tell me the code to calculate the distance between two pixel points.

If i enter Point(x1,y1) and Point(x2,y2) then i get length of the line between them (in pixels).

Thanks.

ever heard of Pythagoras' Theorem " a on power of two plus b on power of two equals to c on power of two"?
just example

``````(x1 - x2 ) = x           // your a
(y1 - y2) = y            // your b

if ( x < 0) then x * (-1)
if ( y < 0) then y * (-1)

x^2 + y^2 = z^2       // z is your c distance between pixels    this ^2 on power of two

then get square root``````

ever heard of Pythagoras' Theorem " a on power of two plus b on power of two equals to c on power of two"?
just example

``````(x1 - x2 ) = x           // your a
(y1 - y2) = y            // your b

if ( x < 0) then x * (-1)
if ( y < 0) then y * (-1)

x^2 + y^2 = z^2       // z is your c distance between pixels    this ^2 on power of two

then get square root``````

lleave out the multiplying with -1 : x^2 is eual to (-x)^2

lleave out the multiplying with -1 : x^2 is eual to (-x)^2

in other words :

double a = P.x - Q.x;
double b = P.y - Q.y;
double distance = Math.sqrt(a * a + b * b);

and on you go

yeah that's correct forgot about it :mrgreen:

Hi,

Thanks for your help. It worked.

Regards.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.