{"id":696,"date":"2011-06-18T02:20:09","date_gmt":"2011-06-18T02:20:09","guid":{"rendered":"http:\/\/www.funkboxing.com\/wordpress\/?p=696"},"modified":"2021-01-03T18:13:00","modified_gmt":"2021-01-03T18:13:00","slug":"stupid-but-helpful-code-snippets","status":"publish","type":"post","link":"http:\/\/funkboxing.com\/wordpress\/?p=696","title":{"rendered":"Stupid but Helpful Code Snippets"},"content":{"rendered":"<p>To aid my never-ending quest to remember the things I learn about programming &#8211; I&#8217;ve decided to make this post as a place to leave little functions and crap that I always forget and are way too stupid to have to figure out more than once.<\/p>\n<p>It&#8217;ll grow, I&#8217;m constantly learning things I forgot.<\/p>\n<div style=\"height: 300px; width: 600px; font: 12px\/16px Georgia,Garamond,Serif; overflow: scroll;\">\n<pre class=\"brush:py\">######################################\n################ WARNING: ############\n############## STUPID CODE ###########\n######################################\n#### PLEASE DO NOT LEARN ANYTHING ####\n######################################\n\ndef sbh_within(x,y,d):\n###---CHECK IF x-d &lt;= y &lt;= x+d\n if x-d &lt;= y and x + d &gt;= y:\n return True\n else: return False\n\ndef sbh_center2d(Ax, Ay, Bx, By):\n###---GET CENTER BETWEEN TWO 2D POINTS\n    Cx = Ax + (Bx - Ax)\/2\n    Cy = Ay + (By - Ay)\/2\n    return Cx, Cy\n\ndef sbh_dist2d(Ax, Ay, Bx, By):\n###---GET DISTANCE BETWEEN TWO 2D POINTS\n    Cx = Bx - Ax\n    Cy = By - Ay\n    return Cx, Cy\n\ndef sbh_hypot(a, b):\n    c = sqrt(a*a+b*b)\n    return c\n\ndef sbh_getAngle2d(A, B):\n###---RETURNS HEADING FROM A TO B\n    opp = B.y - A.y\n    adj = B.x - A.x\n    hyp = hypot(opp, adj)\n    s = asin(opp\/hyp)\n    c = acos(adj\/hyp)\n    if B.x &gt;= A.x and B.y &gt;= A.y: r = s-pi\/2\n    if B.x &lt;= A.x and B.y &gt;= A.y: r = c-pi\/2\n    if B.x &lt;= A.x and B.y &lt;= A.y: r = (pi\/2)-s\n    if B.x &gt;= A.x and B.y &lt;= A.y: r = -(pi\/2)-c\n    return r\n\ndef sbh_si(num):\n###---RETURNS SIGN OF A NUMBER\n    if num&gt;=0: return 1\n    if num&lt;0: return -1\n\ndef sbh_wrapAng(x):\n###---WRAP EULER ANGLES (-pi &lt;= a &lt;= pi)\n    p360 = pi*2\n    f = x - (p360)*floor((x+pi)\/p360)\n    return f<\/pre>\n<\/div>\n<p>&#8212;OTHER BLENDER PYTHON API NOTES&#8212;<br \/>\nMost of these are issues I&#8217;ve run into with and without solutions.<\/p>\n<p>&#8211; Can not add game logic bricks via. python API. [SOLVED]<br \/>\n&#8211; Can not access poseLib data with bpy.data, only bpy.ops functions and none to read pose data.<br \/>\n&#8211; Voxel data files: .raw\/.bvox &#8211; can&#8217;t use multi-frame data. Only 64x64x64 grid size works.<\/p>\n<p>&#8211; active object &#8211; accessible with &#8220;bpy.context.scene.objects.active = ob&#8221;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To aid my never-ending quest to remember the things I learn about programming &#8211; I&#8217;ve decided to make this post as a place to leave little functions and crap that I always forget and are way too stupid to have to figure out more than once. It&#8217;ll grow, I&#8217;m constantly learning things I forgot. ###################################### <a href='http:\/\/funkboxing.com\/wordpress\/?p=696' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"http:\/\/funkboxing.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/696"}],"collection":[{"href":"http:\/\/funkboxing.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/funkboxing.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/funkboxing.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/funkboxing.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=696"}],"version-history":[{"count":1,"href":"http:\/\/funkboxing.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/696\/revisions"}],"predecessor-version":[{"id":2624,"href":"http:\/\/funkboxing.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/696\/revisions\/2624"}],"wp:attachment":[{"href":"http:\/\/funkboxing.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=696"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/funkboxing.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=696"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/funkboxing.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=696"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}