JUNGで頂点の周りに円を描く必要があります。円は頂点を中心とし、半径 r で定義されます。
1013 次
1 に答える
0
このようなものだと思います。これにより、指定された円のポイントが得られ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
}
EDIT : JUNG は実際には XY プロットではなく、ネットワーク/グラフ フレームワークのようです。したがって、必要なのは、提供されているレイアウトの 1 つを使用して円内にポイントをレイアウトすることだけです。多くのノードがある場合に奇妙な結果が得られますが、トリックを行うようですCircleLayout
。完全なサンプル コードは次のとおりです。KKLayout
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);
それがJUNGチュートリアルSparseMultiGraph
にあったものなので、私は選びました。他の種類のグラフもありますが、違いがわかりません。
StaticLayout
頂点を取ることができるa を使用し(x,y)
てから、元のコードを使用してポイントをプロットすることもできますが、JUNG フレームワークにはそれほどエレガントではありません。ただし、要件によって異なります。
于 2011-01-13T13:52:44.587 に答える