【问题标题】:Plotting a third point given two points and a desired angle for the third point (and possibly a distance)在给定两个点和第三个点的所需角度(可能还有距离)的情况下绘制第三个点
【发布时间】:2019-08-28 10:12:59
【问题描述】:

给定两个点 (A, B) 和我希望第三个点所在的角度,我正在尝试绘制第三个点 (C)。我可能还需要一个距离长度来绘制第三个点,但让我们假设它现在是固定的。如何取 pontA (a.x, a.y)、pointB (b.x, b.y) 和(例如)45 度角并从中绘制第三点 (C)。

【问题讨论】:

  • 可能涉及到一些三角函数......你试过什么?

标签: javascript plot trigonometry angle


【解决方案1】:

这是一个三角问题。

// 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)


注意:角度应该是弧度才能起作用。

【讨论】:

  • 谢谢!你能想出一种方法来知道你是顺时针还是逆时针?考虑到 A-B 线可以在任何方向。
  • 我在帖子中所说的顺时针和逆时针是指角度 ABC(“已知角度”)是顺时针还是逆时针。从你上面的图片看,它似乎是顺时针的。
  • 如果 A-B 线在平面上,但当 A-B 线垂直或倾斜时,您的代码对我有用。我现在正在研究解决方案,并将发布我正在使用的代码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-02
  • 1970-01-01
  • 2021-04-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多