问题
Let's say that you have a stick figure. Let's say the stick figure has an elbow and a hand. What if the stick figure wants to spin his hand in a windmill without moving his elbow? If the elbow serves as the center of a circle, and the hand must always be on the circle's circumference, and I know the exact location of the elbow and hand, how do I move the hand around the circle's circumference, while preserving the radius (the length of the arm between the elbow and hand because it really shouldn't shrink or grow)?
I need to move the coordinate of the hand along the circumference of a circle, where the center of the circle is the elbow. This is in 2D.
I have the coordinates of both points. I can calculate the radius which is the length of the line between the points. Knowing the circle's center and radius, how do I rotate the hand along the circle circumference? I want it to maintain the radius, but change positions on the circumference. Basically, it must act like it's hinged.
P.S: I had a picture, but Stack Overflow said I was too new... Blame Stack Overflow.
回答1:
Basic trigonometry says:
x = r * cos(a);
y = r * sin(a);
This does not take into account the rotation of the hand, just shows the point on the circle where the wrist will be. Is that what you are after?
EDIT: Sorry, that assumes the elbow is at (0, 0) and x +ve is right and y +ve is up.
Given the elbow is at (ex, ey) then wrist is at:
wx = ex + r * cos(a);
wy = ey + r * sin(a);
If, as happens in browsers, y is +ve down, then subtract instead of add.
来源:https://stackoverflow.com/questions/11335742/find-a-point-on-a-circle-circumference-based-on-degrees