This is something I can't seem to figure out:
[attachment=5990:problem.png]
I have two 2D points P and Z, and two 2D vectors V and D. I need to find a rotation angle a such that Z lies on a line with the origin P+V[sup]R[/sup] and direction D[sup]R [/sup]where V[sup]R [/sup]is V rotated by a and the same for D.
Note that D doesn't have to be a vector, it can be an angle if that makes it easier.
I'd appreciate any help on this issue.
Rotating an offset vector to point at a position
This is something I can't seem to figure out:
[attachment=5990:problem.png]
I have two 2D points P and Z, and two 2D vectors V and D. I need to find a rotation angle a such that Z lies on a line with the origin P+V[sup]R[/sup] and direction D[sup]R [/sup]where V[sup]R [/sup]is V rotated by a and the same for D.
Note that D doesn't have to be a vector, it can be an angle if that makes it easier.
I'd appreciate any help on this issue.
Here's a crack at it, untested and could be completely wrong
theta = angle between V, D (given)
||P - Z|| / sin(theta) = ||V - P|| / sin(phi)
phi = arcsin(sin(theta) * ||V - P|| / ||P - Z||)
beta = arctan((Zy - Py)/(Zx - Px))
omega = 2 * pi - theta - phi - beta
Vr.x = ||V - P|| * cos(omega)
Vr.y = ||V - P|| * sin(omega)
I tried out your solution pantaloons and it seems to work properly, but only when V.y is less than zero and when D is pointing directly to the right.
The restriction on D isn't really an issue, because V and D can always be rotated beforehand to make D point to the right, but the restriction on V is a bigger problem.
Still, thanks a lot!
Edit: Figured out how to make it work when V.y > 0. Kind of an unintuitive solution, but omega = beta - (PI - theta - phi), and Z.x should be mirrored relative to P.x when V.y > 0
The restriction on D isn't really an issue, because V and D can always be rotated beforehand to make D point to the right, but the restriction on V is a bigger problem.
Still, thanks a lot!
Edit: Figured out how to make it work when V.y > 0. Kind of an unintuitive solution, but omega = beta - (PI - theta - phi), and Z.x should be mirrored relative to P.x when V.y > 0
It should have been:
[color="#1C2837"]omega = pi - theta - phi - beta
[color="#1C2837"]If you didn't catch that. Although you are right I think quadrant issues get in the way with the right triangle approach to computing Vr. We can make it easier:
[color="#1C2837"]theta = angle between V, D (given)[color="#1C2837"]
[color="#1C2837"]
[color="#1C2837"]
[color="#1C2837"]
[color="#1C2837"]omega = pi - theta - phi - beta
[color="#1C2837"]If you didn't catch that. Although you are right I think quadrant issues get in the way with the right triangle approach to computing Vr. We can make it easier:
[color="#1C2837"]theta = angle between V, D (given)[color="#1C2837"]
||P - Z|| / sin(theta) = ||V|| / sin(phi)
phi = arcsin(sin(theta) * ||V|| / ||P - Z||)
[color="#1C2837"]omega = pi - theta - phi[color="#1C2837"]
X = (Z - P)/||Z - P||
[color="#1C2837"]if(0 <= theta <= pi) [color="#1C2837"]Vr = ||V|| * R(omega) * X [color="#1C2837"]else Vr = ||V|| * R(-omega) * X[color="#1C2837"]
[color="#1C2837"]
Where R(omega) is a standard 2x2 rotation matrix through angle omega. Notice that in fact, discounting the direction of vector D, there are two solutions that are equally rotated away from the vector Z - P, however you want the solution where D points towards Z which necessitates a negative rotation if -pi < theta < 0 (or turn(P, V, D) == right)).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement