Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/lamont/test/implicit-surface/unit-circle.diderot
ViewVC logotype

Annotation of /branches/lamont/test/implicit-surface/unit-circle.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2132 - (view) (download)

1 : lamonts 2131 // unit-circle
2 :     //
3 :     // Demo of distributing particles on the unit circle
4 :     //
5 :     int numOfParticles = 1000;
6 :    
7 :    
8 :     strand Particle (int i) {
9 : lamonts 2132 output vec2 pos = [0.0,0.0];
10 : lamonts 2131
11 :     real isoval = 1;
12 :     int steps = 0;
13 :    
14 :     update {
15 : lamonts 2132 real energy = 0.0;
16 :     real force = 0.0;
17 :     real raduis =0.01;
18 : lamonts 2131
19 : lamonts 2132 for(Particle neighbor in sphere(raidus) {
20 :     real d = distance (pos,neighbor.pos);
21 :     if(d > 0) {
22 :     if(d >= 0 && d <= 1) {
23 :     force += -4.0 * ((1 - d)^3);
24 :     energy += ((1 - d)^4);
25 :     }
26 :     }
27 :     }
28 :    
29 :    
30 :    
31 : lamonts 2131 vec2 grad = ∇F(pos);
32 :     if (|grad| == 0.0) { // can't compute step if |∇F|, so have to bail
33 :     die;
34 :     }
35 :     vec2 norm = normalize(grad);
36 :     vec2 delta = -((F(pos) - isoval)/|grad|)*norm; // Newton-Raphson step
37 :     if (|delta| < epsilon) { // we've converged if step is small enough
38 :     stabilize;
39 :     }
40 :     pos += stepScale * delta;
41 :     steps += 1;
42 :     }
43 :     }
44 :     initially {Particle(i) | i in 0 .. numOfParticles-1 };
45 :    

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0