Formula to calculate how much should be added to the x and y to move to a new point (On a rotated square) 
Hey!
(please see the diagram before reading the question)
i have this square ABCD which is 10x10cm and it is rotated 45 degrees clockwise
i need to move it 25 cm (so to square EHGF) over the red lines lines (AF and CG)
but i cant slide it over those lines, instead i need to move it an X amount to the left and an Y amount up to get to the square EHGF
is there a formula to calculate how much X and Y are in this case?
i am looking for a formula that always works no matter how much the square is rotated
All help is very appreciated!
 A: There are various ways to do this.
If you know the angle of rotation, you can use trigonometry to calculate the $x$ and $y$ components of the desired motion.
In this example, before rotation you would have started with $B$ directly above $A$
(at the same $x$ coordinate), and you then rotated $45$ degrees clockwise to get to the position shown.
In general, suppose you rotate by an angle $\theta$ clockwise,
and then you want to move by a distance $d$ in the rotated direction.
(In the figure it appears that $d$ is $15$. You say $25$ in the question.
Using a symbol $d$ for the distance means you can make the distance anything
you want; just make sure you set $d$ to the desired distance from $A$ to $E$.)
Then the amount to add to $y$ is
$$ d \cos(\theta) $$
(assuming positive $y$ is upward in the figure,
the direction from $C$ to $B$, as implied in the question)
and the amount to add to $x$ is
$$ -d \sin(\theta) $$
(assuming positive $y$ is leftward in the figure, the direction from $D$ to $A$, as implied in the question).
If adding a positive number to $x$ will move you to the right (as in the usual Cartesian coordinates on a graph) then the $x$ formula is reversed and becomes $d \sin(\theta).$
You can verify the formulas with a few test values, such as zero and a right angle. Just be careful to use the correct angle measurements when passing arguments to the sine and cosine functions; most computer math libraries expect these arguments to be measured in radians rather than degrees.
If you already have the coordinates of all the vertices of the square at the time you have to compute the $x$ and $y$ amounts, however, you can avoid the need to use trigonometric functions.
Suppose the $(x,y)$ coordinates of $A$ are $(a_x, a_y)$ and
the $(x,y)$ coordinates of $B$ are $(b_x, b_y)$.
Let $s$ be the length of the side of the square;
you say in the question that $s = 10,$ but if you don't know the size of the square it is easy to compute it from the coordinates:
$$ s = \sqrt{(b_x - a_x)^2 + (b_y - a_y)^2}. $$
Now the amount to add to the $x$ coordinate is just
$$ \frac ds(b_x - a_x) $$
and the amount to add to the $y$ coordinate is just
$$ \frac ds(b_y - a_y). $$
That is, you know that adding $b_x - a_x$ to the $x$ coordinates and $b_y - a_y$ to the $y$ coordinates will move you $s$ units in the desired direction;
to move $d$ units in that direction instead of $s$ units, you just have to move $d/s$ times as far.

By the way, if the side of the square is really $10$ cm and the points that appear to be at the intersections of grid lines really are at intersections of grid lines, then your grid lines are approximately
$4.714$ cm apart.
When an actual $10$-cm square is rotated $45$ degrees on a $5$-cm grid,
keeping one vertex on an intersection of grid lines,
the diagonally opposite vertex is visibly below the third grid line above the fixed vertex.
