{"id":280,"date":"2009-05-10T10:35:16","date_gmt":"2009-05-10T17:35:16","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1318"},"modified":"2009-05-10T10:35:16","modified_gmt":"2009-05-10T17:35:16","slug":"implicit-3d-plot","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=280","title":{"rendered":"Implicit 3D Plot"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar matrix:Matrix3D = new Matrix3D();\r\nvar verts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;();\r\nvar pVerts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;();\r\nvar uvts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;();\r\nfor (var i:Number = -2; i&lt;2; i+=.04) {\r\n\tfor (var j:Number = -2; j&lt;2; j+=.04) {\r\n\t\tfor (var k:Number = -2; k&lt;2; k+=.04) {\r\n\t\t\t\/\/ blobby, from here www.iiit.net\/techreports\/ImplicitTR.pdf\r\nvar s:Number=i*i+j*j+k*k+Math.sin(4*i)-Math.cos(4*j)+Math.sin(4*k)-1;\r\n\t\t\tif (s&lt;0&amp;&amp;s&gt;-.2) {\r\n\t\t\t\tverts.push(i * 60);\r\n\t\t\t\tverts.push(j * 60);\r\n\t\t\t\tverts.push(k * 60);\r\n\t\t\t\tpVerts.push(0),pVerts.push(0);\r\n\t\t\t\tuvts.push(0),uvts.push(0),uvts.push(0);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\nvar brush:BitmapData=new BitmapData(3,2,true,0x41FFFFFF);\r\nvar canvas:BitmapData=new BitmapData(400,400,false,0x000000);\r\naddChild(new Bitmap(canvas));\r\nvar dx:Number=0;\r\nvar dy:Number=0;\r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\nfunction onLoop(evt:Event):void {\r\n\tdx += (mouseX - dx)\/4;\r\n\tdy += (mouseY - dy)\/4;\r\n\tmatrix.identity();\r\n\tmatrix.appendRotation(dy,Vector3D.X_AXIS);\r\n\tmatrix.appendRotation(dx,Vector3D.Y_AXIS);\r\n\tmatrix.appendTranslation(200, 200, 0);\r\n\tUtils3D.projectVectors(matrix, verts, pVerts, uvts);\r\n\tcanvas.lock();\r\n\tcanvas.fillRect(canvas.rect, 0x000000);\r\n\tvar p = new Point();\r\n\tfor (var i:int = 0; i&lt;pVerts.length; i+=2) {\r\n\t\tp.x = pVerts&#x5B;i];\r\n\t\tp.y = pVerts&#x5B;i+1];\r\n\t\tcanvas.copyPixels(brush, brush.rect, p, null, null, true);\r\n\t}\r\n\tcanvas.unlock();\r\n}\r\n<\/pre>\n<p>I was looking at some equations for implicit 3D surfaces in <a href=\"www.iiit.net\/techreports\/ImplicitTR.pdf\" target=\"blank\">this pdf<\/a> about raytracing&#8230; 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.<\/p>\n<p><a href=\"http:\/\/wonderfl.net\/code\/6c69696a53b8b57cfd7453cef6e6d31e7d3ea1d5\" target=\"blank\">(check out the swf on wonderfl.net)<\/a><\/p>\n<p>Here are some stills of the above snippet:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/blobby.gif\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>var matrix:Matrix3D = new Matrix3D(); var verts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;(); var pVerts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;(); var uvts:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;(); for (var i:Number = -2; i&lt;2; i+=.04) { for (var j:Number = -2; j&lt;2; j+=.04) { for (var k:Number = -2; k&lt;2; k+=.04) { \/\/ blobby, from here www.iiit.net\/techreports\/ImplicitTR.pdf var s:Number=i*i+j*j+k*k+Math.sin(4*i)-Math.cos(4*j)+Math.sin(4*k)-1; if (s&lt;0&amp;&amp;s&gt;-.2) { verts.push(i [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101,24,114,121,25,21,79],"tags":[3,4],"class_list":["post-280","post","type-post","status-publish","format-standard","hentry","category-3d","category-bitmapdata","category-graphics-algorithms","category-math","category-pixel-manipulation","category-strings","category-vector","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/280","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=280"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/280\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}