0

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.

3
Contributors
5
Replies
7
Views
10 Years
Discussion Span
Last Post by anti_genius
1

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
0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.