使用带有偏移圆的 atan2

Using atan2 with offset circle

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

用户可以点击圆边,代码应该会自动计算从位置 y=radius x=cx 开始的弧长。给定函数 atan2(),我无法成功实现,因为如果我理解正确,atan2 return 正 X-axis 与从我的圆心到单击的点。但是我需要点击点和 y-axis.

之间的角度

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

我目前拥有的是:

// 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-axis.

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

let angleRadian = Math.atan2(deltaX, deltaY)

(基于公式cos(a)=sin(Pi/2-a), sin(a)=cos(Pi/2-a)

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

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