n点圆上的近似位置 [英] Approximate position on circle for n points

查看:189
本文介绍了n点圆上的近似位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力解决以下问题:
我得到了 n 点和一个半径,我必须将它们放在尽可能对称的圆上。



目前,我使用的是这样的:

  float theta = 360.0f / n; 
int i = 0;
for(Word w:e.getValue()){
double newX = Math.sin(theta * i)* RADIUS + I_OFFSET_X;
double newY = Math.cos(theta * i)* RADIUS + I_OFFSET_Y;
mxCell v2 =(mxCell)graph.insertVertex(parent,null,w.getValue(),newX,newY,OW_WIDTH,OW_HEIGHT,shape = ellipse);
graph.insertEdge(parent,null,,v1,v2);
i ++;

其中 n 是我的点数。



例如,这适用于足够大的n,但对于 n = 3 我得到如下所示:





实际上我喜欢这样的内容:


(坏的绘画技巧不好..)



所以基本上,尽可能对称的东西会很棒。



关于如何解决这个问题的任何提示?



感谢< 3

解决方案

感谢Jongware,答案很明显。因为我正在处理Java,所以 sin / cos 参数应该以弧度表示。
修正:

  double newX = Math.sin(Math.toRadians(theta * i))* RADIUS + I_OFFSET_X ; 
double newY = Math.cos(Math.toRadians(theta * i))* RADIUS + I_OFFSET_Y;

像魅力一样工作


I am struggling with the following problem: I am given n points and a radius and I have to place them on a circle as symmetrical as possible.

Currently, I used something like this:

float theta = 360.0f / n;
int i = 0;
for (Word w : e.getValue()) {
    double newX = Math.sin(theta * i) * RADIUS + I_OFFSET_X;
    double newY = Math.cos(theta * i) * RADIUS + I_OFFSET_Y;
    mxCell v2 = (mxCell) graph.insertVertex(parent, null, w.getValue(), newX, newY, OW_WIDTH, OW_HEIGHT,"shape=ellipse");
    graph.insertEdge(parent, null, "", v1, v2);
    i++;
}

where n is my number of points.

This works fine for a large enough n, but for n=3 for example, I get something like:

I would actually like to have something like:

(bad drawing skills are bad..)

So basically, something as symmetric as possible would be awesome.

Any hints on how to solve this?

Thanks <3

解决方案

Thanks to Jongware, the answer was quite obvious. Because I'm dealing with Java, all the sin/cos parameters should be in radians. Fix:

double newX = Math.sin(Math.toRadians(theta * i)) * RADIUS + I_OFFSET_X;
double newY = Math.cos(Math.toRadians(theta * i)) * RADIUS + I_OFFSET_Y;

Works like a charm

这篇关于n点圆上的近似位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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