你如何通过查看我的鼠标光标找到基于圆的边缘的 x,y 坐标

How do you find x,y coordinate of based on the edge of a circle by looking at my mouse cursor

我试图根据我的鼠标位置在圆的边缘内基于三角函数找到 x,y 坐标。

从gif图中可以看出,当你的鼠标移动时,三角形的尖端总是指向圆的边缘,而我的鼠标在椭圆周围移动。

我正在使用 P5.js,我想知道如何写这个,如果你能带我了解这背后的三角学,我将不胜感激,这样我就可以利用这些知识并尝试更多类型的可视化编程思想在我的脑海里。

计算从圆心 (cx, cy) 到鼠标位置 (mouseX, mouseY). Use p5.Vector respectively createVector() to represent the vector and change the magnitude of the vector to the radius of the circle by setMag():

的矢量
let v = createVector(mouseX - cx, mouseY - cy).setMag(radius);
let px = v.x + cx;
let py = v.y + cy;

分别

let cpt = createVector(cx, cy);
let pt = createVector(mouseX, mouseY).sub(cpt).setMag(radius).add(cpt);
let px = pt.x;
let py = pt.y;