#### EFileTahi-A

##### Contributor
Imagine you have a circle with a radius of 100 pixels at the center of the screen. I need to return the current radius of the circle where ever I put the mouse anywhere inside the circle. That is.. if I put the mouse half way inside the circle it should return 50 pixels.

I have no clue how to do this...

#### EFileTahi-A

##### Contributor
Please, if my previous post was kinda confusing do let me know about it. I will gladly reformulate it!

Thank you

#### EFileTahi-A

##### Contributor
Just wondering is this so complicated?

#### snarfblam

##### Ultimate Contributor
It's not too complicated. I overlooked your question because it was one among many topics that got spammed in the same day.

I think what you are looking for is the distance formula:
distance = Sqrt( (x2 - x1) ^ 2 + (y2 - y1) ^ 2 )

You would just want to calculate the distance between the center of the circle and the mouse position.

#### EFileTahi-A

##### Contributor

I tried that formula but it does not work... I get odd values, like 12 pixels at the distance of 300 pixels away from the circle's center. And sometimes I get NaN result.?

#### snarfblam

##### Ultimate Contributor
Here is a successful implementation of the distance formula:
Code:
``````[Color=Blue]using[/Color] System;
[Color=Blue]using[/Color] System[Color=Red].[/Color]Drawing;
[Color=Blue]using[/Color] System[Color=Red].[/Color]Windows[Color=Red].[/Color]Forms;

namespace WindowsFormsApplication1
[B]{[/B]
[Color=Blue]public[/Color] [Color=Blue]partial[/Color] [Color=Blue]class[/Color] Form1 [Color=Red]:[/Color] Form
[B]{[/B]
[Color=Green]// Location and size of bulls-eye[/Color]
[Color=Blue]const[/Color] [Color=Blue]int[/Color] originX [Color=Red]=[/Color] 100;
[Color=Blue]const[/Color] [Color=Blue]int[/Color] originY [Color=Red]=[/Color] 100;

[Color=Blue]protected[/Color] [Color=Blue]override[/Color] [Color=Blue]void[/Color] OnPaint[B]([/B]PaintEventArgs e[B])[/B] [B]{[/B]

base[Color=Red].[/Color]OnPaint[B]([/B]e[B])[/B];

[Color=Green]// Draw our bulls-eye[/Color]
[B]}[/B]

[Color=Blue]protected[/Color] [Color=Blue]override[/Color] [Color=Blue]void[/Color] OnMouseMove[B]([/B]MouseEventArgs e[B])[/B] [B]{[/B]
base[Color=Red].[/Color]OnMouseMove[B]([/B]e[B])[/B];

[Color=Green]// X and Y Distance from bulls-eye[/Color]
[Color=Blue]int[/Color] dx [Color=Red]=[/Color] e[Color=Red].[/Color]X [Color=Red]-[/Color] originX;
[Color=Blue]int[/Color] dy [Color=Red]=[/Color] e[Color=Red].[/Color]Y [Color=Red]-[/Color] originY;

[Color=Green]// Distance formula: Dist = Sqrt(dX ^ 2 + dY ^ 2)[/Color]
var dist [Color=Red]=[/Color] Math[Color=Red].[/Color]Sqrt[B]([/B]dx [Color=Red]*[/Color] dx [Color=Red]+[/Color] dy [Color=Red]*[/Color] dy[B])[/B];

[Color=Green]// Show Dist[/Color]
[Color=Blue]this[/Color][Color=Red].[/Color]Text [Color=Red]=[/Color] dist[Color=Red].[/Color]ToString[B]([/B][Color=DarkRed]"0.00"[/Color][B])[/B];
[B]}[/B]
[B]}[/B]
[B]}[/B]``````
Without seeing your code I couldn't even guess where the problem may lie.

#### EFileTahi-A

##### Contributor
Thank you!

Do you mind I add your name / nickname to my credit list? If so, what name should I include.

Thank you again! And please, post back.

#### snarfblam

##### Ultimate Contributor
I don't think there is much credit due; I didn't come up with the formula. At any rate, if you really feel so compelled I'd say just leave it at snarfblam.

#### EFileTahi-A

##### Contributor
It might be simple what you did, but the truth is that not one else managed to help me (I post this problem of mine also at other forums).

Consider yourself added to my credit list.

Thank you once more.