Determine rotation direction /toward/ variable poi

2020-05-09 09:54发布

问题:

Given circle centre: vectorA and another Vector on the circle's perimeter:vectorB, how can you determine the shorter route for vectorB to translate to another point on the circle's perimeter that is variable:vectorC? Will the shorter route be clockwise or counter clockwise rotation?

If it helps think of a clock. If the times is a random point on the clock's perimeter eg. 6, and the minute hand position is known, eg. 4. Does the hand need to rotate around the clock's centre point clockwise or counter clockwise to reach the random point (6)?

See also:
Vec1 = Circle centre, Vec2 = mousepos, find the point on the circle between Vec1, Vec2

回答1:

Just compute winding direction of triangle ABC

so if you compute normal n=(B-A)x(C-B) where x is cross product then n.z sign determine the direction.

n.z = ((B.x-A.x)*(C.y-B.y)) - ((B.y-A.y)*(C.x-B.x))
if (n.z<0.0) dir=CW else dir=CCW;

that is all you need (CW means clockwise and CCW counter clockwise) of coarse if your coordinate system is different then the rotation can be negated

[Notes]

if (n.z==0) then the points B,C are either opposite or identical so direction does not matter because both ways the angular distance is the same