Calculating distance between pixels

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2006
Posts: 27
Reputation: anti_genius is an unknown quantity at this point 
Solved Threads: 0
anti_genius anti_genius is offline Offline
Light Poster

Calculating distance between pixels

 
0
  #1
Nov 17th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,195
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 485
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Calculating distance between pixels

 
1
  #2
Nov 17th, 2006
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
Last edited by peter_budo; Nov 17th, 2006 at 7:39 am.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 17
Reputation: p.bondam is an unknown quantity at this point 
Solved Threads: 0
p.bondam's Avatar
p.bondam p.bondam is offline Offline
Newbie Poster

Re: Calculating distance between pixels

 
0
  #3
Nov 17th, 2006
Originally Posted by peter_budo View Post
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 17
Reputation: p.bondam is an unknown quantity at this point 
Solved Threads: 0
p.bondam's Avatar
p.bondam p.bondam is offline Offline
Newbie Poster

Re: Calculating distance between pixels

 
0
  #4
Nov 17th, 2006
Originally Posted by p.bondam View Post
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,195
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 485
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Calculating distance between pixels

 
0
  #5
Nov 17th, 2006
yeah that's correct forgot about it :mrgreen:
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 27
Reputation: anti_genius is an unknown quantity at this point 
Solved Threads: 0
anti_genius anti_genius is offline Offline
Light Poster

Re: Calculating distance between pixels

 
0
  #6
Nov 24th, 2006
Hi,

Thanks for your help. It worked.

Regards.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC