Original Post
I'm having a hard time figuring out an equation, and even then figuring out how to use it :( Let's say I have a circle and the diameter is 200 pixels. I render this circle at 0,0 in my window. Thus, the center is at 100, 100. When the mouse is on this circle, I want to know how far away from the center the cursor currently is. I found this equation: However, sometimes the distance is 0 even when I'm clearly not pointing at the center. Other times, the number is about 10 digits long. First question: What am I doing wrong to get 0 sometimes? Second question: How do I convert the 10 digit string to a ratio from 0.0 to 1.0? Any insight is greatly appreciated!
sqrt((x-x1)^2 + (y-y1)^2) In my c++ code, I write this as follows: m_fDistanceFromCenter = sqrt(pow(m_fMouseX - fCenterX, 2) + pow(m_fMouseY - fCenterY, 2));