Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- ) );
Add Comment
Please, Sign In to add comment