{"id":115,"date":"2009-09-04T22:07:28","date_gmt":"2009-09-05T05:07:28","guid":{"rendered":"https:\/\/mathpirate.net\/log\/?p=115"},"modified":"2009-09-04T22:07:28","modified_gmt":"2009-09-05T05:07:28","slug":"scratch-2-1-remaining-1-new","status":"publish","type":"post","link":"https:\/\/mathpirate.net\/log\/2009\/09\/04\/scratch-2-1-remaining-1-new\/","title":{"rendered":"Scratch 2, 1 Remaining, 1 New."},"content":{"rendered":"<p>The &#8220;negative slope bug&#8221; was caused by accidentally reversing X and Y in a statement.\u00c2\u00a0 Fixing that cleared up the problem with the oddly reversing lines.\u00c2\u00a0 Of course, a positive slope should have gotten just as screwed by the problem.\u00c2\u00a0 Whatever.\u00c2\u00a0 It works now.<\/p>\n<p>I also found a mitigation for the duplicate paddle contours causing a jittery trajectory.\u00c2\u00a0 I changed a parameter to cvFindContours to use the External contour retrieval mode, rather than List.\u00c2\u00a0 I think the duplicate contours weren&#8217;t really duplicates at all, but were actually inner and outer contours around the object.\u00c2\u00a0 That is, in certain frames, the paddle looked like a donut to the algorithm, rather than a solid block, so I was getting concentric contours representing the inside and outside of that donut.\u00c2\u00a0 External looks like it simply gives a bounding box, which is what I wanted anyway.\u00c2\u00a0 There are still occasional jitters, but I think I can live with them.\u00c2\u00a0 It&#8217;s running much smoother now.<\/p>\n<p>That still leaves the integer extrapolation issue, which should be fairly straightforward to take care of.\u00c2\u00a0 Just look in the history for a few more points and get a clearer trajectory.<\/p>\n<p>Another bug was exposed after I fixed the two big problems.\u00c2\u00a0 While I was working out the calculation for the intersection between the extrapolated trajectory and the boundary walls, I noted a case where there&#8217;d be a division by zero, if the slope ever happened to be zero, so I put in a guard clause against that.\u00c2\u00a0 However, at the time, I didn&#8217;t think about the fact that a zero slope is, in fact, perfectly acceptable in Pong.\u00c2\u00a0 If you hit the ball at the middle of your paddle, it&#8217;s bounced back straight across the playfield.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The &#8220;negative slope bug&#8221; was caused by accidentally reversing X and Y in a statement.\u00c2\u00a0 Fixing that cleared up the problem with the oddly reversing lines.\u00c2\u00a0 Of course, a positive slope should have gotten just as screwed by the problem.\u00c2\u00a0 Whatever.\u00c2\u00a0 It works now. I also found a mitigation for the duplicate paddle contours causing [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[24],"tags":[15,19,25],"_links":{"self":[{"href":"https:\/\/mathpirate.net\/log\/wp-json\/wp\/v2\/posts\/115"}],"collection":[{"href":"https:\/\/mathpirate.net\/log\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mathpirate.net\/log\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mathpirate.net\/log\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mathpirate.net\/log\/wp-json\/wp\/v2\/comments?post=115"}],"version-history":[{"count":2,"href":"https:\/\/mathpirate.net\/log\/wp-json\/wp\/v2\/posts\/115\/revisions"}],"predecessor-version":[{"id":117,"href":"https:\/\/mathpirate.net\/log\/wp-json\/wp\/v2\/posts\/115\/revisions\/117"}],"wp:attachment":[{"href":"https:\/\/mathpirate.net\/log\/wp-json\/wp\/v2\/media?parent=115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mathpirate.net\/log\/wp-json\/wp\/v2\/categories?post=115"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mathpirate.net\/log\/wp-json\/wp\/v2\/tags?post=115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}