QML into coordinates in the pattern angle (rotation)

Today can try to do a finger along the direction of rotation of the turntable, which need the coordinates of the mouse event into the rotation Rectangle.

First, find the slope, it is assumed as the origin (0,0), so that the slope y / x

circleControl.recY/circleControl.recX

The slope angle can be known in order, but using Math.atan obtained radians, the angle needs to be further converted to

Math.atan(circleControl.recY/circleControl.recX)/(Math.PI/180)

Speaking just assume that the origin (0,0), but in fact written qml or graphical programming knows that, in fact, is the origin of the graph (width / 2, height / 2), which is the graph (0,0) is in the upper left corner of the graph, so take the x and y also need a bit of thought, correct point is to take the following code.

//mouse是鼠标坐标(手指坐标)
circleControl.recX=mouse.x-rectangle.width/2;
circleControl.recY=rectangle.height/2-mouse.y;

Then graphics rotation defaults to 0, but 0 when in fact equal to the mathematical coordinate angle of 90 degrees, and the rotation is clockwise rotation increases, with the mathematical point of view there are differences. It is necessary to add a 90 degree angle so that the obtained pattern in mathematical angle becomes 0 degrees, 360 degrees and then subtracting the result, it can be made into counter clockwise.

circleControl.rotation=450-Math.atan(circleControl.recY/circleControl.recX)/(Math.PI/180);
Released six original articles · won praise 0 · Views 231

Guess you like

Origin blog.csdn.net/qq_35342292/article/details/104626058