1 | static void forceBasedLayout(CirclesAndLines cal, final Canvas canvas) { |
2 | awtEvery(canvas, r { |
3 | L<Circle> circles = cal.circles; |
4 | int n = l(circles); |
5 | |
6 | new BitSet bs; |
7 | for (Line l : cal.lines) |
8 | bs.set(circles.indexOf(l.a)*n+circles.indexOf(l.b)); |
9 | |
10 | for (int i = 0; i < n; i++) { |
11 | Circle a = circles.get(i); |
12 | for (int j = 0; j < n; j++) |
13 | if (i != j) { |
14 | Circle b = circles.get(j); |
15 | bool connected = bs.get(i*n+j); |
16 | if (connected) |
17 | forceBasedLayout_attract(a, b); |
18 | else |
19 | forceBasedLayout_repel(a, b); |
20 | } |
21 | showCAL2(cal, cal, canvas); |
22 | } |
23 | } |
24 | |
25 | static Vector forceBasedLayout_repulsionForce(Circle a, Circle b) { |
26 | po proximity = max(distance(a.x, a.y, b.x, b.y), 0.1); |
27 | double force = -REPULSION_CONSTANT / sqr(proximity); |
28 | double angle = GetBearingAngle(x.Location, y.Location); |
29 | return doublePtFromAngle(force, angle); |
30 | } |
31 | |
32 | svoid forceBasedLayout_attract(Circle a, Circle b) { |
33 | double distance = sqr(b.x-a.x)+sqr(b.y-a.y); |
34 | double desiredDistance = 0.1; |
35 | double distanceDelta = desiredDistance |
36 | |
37 | double dx = (b.x-a.x)*strength, dy = (b.y-a.y)*strength; |
38 | a.x += dx* |
39 | } |
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: | 506 / 506 |
Version history: | 1 change(s) |
Referenced in: | [show references] |