Tooth Curve (modified Bicuspid)

Actionscript:
  1. var canvas:BitmapData=new BitmapData(400,400,false,0xCCCCCC);
  2. addChild(new Bitmap(canvas));
  3.  
  4. var a:Number=-1.21;
  5. var r:Rectangle=new Rectangle(0,0,3,5);
  6. var halfWidth:Number=canvas.width/2;
  7. var halfHeight:Number=canvas.height/2;
  8.  
  9. render();
  10.  
  11. function render():void{
  12.     for (var x:Number = -2; x<=2; x+=.05) {
  13.         for (var y:Number = -2; y<=2; y+=.05) {
  14.    
  15.             // equation from : http://en.wikipedia.org/wiki/Bicuspid_curve
  16.             //(x^2 - a^2) * (x - a)^2 + (y^2 - a^2) * (y^2 - a^2) = 0
  17.    
  18.             // unpoptimized:
  19.             // var e:Number = (x*x - a*a) * (x-a)*(x-a) + (y*y-a*a) * (y*y-a*a);  
  20.             // optimized:
  21.             var x_a:Number=x-a;
  22.             // factoring: x^2 - a^2 = (x + a) * (x - a)
  23.             var y2_a2:Number =  (y + a) * (y - a);
  24.             var e:Number = (x + a) * x_a * x_a * x_a +  y2_a2 * y2_a2;
  25.    
  26.             // tolerance beetween .7 & -.1;
  27.             if (e<.7&&e>-.1) {
  28.                 r.x=halfWidth+y*50;
  29.                 r.y=halfHeight-x*100;
  30.                 canvas.fillRect(r, 0x000000);
  31.             }
  32.         }
  33.     }
  34. }

I've been looking for a single math equation to draw a tooth for sometime.... today I stumbled upon this... and realized it could probably be changed to look more like a tooth.

This snippet will draw this:

I'm using a graphing method here that allows me to use the Cartesian form of the equation and not the parameteric... I'll explain a bit more about this in a later post.

This entry was posted in BitmapData, Math and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Comment

  1. Posted July 8, 2011 at 4:21 am | Permalink

    its a good snippet

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*