Trying to draw an arrow (= directional segment = vector) with mechanics as in the paint. That is, we hold down the left key, and until we let go, a segment is drawn as in a drawing, only at the end of the segment (that is, at the current position of the mouse) should there be a right-pointing triangle (in my case, equilateral). I do it in steps: 1) draw a segment of 2 points; 2) I draw a correctly directed triangle over the last point. Question 2 step.
My library can draw an equilateral triangle, and can also do it rotate(float angle) , where angle is the angle in degrees clockwise .
For example, triangle.rotate(45) will rotate the initial equilateral triangle (symmetrical about the Oy axis) 45 clockwise.
So, the problem is that the triangle rotates with the "rotating" segment. In fact, the segment does not rotate, but each time it is drawn again by 2 points: where the current coordinates of the mouse are clamped +. Here is how I get the angle between my current line and the Ox axis at (0;360] :
auto angle = 360.f - std::atan2(second.y - first.y, second.x - first.x) * 180 / 3.14159265f; if (angle > 360.f) angle -= 360; where first is the clamped point, second is the current one. How from this angle (and maybe there is an easier option) to go to the triangle.rotate(float angle) required for triangle.rotate(float angle) ?
angle = 90 - angle;- Igor