# Implicit 3D Plot

Actionscript:
1. var matrix:Matrix3D = new Matrix3D();
2. var verts:Vector.<Number> = new Vector.<Number>();
3. var pVerts:Vector.<Number> = new Vector.<Number>();
4. var uvts:Vector.<Number> = new Vector.<Number>();
5. for (var i:Number = -2; i<2; i+=.04) {
6.     for (var j:Number = -2; j<2; j+=.04) {
7.         for (var k:Number = -2; k<2; k+=.04) {
8.             // blobby, from here www.iiit.net/techreports/ImplicitTR.pdf
9. var s:Number=i*i+j*j+k*k+Math.sin(4*i)-Math.cos(4*j)+Math.sin(4*k)-1;
10.             if (s<0&&s>-.2) {
11.                 verts.push(i * 60);
12.                 verts.push(j * 60);
13.                 verts.push(k * 60);
14.                 pVerts.push(0),pVerts.push(0);
15.                 uvts.push(0),uvts.push(0),uvts.push(0);
16.             }
17.         }
18.     }
19. }
20. var brush:BitmapData=new BitmapData(3,2,true,0x41FFFFFF);
21. var canvas:BitmapData=new BitmapData(400,400,false,0x000000);
23. var dx:Number=0;
24. var dy:Number=0;
26. function onLoop(evt:Event):void {
27.     dx += (mouseX - dx)/4;
28.     dy += (mouseY - dy)/4;
29.     matrix.identity();
30.     matrix.appendRotation(dy,Vector3D.X_AXIS);
31.     matrix.appendRotation(dx,Vector3D.Y_AXIS);
32.     matrix.appendTranslation(200, 200, 0);
33.     Utils3D.projectVectors(matrix, verts, pVerts, uvts);
34.     canvas.lock();
35.     canvas.fillRect(canvas.rect, 0x000000);
36.     var p = new Point();
37.     for (var i:int = 0; i<pVerts.length; i+=2) {
38.         p.x = pVerts[i];
39.         p.y = pVerts[i+1];
40.         canvas.copyPixels(brush, brush.rect, p, null, null, true);
41.     }
42.     canvas.unlock();
43. }

I was looking at some equations for implicit 3D surfaces in this pdf about raytracing... anyway, I realized I could just modify the Utils3D.projectVectors() code (that I wrote a little while ago) to easily render any of the implicit equations mentioned in the pdf. I also did some experimentation with fake lighting and distance rendering which I may post in the future.

(check out the swf on wonderfl.net)

Here are some stills of the above snippet: