2

I have drawn few concentric circles and added a gesture listener too on the same view. I have drawn a point where i am placing the marker and tapping the button below. Once i tap the button, i will be getting the (x,y) co ordinates of the position where i place the maker and clicked the button. now i have to find out the distance between the center(x,y) of the view and marking that i have made earlier. I tried with distance calculation form ula, but still i am not sure i am getting the right solution. This is because, for example , when i mark a point at the top portion of the circle and made a mark at the bottom portion of the circle, its giving a different value. Since all are circles, from which ever part of the circle i mark, it has to give me the same distance . am i right ?

I tried with lot of ideas, still nothing work out well.

I have attached the screen shot of that page too, Please take a look at it

enter image description here

Any help is Appreciable.

Thanks.

Nandagopal T
  • 2,037
  • 9
  • 42
  • 54

2 Answers2

9

How are you using the distance formula?
It should just be something like this

Math.sqrt(Math.pow(clickX - centerX, 2) + Math.pow(clickY - centerY, 2));
mparizeau
  • 663
  • 5
  • 12
  • Hi , I tried with a similar way like this, private void distanceCalculation(int x1, int y1, int x2, int y2) { double calculation = (Math.pow((x2 - x1), 2) + Math.pow((y2 - y1) , 2)); mDistance = (int) Math.sqrt(calculation); Log.i(TAG, "Distance between Center point and Current Points :" + mDistance); } . I am not getting the exact solution. – Nandagopal T Apr 19 '11 at 08:56
  • Hi Guys, i got the solution for my own post. I made some little modification my logic. Thanks for your support. – Nandagopal T Apr 19 '11 at 14:08
  • 2
    @Nandagopal T kindly post your solution – Hiren Dabhi Jan 05 '12 at 09:53
0

You can use this formula,

double d = Math.sqrt( (x2-=x1)*x2 + (y2-=y1)*y2 );

Refer this question

Community
  • 1
  • 1
Jithu
  • 1,478
  • 1
  • 13
  • 21