Reputation: 445
I have an arbitrary multiline (series of XY points) starting at (0, 0). The task is to recalculate all positions in that way, so the last point would lay on a predefined edge (Y value). See illustration.
Is there any algorithm to do it?
Upvotes: 1
Views: 63
Reputation: 80117
If the last point has coordinates (xe, ye)
, then direction angle from origin to that point is
fie = Atan2(ye, xe)
Distance from origin to tha point is
len = Sqrt(ye*ye + xe*xe)
Wanted y-position is yw
, so direction angle is
fiw = Arcsin(yw / len)
So you need to rotate all points by angle difference
dfi = fiw - fie = Arcsin(yw / len) - Atan2(ye, xe)
Upvotes: 1