你怎么能找到从矢量a到b的有角度θ?
是的,我知道theta = arccos((ab)/(| a || b |)).
但是,这不包含符号(即它不区分顺时针或逆时针旋转).
我需要能告诉我从a到b旋转的最小角度.正号表示从+ x轴向+ y轴的旋转.相反,负号表示从+ x轴向-y轴的旋转.
assert angle((1,0),(0,1)) == pi/2.
assert angle((0,1),(1,0)) == -pi/2.
Run Code Online (Sandbox Code Playgroud) 任务是使用类似PowerPoint的d3旋转图形:
得到了这个示例,试图实现相同的行为。无法理解,错误出在哪里-人物在晃动,没有按照应有的方式旋转。
function dragPointRotate(rotateHandleStartPos) {
rotateHandleStartPos.x += d3.event.dx;
rotateHandleStartPos.y += d3.event.dy;
const updatedRotateCoordinates = r
// calculates the difference between the current mouse position and the center line
var angleFinal = calcAngleDeg(
updatedRotateCoordinates,
rotateHandleStartPos
);
// gets the difference of the angles to get to the final angle
var angle =
rotateHandleStartPos.angle +
angleFinal -
rotateHandleStartPos.iniAngle;
// converts the values to stay inside the 360 positive
angle %= 360;
if (angle < 0) {
angle += 360;
} …Run Code Online (Sandbox Code Playgroud)