質問

頂点の周りに円を描く必要があります ユング. 。円は、頂点によって中心として定義され、特定の半径rが定義されます。

役に立ちましたか?

解決

このようなものだと思います。これにより、指定されたサークルのポイントが得られます radius. 。ポイントの解像度を調整するには、変更されます x+=0.01 必要に応じて、より大きな/小さい値に。サークル中心を任意のポイントに移動します (p,q), 、それを追加するだけです (x,y), 、 あれは plot(x+p,y+q);.

double radius = 3;
for (double x = -radius; x <= radius; x += 0.01) {
    double y = Math.sqrt(radius * radius - x * x);
    plot(x, y);//top half of the circle
    plot(x, -y);//bottom half of the circle
}

編集: :Jungは実際にはXYプロットではなく、ネットワーク/グラフフレームワークであるように見えます。したがって、必要なのは、提供されたレイアウトの1つを使用して、ポイントを円にレイアウトすることだけです。 CircleLayoutKKLayout しかし、トリックをしているようです CircleLayout 多くのノードがある場合、奇妙な結果をもたらします。これが完全なサンプルコードです:

//Graph holder
Graph<Integer, String> graph = new SparseMultigraph<Integer, String>();

//Create graph with this many nodes and edges
int nodes = 30;
for (int i = 1; i <= nodes; i++) {
    graph.addVertex(i);
    //connect this vertext to vertex+1 to create an edge between them.
    //Last vertex is connected to the first one, hence the i%nodes
    graph.addEdge("Edge-" + i, i, (i % nodes) + 1);
}

//This will automatically layout nodes into a circle.
//You can also try CircleLayout class
Layout<Integer, String> layout = new KKLayout<Integer, String>(graph);
layout.setSize(new Dimension(300, 300)); 

//Thing that draws the graph onto JFrame
BasicVisualizationServer<Integer, String> vv = new BasicVisualizationServer<Integer, String>(layout);
vv.setPreferredSize(new Dimension(350, 350)); // Set graph dimensions

JFrame frame = new JFrame("Circle Graph");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(vv);
frame.pack();
frame.setVisible(true);

私は選んだ SparseMultiGraph それがあったからです Jungチュートリアル. 。他の種類のグラフがありますが、違いが何であるかはわかりません。

aを使用することもできます StaticLayout それにはかかることがあります (x,y) 頂点は、元のコードを使用してポイントをプロットしますが、それはJungフレームワークにとってそれほどエレガントではありません。ただし、要件が何であるかによって異なります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top