2011-01-13 2 views

답변

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 
} 

편집 : 그것은 JUNG는 정말 XY 플롯하지만 네트워크/그래프 프레임 워크하지 않은 것 같습니다. 필요한 레이아웃은 제공된 레이아웃 중 하나를 사용하여 원에 점을 배치하는 것뿐입니다. CircleLayoutKKLayout은 많은 수의 노드가있는 경우에 이상한 결과를 보여 주지만 그 트릭을 수행하는 것처럼 보입니다. 그 JUNG tutorial에 무엇 때문에 내가 SparseMultiGraph를 잡혔습니다

//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); 

: 여기에 완전한 샘플 코드입니다. 다른 유형의 그래프가 있지만 그 차이점을 알 수는 없습니다.

또한 (x,y) 정점을 취할 수있는 StaticLayout을 사용할 수 있습니다. 그런 다음 원래 코드를 사용하여 점을 그릴 수 있지만 JUNG 프레임 워크에서는 그다지 우아하지 않습니다. 그러나 귀하의 요구 사항에 달려 있습니다.

+0

흠, 나는 JFrame을 사용하여 JUNG이 기존의 음모에 이것을 어떻게 적용 할까? – mamruoc

+0

죄송 합니다만 JUNG에게 익숙하지 않습니다. 이전의'(x, y)'정점을 변수에 저장하고 루프에서 이전과 현재 사이의 가장자리를 만들어야합니다. 그런 다음 그래프에 가장자리를 추가하십시오. 정확한 API에 대해 잘 모르겠습니다. 나는 그것을 보일 것이다. 그러나 다른 누군가가 올바른 API 사용법을 가지고 답을 게시한다면 좋을 것이다. 누군가? – rodion

+0

나는 이것을 받아 들일 것이다. 나는 일하게 만들었지 만 나는 정을 사용하지 않았다. – mamruoc