I am trying to find the new position of the points in a line, after certain changes.
The line is simple: coordinate locale (0,0) to (len, 0); it has a position in the scene, and a rotation.
If rotation is applied, the line changes visually, but the position doesn't... The rotation is stored in the rotation transformation, along with shifts for x and y.
That allows me to determine the true position of the end points of the line, P1 and P2 ... the program I use has even functions:
P1 = mapToScene(0,0) and P2 = mapToScene(len,0)
I think formulas would be
$P1 = pos.x - \frac{len*sin(\theta)}{2}$
$P2 = pos.y + \frac{len*(1 - cos(\theta))}{2}$
Changing the length of the line would change P2, but not P1, while rotation would change both.
What I am struggling to find out is, formulas for
- changing P1 while keeping P2 constant, and
- changing P2 while keeping P1 constant
How can I determine the change in position in the two cases ?
What I can determine:
I can find the length and angle of the original line ($len_1$, $\theta_1$)
Given a new P1, I can determine the length and angle of the line between the new P1 and P2 ($len_2$, $\theta_2$).
But from there, I keep trying to find the difference between the old and new position (since the line will still be an object horizontal line, of length $len_2$ and a transformation with angle $\theta_2$).
Edit I have been unable to use transformations as suggested in comment, but after multiple redraws of what the moves would look like, I fixed the formula for determining the position shift for a change in P1 - so P2 change will be next.
$dx = \frac{len_1*(1+\cos(\theta_1))}{2} - \frac{len_2*(1+\cos(\theta_2))}{2}$
$dy = \frac{len_1*\sin(\theta_1)}{2} - \frac{len_2*\sin(\theta_2)}{2}$
$pos.x += dx$
$pos.y += dy$
It almost works... It works when $\theta_1$ is 0...
For changing P2 and keeping P1 constant, it would seem the solution is even simpler:
- From the current transform, involving a rotation, take the translation coefficients
- create a transform for the new rotation
- move pos by the difference
Very simple... Very logical... But it only works once (subsequent transforms all change points).
I am close to drawing the conclusion that this is an unsolvable problem.