我有一个等边三角形。我知道圆心(S)、所有顶点(A、B、C)的坐标以及圆半径(r)的长度。如何获得位于三角形边 (a) 上均匀分布(例如,彼此距离相同)的可变数量的点 [X1, X2, X3, ...] 的坐标?有公式吗?
您可以使用向量来做到这一点
// calculating A, B, C, you can ignore that part
const a = 1
const h = a * Math.sqrt(3) / 2
const R = 2 / 3 * h
const A = { x: 0, y: R }
const B = { x: -a / 2, y: h / 3 }
const C = { x: a / 2, y: h / 3 }
console.log('A=', A, 'B=', B, 'C=', C)
// number of points on each side
const parts = 3
const sides = [[A, B], [B, C], [C, A]]
const points = []
for (const [f, s] of sides) {
// for each side calculate a vector (e.g. A -> B)
const v = { x: s.x - f.x, y: s.y - f.y }
for (let i = 1; i <= parts; i += 1) {
// calculate position of each points
// e.g. (A + ABvector * 1/3)
const p = { x: f.x + v.x / parts * i, y: f.y + v.y / parts / i }
points.push(p)
}
}
console.log('points=', points)