仅在象限I和IV中均匀分布圆周上的点 [英] Distribute points evenly on circle circumference in quadrants I and IV only

查看:187
本文介绍了仅在象限I和IV中均匀分布圆周上的点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想仅在象限I和IV中均匀分布 n 点数。



参数,我有点数 n ,圈子坐标的中心 cx cy 和半径 r



我可以在整个圆周上分配点使用下面的公式,但我正在寻找的公式只能在象限I和IV中分布它们

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

//我将这个数组中每个点的坐标存储在
下面的数组中var coordinates = [];

for(var i = 0; i< n; i ++){
//定义点的角度与辐射的圆的中心
//这个角度分布在所有4个象限上均匀分布
var angle =((360 / n)* i)*(Math.PI / 180);

//计算圆周上的点坐标
var pointX = cx + r * Math.cos(angle);
var pointY = cx + r * Math.sin(angle);

//存储点的坐标
coordinates.push([pointX,pointY]);
}


解决方案

'需要解决这个问题:


  1. 找到角度。每个点 var incrementBy = 180 / n

  2. 开始角度为270º,结束角度为90º
  3. 通过

代码进行迭代

  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(angle)
var ty = cy + r * Math.sin(angle)

coords.push([tx,ty])
}

note



我没有为传统象限转换(vs JS的y轴向下移动)。如果需要,那么在计算之后,只需反转 ty 值。当您增加到四分之一时,我也不会在超过360º时减小角度值。

I want to distribute n points evenly on a circle circumference in quadrants I and IV only.

As parameters, I have the numbers of point n, the center of circle coordiantes cx and cy and the radius r.

I can distribute the points over the whole circumference like using this formula below, but I am looking for the formula to spread them only in quadrants I and 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]);
}

解决方案

Here would be the steps I'd take to solve this:

  1. find the angle betw. each point var incrementBy = 180 / n
  2. start angle will be 270º and end angle will be 90º
  3. iterate through via

code

 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(angle)
     var ty = cy + r * Math.sin(angle)

     coords.push([tx, ty])
 }

note

I didn't bother to convert for traditional quadrants (vs JS's y-axis moving downwards). If that is needed then, after your calculations, just invert the ty value. I also didn't bother to reduce the angle value when it exceeds 360º when you're incrementing back into Quad I.

这篇关于仅在象限I和IV中均匀分布圆周上的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆