/**
* @description: 星形
* @param {number} n 边数 3-n
* @param {number} r1 大圈
* @param {number} r2 小圈
*/
star(n: number, rx1: number, rx2: number, ry1: number, ry2: number) {
const points = []
const cor = 360 / n / 2
const rightAngle = n % 2 === 0 ? 360 / n : 360 / (n * 2)
for (let i = 0; i <= n; i++) {
const x1 = rx1 * Math.sin(((rightAngle + 2 * i * cor) / 180) * Math.PI)
const y1 = ry1 * Math.cos(((rightAngle + 2 * i * cor) / 180) * Math.PI)
//画第二条边
const x2 = rx2 * Math.sin(((rightAngle + (2 * i + 1) * cor) / 180) * Math.PI)
const y2 = ry2 * Math.cos(((rightAngle + (2 * i + 1) * cor) / 180) * Math.PI)
points.push({ x: x1, y: y1 })
if (i !== n) {
points.push({ x: x2, y: y2 })
}
}
return { points }
}
调用
this.star(5, width / 2, (width / 2) * 0.4, height / 2, (height / 2) * 0.4)