VisClient/org/hfbk/vis/visnode/VisKeycloud.java

Go to the documentation of this file.
00001 /*
00002  * Created on 27.04.2008
00003  */
00004 package org.hfbk.vis.visnode;
00005 
00006 import org.dronus.graph.Node;
00007 import org.lwjgl.util.vector.Vector3f;
00008 
00016 public class VisKeycloud extends VisNode {
00017 
00018         final float RADIUSFACTOR=15;
00019         
00020         public VisKeycloud(Node node, Vector3f position) {
00021                 super(node, position);
00022         }
00023         
00024         
00025         void renderSelf() {
00026                 if (layoutLocked) return;
00027                 
00028                 /*
00029                  * we now try to space the keywords regulary on a sphere.
00030                  * therefore we assume the sphere surface as a 2d plane
00031                  * and place the keywords approx equidistant in it. as
00032                  * the plane is spherical bend, this don't result in a regular 
00033                  * grid. we prior the lattitudes so they get a truly equidistant
00034                  * spacing and fill them with a longitudal grid til circle 
00035                  * completes. By carefully adjusting the sphere radius we
00036                  * make sure all keywords find theire place.  
00037                  */
00038                 
00039                 int n=children.size();
00040                 
00041                 //compute the distance of keywords on the 2d surface of the 3d sphere
00042                 double dist=Math.PI*2/(Math.floor(Math.sqrt(n*4))+1);
00043                 
00044                 //compute needed radius for sphere
00045                 radius=RADIUSFACTOR*(float)Math.sqrt(n/4/Math.PI);
00046 
00047                 int i=0;
00048                 for (double lat=dist/2-Math.PI/2; lat<Math.PI/2 && i<n; lat+=dist) //lattitudal grid
00049                         for (double lon=dist/2; lon<Math.PI*2 && i<n; lon+=dist/(1-Math.abs(lat/Math.PI*2))){ //longitudal grid 
00050                                 
00051                                 children.get(i).position=new Vector3f(
00052                                                 (float)(radius*Math.cos(lat)*Math.cos(lon)),
00053                                                 (float)(radius*-Math.sin(lat)),
00054                                                 (float)(radius*Math.cos(lat)*-Math.sin(lon))
00055                                 );
00056                                 i++;
00057                         }
00058                 
00059                 layoutLocked=true;
00060         }
00061 
00062 }

Generated on Tue Apr 7 17:57:21 2009 for visclient by  doxygen 1.5.1