仅在象限I和IV的圆周上均匀分布点

时间:2016-05-10 17:58:17

标签: javascript geometry algebra

我想将n点均匀地分布在象限I和IV的圆周上。

作为参数,我有点n的数字,圆坐标cxcy的中心以及半径r

我可以在整个圆周上分配点,就像使用下面这个公式一样,但我正在寻找公式,只在象限I和IV中传播它们

var n = 5;
var cx = 1;
var cy = 1;
var r = 2;

//I store each point's coordinates in this array below
var coordinates = [];

for (var i=0; i < n; i++) {
    //defining point's angle with the center of the circle in radiant
    //this angle distribute the points evenly over all 4 quadrants
    var angle = ((360/n) * i) * (Math.PI/180);

    //calculating the point's coordinates on the circle circumference
    var pointX = cx + r * Math.cos(angle);
    var pointY = cx + r * Math.sin(angle);

    //storing the point's coordinates
    coordinates.push([pointX, pointY]);
}

4 个答案:

答案 0 :(得分:2)

以下是解决这个问题的步骤:

  1. 找到角度。每个点 $.post("http://192.168.1.15/fou/promoCre.php",{nom_restaurant:nom_restaurant},function(data){ alert(data); })
  2. 起始角度为270º,终止角度为90º
  3. 遍历通过
  4. <强>码

    var incrementBy = 180 / n

    注意

    我没有费心去转换传统的象限(相比JS的y轴向下移动)。如果需要,那么在计算之后,只需反转 var increment = 180 / n var startAngle = 270 for (var i = 0; i < n; i++) { var angle = startAngle + increment * i var rads = angle * Math.pi / 180 var tx = cx + r * Math.cos(rads) var ty = cy + r * Math.sin(rads) coords.push([tx, ty]) } 值。当你增加回Quad I时,当它超过360º时,我也没有费心去减小角度值。

答案 1 :(得分:1)

像这样?

var n = 5;
var r = 2;
var cx = 1;
var cy = 1;
var coordinates = [];

for(var i=0; i<n; ++i){
  var a = (i+.5) / n * Math.PI;
  coordinates.push([
    cx + Math.sin(a) * r,
    cy - Math.cos(a) * r
  ]);
}

答案 2 :(得分:1)

这是平均分配对象的方法

var boxes = []
let count = 10;
for (let i = 0; i < count; i++) {
let size = 0.8;
let radius = 3;
let box = new THREE.Mesh(new THREE.BoxGeometry( size, size, size ),new THREE.MeshPhysicalMaterial(0x333333))
let gap = 0.5;
let angle = i * ((Math.PI * 2) / count);
let x = radius * Math.cos(angle);
let y = 0;
let z = radius * Math.sin(angle);
box.position.set(x,y,z);
boxes.push(box);`enter code here`
scene.add(box)
}

here is how it looks for 10 blocks

here is how it looks for 5 blocks

答案 3 :(得分:0)

var n = 5;
var cx = 1;
var cy = 1;
var r = 2;

//I store each point's coordinates in this array below
var coordinates = [];

for (var i=0; i < n; i++) {
    //defining the angle of the point with the center of the circle in radiant
    var angle = ((360/n) * i) * (Math.PI/180);

    //calculating the coordinates of the point on the circle circumference
    var pointX = cx + r * Math.cos(angle);
    var pointY = cx + r * Math.sin(angle);



    // Here, we are going to use a boolean expression to determine if 
    // [pointX, pointY] is within quadrant 1 or 4.
    // We can start with this boolean equation:
    // (pointX >= cx && pointY >= cy) || (pointX >= cx && pointY <= cy)
    // But this problem can be simplified to only pointX >= cx

    if(pointX >= cx){
        //storing the point's coordinates
        coordinates.push([pointX, pointY]);
    } 
}