Javascript 使用带有偏移圆的atan2

Javascript 使用带有偏移圆的atan2,javascript,geometry,trigonometry,Javascript,Geometry,Trigonometry,我正在尝试计算弧长,以便在给定弧长的情况下为圆边界着色 用户可以单击圆边,代码应自动计算从位置开始的弧长y=radiusx=cx。给定函数atan2(),我无法成功实现这一点,因为如果我理解正确,atan2将返回正X轴与从圆心到单击点的光线之间的角度。但是我需要点击点和y轴之间的角度 我附上图片,以防它更有意义: 我目前拥有的是: // Calcualte the deltas for point X and Y which are required for atan2 function le

我正在尝试计算弧长,以便在给定弧长的情况下为圆边界着色

用户可以单击圆边,代码应自动计算从位置开始的弧长
y=radius
x=cx
。给定函数
atan2()
,我无法成功实现这一点,因为如果我理解正确,
atan2
将返回正X轴与从圆心到单击点的光线之间的角度。但是我需要点击点和y轴之间的角度

我附上图片,以防它更有意义:

我目前拥有的是:

// Calcualte the deltas for point X and Y which are required for atan2 function
let deltaX = event.pageX - this.centerX
let deltaY = event.pageY - this.centerY

// The Math.atan2() function returns the angle in the plane (in radians) between the positive x-axis and the ray from (0,0) to the point (x,y), for Math.atan2(y,x)
let angleRadian = Math.atan2(deltaY, deltaX)
// Apply formula to calculate Arc length
let arcLength = radius * angleRadian

我知道atan2会像我上面所描述的那样计算角度,但我不知道如何修改我的代码以实现我需要它做的事情-即,获取单击点与y轴之间的角度。

只需交换
atan2
参数即可从y轴获取角度。 对于逆时针(CCW)系统:

(根据公式
cos(a)=sin(Pi/2-a),sin(a)=cos(Pi/2-a)

对于顺时针(CW)系统,其中OY轴方向为向下:

let angleRadian = Math.atan2(deltaX, -deltaY)

我已经试过了,但不起作用。我认为我也应该处理一些
deltaY
deltaX
为负值的情况,但我不确定如何处理。它肯定有效。但是你的Y轴方向是什么?向上还是向下?也许你们和坐标系纠缠不清。在顺时针系统中,您还必须更改一个参数的符号。处理负偏移取决于您的目的-也许您可以使用结果的绝对值。如果您看我问题中的图片,方向是顺时针的。因此,当用户单击圆时,应根据y=半径和用户按顺时针方向单击的点计算圆弧。我看到cx=200,cy=200表示小圆,因此决定您指的是CCW系统。使用
atan2(deltaX,-deltaY)
用于CW系统哦,对不起,我只是使用了我在web上看到的用于此类方程的“命名”。对于cx和cy,我指的是圆的“中心”,不一定在0,0点。
let angleRadian = Math.atan2(deltaX, -deltaY)