Skip to content

Instantly share code, notes, and snippets.

@mkeeter
Created Jun 28, 2012
Embed
What would you like to do?
Javascript function to build involute gear
function gear(x,y){
X = (x - 250) * 0.75/500
Y = (y - 250) * 0.75/500
return (((((X-(0))*(X-(0)) + (Y-(0))*(Y-(0))) <= (0.2665*0.2665))) || (((((X-(0))*(X-(0)) + (Y-(0))*(Y-(0))) <= (0.325*0.325))) && !((((((((((((((Math.atan2(Y, X)<=-3.08509824571||Math.atan2(Y, X)>=3.08509824571)) || (((Math.atan2(Y, X)<=0.0564944078792&&Math.atan2(Y, X)>=-0.0564944078792)) || (((0.286*(Math.atan((-Math.sin(0.0564944078792)*X+Math.cos(0.0564944078792)*Y)/(Math.cos(0.0564944078792)*X+Math.sin(0.0564944078792)*Y)) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0) && ((0.286*(Math.atan((-Math.sin(0.0564944078792)*X+Math.cos(0.0564944078792)*(0-Y))/(Math.cos(0.0564944078792)*X+Math.sin(0.0564944078792)*(0-Y))) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0)))) || (((Math.atan2(Y, X)<=-2.82329885791&&Math.atan2(Y, X)>=-2.93628767367)) || (((Math.atan2(Y, X)<=0.318293795678&&Math.atan2(Y, X)>=0.20530497992)) || (((0.286*(Math.atan((-Math.sin(0.318293795678)*X+Math.cos(0.318293795678)*Y)/(Math.cos(0.318293795678)*X+Math.sin(0.318293795678)*Y)) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0) && ((0.286*(Math.atan((-Math.sin(0.0564944078792)*(Math.cos(0.261799387799)*X+Math.sin(0.261799387799)*Y)+Math.cos(0.0564944078792)*(0-(-Math.sin(0.261799387799)*X+Math.cos(0.261799387799)*Y)))/(Math.cos(0.0564944078792)*(Math.cos(0.261799387799)*X+Math.sin(0.261799387799)*Y)+Math.sin(0.0564944078792)*(0-(-Math.sin(0.261799387799)*X+Math.cos(0.261799387799)*Y)))) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0))))) || (((Math.atan2(Y, X)<=-2.56149947011&&Math.atan2(Y, X)>=-2.67448828587)) || (((Math.atan2(Y, X)<=0.580093183477&&Math.atan2(Y, X)>=0.467104367719)) || (((0.286*(Math.atan((-Math.sin(0.580093183477)*X+Math.cos(0.580093183477)*Y)/(Math.cos(0.580093183477)*X+Math.sin(0.580093183477)*Y)) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0) && ((0.286*(Math.atan((-Math.sin(0.0564944078792)*(Math.cos(0.523598775598)*X+Math.sin(0.523598775598)*Y)+Math.cos(0.0564944078792)*(0-(-Math.sin(0.523598775598)*X+Math.cos(0.523598775598)*Y)))/(Math.cos(0.0564944078792)*(Math.cos(0.523598775598)*X+Math.sin(0.523598775598)*Y)+Math.sin(0.0564944078792)*(0-(-Math.sin(0.523598775598)*X+Math.cos(0.523598775598)*Y)))) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0))))) || (((Math.atan2(Y, X)<=-2.29970008231&&Math.atan2(Y, X)>=-2.41268889807)) || (((Math.atan2(Y, X)<=0.841892571276&&Math.atan2(Y, X)>=0.728903755518)) || (((0.286*(Math.atan((-Math.sin(0.841892571276)*X+Math.cos(0.841892571276)*Y)/(Math.cos(0.841892571276)*X+Math.sin(0.841892571276)*Y)) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0) && ((0.286*(Math.atan((-Math.sin(0.0564944078792)*(Math.cos(0.785398163397)*X+Math.sin(0.785398163397)*Y)+Math.cos(0.0564944078792)*(0-(-Math.sin(0.785398163397)*X+Math.cos(0.785398163397)*Y)))/(Math.cos(0.0564944078792)*(Math.cos(0.785398163397)*X+Math.sin(0.785398163397)*Y)+Math.sin(0.0564944078792)*(0-(-Math.sin(0.785398163397)*X+Math.cos(0.785398163397)*Y)))) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0))))) || (((Math.atan2(Y, X)<=-2.03790069451&&Math.atan2(Y, X)>=-2.15088951027)) || (((Math.atan2(Y, X)<=1.10369195908&&Math.atan2(Y, X)>=0.990703143321)) || (((0.286*(Math.atan((-Math.sin(1.10369195908)*X+Math.cos(1.10369195908)*Y)/(Math.cos(1.10369195908)*X+Math.sin(1.10369195908)*Y)) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0) && ((0.286*(Math.atan((-Math.sin(0.0564944078792)*(Math.cos(1.0471975512)*X+Math.sin(1.0471975512)*Y)+Math.cos(0.0564944078792)*(0-(-Math.sin(1.0471975512)*X+Math.cos(1.0471975512)*Y)))/(Math.cos(0.0564944078792)*(Math.cos(1.0471975512)*X+Math.sin(1.0471975512)*Y)+Math.sin(0.0564944078792)*(0-(-Math.sin(1.0471975512)*X+Math.cos(1.0471975512)*Y)))) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0))))) || (((Math.atan2(Y, X)<=-1.77610130671&&Math.atan2(Y, X)>=-1.88909012247)) || (((Math.atan2(Y, X)<=1.36549134688&&Math.atan2(Y, X)>=1.25250253112)) || (((0.286*(Math.atan((-Math.sin(1.36549134688)*X+Math.cos(1.36549134688)*Y)/(Math.cos(1.36549134688)*X+Math.sin(1.36549134688)*Y)) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0) && ((0.286*(Math.atan((-Math.sin(0.0564944078792)*(Math.cos(1.308996939)*X+Math.sin(1.308996939)*Y)+Math.cos(0.0564944078792)*(0-(-Math.sin(1.308996939)*X+Math.cos(1.308996939)*Y)))/(Math.cos(0.0564944078792)*(Math.cos(1.308996939)*X+Math.sin(1.308996939)*Y)+Math.sin(0.0564944078792)*(0-(-Math.sin(1.308996939)*X+Math.cos(1.308996939)*Y)))) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0))))) || (((Math.atan2(Y, X)<=-1.51430191892&&Math.atan2(Y, X)>=-1.62729073468)) || (((Math.atan2(Y, X)<=1.62729073467&&Math.atan2(Y, X)>=1.51430191891)) || (((0.286*(Math.atan((-Math.sin(1.62729073467)*X+Math.cos(1.62729073467)*Y)/(Math.cos(1.62729073467)*X+Math.sin(1.62729073467)*Y)) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0) && ((0.286*(Math.atan((-Math.sin(0.0564944078792)*(Math.cos(1.57079632679)*X+Math.sin(1.57079632679)*Y)+Math.cos(0.0564944078792)*(0-(-Math.sin(1.57079632679)*X+Math.cos(1.57079632679)*Y)))/(Math.cos(0.0564944078792)*(Math.cos(1.57079632679)*X+Math.sin(1.57079632679)*Y)+Math.sin(0.0564944078792)*(0-(-Math.sin(1.57079632679)*X+Math.cos(1.57079632679)*Y)))) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0))))) || (((Math.atan2(Y, X)<=-1.25250253112&&Math.atan2(Y, X)>=-1.36549134688)) || (((Math.atan2(Y, X)<=1.88909012247&&Math.atan2(Y, X)>=1.77610130671)) || (((0.286*(Math.atan((-Math.sin(1.88909012247)*X+Math.cos(1.88909012247)*Y)/(Math.cos(1.88909012247)*X+Math.sin(1.88909012247)*Y)) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0) && ((0.286*(Math.atan((-Math.sin(0.0564944078792)*(Math.cos(1.83259571459)*X+Math.sin(1.83259571459)*Y)+Math.cos(0.0564944078792)*(0-(-Math.sin(1.83259571459)*X+Math.cos(1.83259571459)*Y)))/(Math.cos(0.0564944078792)*(Math.cos(1.83259571459)*X+Math.sin(1.83259571459)*Y)+Math.sin(0.0564944078792)*(0-(-Math.sin(1.83259571459)*X+Math.cos(1.83259571459)*Y)))) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0))))) || (((Math.atan2(Y, X)<=-0.99070314332&&Math.atan2(Y, X)>=-1.10369195908)) || (((Math.atan2(Y, X)<=2.15088951027&&Math.atan2(Y, X)>=2.03790069451)) || (((0.286*(Math.atan((-Math.sin(2.15088951027)*X+Math.cos(2.15088951027)*Y)/(Math.cos(2.15088951027)*X+Math.sin(2.15088951027)*Y)) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0) && ((0.286*(Math.atan((-Math.sin(0.0564944078792)*(Math.cos(2.09439510239)*X+Math.sin(2.09439510239)*Y)+Math.cos(0.0564944078792)*(0-(-Math.sin(2.09439510239)*X+Math.cos(2.09439510239)*Y)))/(Math.cos(0.0564944078792)*(Math.cos(2.09439510239)*X+Math.sin(2.09439510239)*Y)+Math.sin(0.0564944078792)*(0-(-Math.sin(2.09439510239)*X+Math.cos(2.09439510239)*Y)))) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0))))) || (((Math.atan2(Y, X)<=-0.72890375552&&Math.atan2(Y, X)>=-0.84189257128)) || (((Math.atan2(Y, X)<=2.41268889807&&Math.atan2(Y, X)>=2.29970008231)) || (((0.286*(Math.atan((-Math.sin(2.41268889807)*X+Math.cos(2.41268889807)*Y)/(Math.cos(2.41268889807)*X+Math.sin(2.41268889807)*Y)) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0) && ((0.286*(Math.atan((-Math.sin(0.0564944078792)*(Math.cos(2.35619449019)*X+Math.sin(2.35619449019)*Y)+Math.cos(0.0564944078792)*(0-(-Math.sin(2.35619449019)*X+Math.cos(2.35619449019)*Y)))/(Math.cos(0.0564944078792)*(Math.cos(2.35619449019)*X+Math.sin(2.35619449019)*Y)+Math.sin(0.0564944078792)*(0-(-Math.sin(2.35619449019)*X+Math.cos(2.35619449019)*Y)))) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0))))) || (((Math.atan2(Y, X)<=-0.46710436772&&Math.atan2(Y, X)>=-0.58009318348)) || (((Math.atan2(Y, X)<=2.67448828587&&Math.atan2(Y, X)>=2.56149947011)) || (((0.286*(Math.atan((-Math.sin(2.67448828587)*X+Math.cos(2.67448828587)*Y)/(Math.cos(2.67448828587)*X+Math.sin(2.67448828587)*Y)) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0) && ((0.286*(Math.atan((-Math.sin(0.0564944078792)*(Math.cos(2.61799387799)*X+Math.sin(2.61799387799)*Y)+Math.cos(0.0564944078792)*(0-(-Math.sin(2.61799387799)*X+Math.cos(2.61799387799)*Y)))/(Math.cos(0.0564944078792)*(Math.cos(2.61799387799)*X+Math.sin(2.61799387799)*Y)+Math.sin(0.0564944078792)*(0-(-Math.sin(2.61799387799)*X+Math.cos(2.61799387799)*Y)))) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0))))) || (((Math.atan2(Y, X)<=-0.20530497992&&Math.atan2(Y, X)>=-0.31829379568)) || (((Math.atan2(Y, X)<=2.93628767367&&Math.atan2(Y, X)>=2.82329885791)) || (((0.286*(Math.atan((-Math.sin(2.93628767367)*X+Math.cos(2.93628767367)*Y)/(Math.cos(2.93628767367)*X+Math.sin(2.93628767367)*Y)) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0) && ((0.286*(Math.atan((-Math.sin(0.0564944078792)*(Math.cos(2.87979326579)*X+Math.sin(2.87979326579)*Y)+Math.cos(0.0564944078792)*(0-(-Math.sin(2.87979326579)*X+Math.cos(2.87979326579)*Y)))/(Math.cos(0.0564944078792)*(Math.cos(2.87979326579)*X+Math.sin(2.87979326579)*Y)+Math.sin(0.0564944078792)*(0-(-Math.sin(2.87979326579)*X+Math.cos(2.87979326579)*Y)))) + Math.acos(0.286/Math.sqrt(X*X + Y*Y))) - Math.sqrt(X*X + Y*Y-0.286*0.286)) < 0)))))))}
emit(gear);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment