我正在尝试绘制第三个点 (C),给定两个点 (A, B) 和我希望第三个点所在的 Angular 。我可能还需要一个距离长度来绘制第三个点,但我们假设它现在是固定的。我如何取 pontA (a.x, a.y)、pointB (b.x, b.y) 和一个(例如)45 度 Angular ,并从中绘制第三个点 (C)。
最佳答案
这是一个三 Angular 问题。
// angle = the known angle
// dist = the distance from b to c
let angleAB = Math.atan2(a.y - b.y, a.x - b.x);
// if c is counterclockwise from a
c.x = b.x + dist*Math.cos(angleAB + angle)
c.y = b.y + dist*Math.sin(angleAB + angle)
// if c is clockwise from a
c.x = b.x + dist*Math.cos(angleAB - angle)
c.y = b.y + dist*Math.sin(angleAB - angle)
注意: Angular 应以弧度为单位才能正常工作。
关于javascript - 给定两点和第三点的所需 Angular (可能还有距离)绘制第三点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57682897/