基础公式:r * cos(angle) = x ; r * sin(angle) = y;
核心方法参考扩展了下,根据角度话等多边形
function Circle(x, y, r) {
this.mPointX = x;
this.mPointY = y;
this.mRadius = r;
}
function Point(x, y) {
this.x = x || 0;
this.y = y || 0;
}
Circle.prototype.getPointOnCircle = function (angle) {
let mPointX = this.mPointX;
let mRadius = this.mRadius;
let mPointY = this.mPointY;
let lth = 360/angle;
let startangle = parseInt(Math.random() * angle);
let list = []
for(let i = 0; i<lth; i++) {
list.push(new Point(mPointX + (mRadius * Math.cos((angle * i + startangle) * Math.PI / 180)),
mPointY + (mRadius * Math.sin((angle * i + startangle) * Math.PI / 180))))
}
return list
}
var circle = new Circle(10,20,50);
var p = circle.getPointOnCircle(process.argv[2] || 10);
console.log(p)
更多