11-20-2010 09:44 PM
Hello,
I have drawed a circle on the canvas control, and want to capture an arbitrary point in the circle, where the point's coordinate is determined by the "GetRelativeMouseState()" function. The whole idea is this: once click in the circle, I can get the coordinate of the clicking point by using "GetRelativeMouseState()", then drawing a line from the circle's midpoint to the point, expecting to calculate the angle between the line and the X axis. I post the sketch to explain how the process is treated :
the coordinate of the midpoint is (width/2, height/2), so if want to calculate the theta angle, I can get the formular: theta = atan((height/2 - yCoor) / (width/2 - xCoor)), there is a strange condition: if the line is near to the X axis (in fact, the line turn to angle exceed 135 degree (as to the counterclockwise) but there is a distinct angle between the X axis, the theta), I always get a zero angle value(the theta).
Please help whether the "GetRelativeMouseState()" can provide an exact position?
David
11-21-2010 06:29 AM
How are you calculating the angles? With some basic trigonometry and atan2 () function I always get the correct angles: take a look at the attached canvas.prj sample which I modified adding the necessary functions (click Draw Circle and check Angle drawing: when clicking on the canvas the program will draw the line and calculate the corresponding angle)