static void forceBasedLayout(CirclesAndLines cal, final Canvas canvas) {
awtEvery(canvas, r {
L<Circle> circles = cal.circles;
int n = l(circles);
new BitSet bs;
for (Line l : cal.lines)
bs.set(circles.indexOf(l.a)*n+circles.indexOf(l.b));
for (int i = 0; i < n; i++) {
Circle a = circles.get(i);
for (int j = 0; j < n; j++)
if (i != j) {
Circle b = circles.get(j);
bool connected = bs.get(i*n+j);
if (connected)
forceBasedLayout_attract(a, b);
else
forceBasedLayout_repel(a, b);
}
showCAL2(cal, cal, canvas);
}
}
static Vector forceBasedLayout_repulsionForce(Circle a, Circle b) {
po proximity = max(distance(a.x, a.y, b.x, b.y), 0.1);
double force = -REPULSION_CONSTANT / sqr(proximity);
double angle = GetBearingAngle(x.Location, y.Location);
return doublePtFromAngle(force, angle);
}
svoid forceBasedLayout_attract(Circle a, Circle b) {
double distance = sqr(b.x-a.x)+sqr(b.y-a.y);
double desiredDistance = 0.1;
double distanceDelta = desiredDistance
double dx = (b.x-a.x)*strength, dy = (b.y-a.y)*strength;
a.x += dx*
}download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1009845 |
| Snippet name: | forceBasedLayout [dev.] |
| Eternal ID of this version: | #1009845/2 |
| Text MD5: | 696e9f899a68886b26af84142a46d4eb |
| Author: | stefan |
| Category: | javax / a.i. / gui |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2017-08-21 16:20:41 |
| Source code size: | 1223 bytes / 39 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 915 / 914 |
| Version history: | 1 change(s) |
| Referenced in: | -