VVK
VVK

Reputation: 445

Rotate multi line (series of points) to match region

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.

illustration

Is there any algorithm to do it?

Upvotes: 1

Views: 63

Answers (1)

MBo
MBo

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

Related Questions