@@ 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));
@@ 90,6 88,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; j<n; j++){
+ if(j != i){
+ delta_x = e->xy.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)
{
for(int i = 0; emanations[i]; i++){
@@ 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);