From 52bf3a5b4642b8b197a26c88780f7c77e23a5d22 Mon Sep 17 00:00:00 2001 From: Grimmware Date: Thu, 12 May 2022 16:15:00 +0000 Subject: [PATCH] Added a bunch of as-of-yet unused and untested code to add repulsion between sephirah --- sim.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/sim.c b/sim.c index e5752b4..8865f56 100644 --- a/sim.c +++ b/sim.c @@ -55,9 +55,7 @@ resolve_path(int i) float force_x, force_y; len_x = fabs(upper->xy.x - lower->xy.x); - if(debug) print("%d: len_x is %f\n", i, len_x); len_y = fabs(upper->xy.y - lower->xy.y); - if(debug) print("%d: len_y is %f\n", i, len_y); // The target length will be a multiple of the original length. If we can figure out this multiple we can then use it to find the resolved target x and y lengths separately, so we use pythagoras to find the total length from the individual lenght components and divide it by the target length path_len = sqrt(pow(len_x, 2.0) + pow(len_y, 2.0)); @@ -89,6 +87,29 @@ resolve_path(int i) } } +void +resolve_emanation(int i, int n, float charge){ + int delta_x, delta_y, radius_sq; + float force, force_x, force_y, angle; + Emanation *e = emanations[i]; + + for(int j=0; jxy.x - emanations[j]->xy.x; + delta_y = e->xy.y - emanations[j]->xy.y; + angle = atan(delta_y/delta_x); + if(debug) print("Angle between %d and %d is %f\n", i, j, angle); + radius_sq = pow(delta_x, 2) + pow(delta_y, 2); + // Reduction of coulomb's law with coefficients boiled out + force = pow(charge, 2) / radius_sq; + force_x = force * cos(angle); + force_y = force * sin(angle); + emanations[j]->force_x += force_x; + emanations[j]->force_y += force_y; + } + } +} + void tick(void) { @@ -106,6 +127,8 @@ tick(void) void main(int argc, char** argv) { + int n; + ARGBEGIN{ case 'D': debug++; @@ -143,6 +166,12 @@ main(int argc, char** argv) //print("Optimizing %s -> %s\n", paths[i]->lower->name, paths[i]->upper->name); resolve_path(i); } + /* We're not ready for this bit yet + for(n = 0; emanations[n]; n++); + for(int i = 0; i < n; i++){ + resolve_emanation(i, n, 10.0); + } + */ tick(); } dumpstate(outstatefile); -- 2.38.5