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.

anti_genius 0 Light Poster

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.

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

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
```

p.bondam 0 Newbie Poster

ever heard of Pythagoras' Theorem "

aon power of two plusbon power of two equals tocon 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

p.bondam 0 Newbie Poster

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

peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster

yeah that's correct forgot about it :mrgreen:

anti_genius 0 Light Poster

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.