【发布时间】:2021-02-24 14:04:13
【问题描述】:
我正在尝试计算弧长,以便在给定弧长的情况下为圆形边框着色。
用户可以点击圆的边缘,代码应该会自动计算从位置y=radiusx=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 轴之间的角度.
【问题讨论】:
标签: javascript geometry trigonometry