Created
May 20, 2012 22:32
-
-
Save bmander/2759768 to your computer and use it in GitHub Desktop.
sphere bulged with gaussian
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dist(x,y,z){ | |
return Math.pow(Math.pow(x,2)+Math.pow(y,2)+Math.pow(z,2),0.5); | |
} | |
function max(a,b){ | |
if(a>b){ | |
return a; | |
}else{ | |
return b; | |
} | |
} | |
function min(a,b){ | |
if(a<b){ | |
return a; | |
} else { | |
return b; | |
} | |
} | |
function bulge(cx,cy,cz,stddev,amp,func){ | |
return function(x,y,z){ | |
//distance from point to center | |
var dd = (dist(x-cx,y-cy,z-cz)); | |
//normal vector from point to center | |
var ux = (cx-x)/dd; | |
var uy = (cy-y)/dd; | |
var uz = (cz-z)/dd; | |
var indraw=amp*(Math.exp(-Math.pow(dd/stddev,2))); | |
indraw = min(dd,indraw); | |
var xp = x+indraw*ux; | |
var yp = y+indraw*uy; | |
var zp = z+indraw*uz; | |
return func(xp,yp,zp); | |
} | |
} | |
function makesphere(r){ | |
return function(x,y,z){ | |
return Math.pow(x,2) + Math.pow(y,2) + Math.pow(z,2) < Math.pow(r,2); | |
} | |
} | |
emit( bulge(99,0,0,62,100, | |
makesphere(100) | |
) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment