# condensation3.R # # Written by Chris McCarthy, Mathematics, Borough of Manhattan Community College, New York NY # ####################################### # Function Definitions ####################################### ####################################### 3 moveP3 = function(p,sites, dt = .3, directionChange = .2, # maxX = 100, maxY = 100, edge = .2, tol = 2){ theta = runif(1, 0, 2*pi); pout = p; if(runif(1,0,1) < directionChange){ s = sqrt(p[3]^2 + p[4]^2); pout[3] = cos(theta)*s; pout[4] = sin(theta)*s; } pout[1] = p[1] + pout[3]*dt; pout[2] = p[2] + pout[4]*dt; if( (pout[1] < edge) || (pout[1] > (maxX- edge)) ){ pout[3] = -pout[3]; pout[1] = p[1] + pout[3]*dt; } if( (pout[2] < edge) || (pout[2] > (maxY - edge) ) ){ pout[4] = -pout[4]; pout[2] = p[2] + pout[4]*dt; } if(min(apply(sites, 1, function(s){sum(abs(s- p[1:2] + p[5]))}))