I have made an object class and set the mouseEnter event on it. Object describes a process of creating a circle using opengl (here is drawing process function):
public void DrawCicrle()
{
GL.Begin(PrimitiveType.TriangleFan);
GL.Color4(Color_);
GL.Vertex2(X_, Y_);
for (int i = 0; i < 360; i++)
{
GL.Vertex2(X_ + Math.Cos(i) * Radius_, Y_ + Math.Sin(i) * Radius_);
}
GL.End();
}
Then I did a mouseEvent, but cant get the coordinates of cursor correctly. What are the correct conditions to get points in the arc of a circle? This function returns a points, but with a little offset on the left side (X_ and Y_ are the center of a circle (double type) Radius_ is double type too):
public Point CursorLocation
{
get
{
return CursorLocation_;
}
set
{
this.CursorLocation_ = value;
for (int i = 0; i < 360; i++)
{
if (CursorLocation_.X <= X_ + Math.Cos(i) * Radius_ && CursorLocation_.Y<= Y_ + Math.Sin(i) * Radius_ && CursorLocation_.Y>=Y_-Radius_)
{
Enter(new Point(CursorLocation_.X, CursorLocation_.Y));
break;
}
}
}
}
The condition is dx * dx + dy * dy < R * R, where dx=Math.Abs(x-cx) and dy=Math.Abs(y-cy)
(x,y) is the cursor location and (cx,cy) the circle center
So you check the Euclidian distance between circle Center and some Point. To avoid square root calculation you just square both sides of comparison
Use <= if you also want to count-in the circle border