LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Can not get the proper angle value

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 :

 

捕获.jpg

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

0 Kudos
Message 1 of 2
(2,839 Views)

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)



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 2
(2,829 Views)