{"id":4931,"date":"2019-04-04T01:30:47","date_gmt":"2019-04-03T17:30:47","guid":{"rendered":"https:\/\/unitycoder.com\/blog\/?p=4931"},"modified":"2019-04-04T01:30:54","modified_gmt":"2019-04-03T17:30:54","slug":"ransac-2d-line-fitting","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2019\/04\/04\/ransac-2d-line-fitting\/","title":{"rendered":"RANSAC 2D Line Fitting"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"437\" height=\"436\" data-attachment-id=\"4932\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2019\/04\/04\/ransac-2d-line-fitting\/image\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/04\/image.png?fit=437%2C436&amp;ssl=1\" data-orig-size=\"437,436\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/04\/image.png?fit=437%2C436&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/04\/image.png?resize=437%2C436&#038;ssl=1\" alt=\"\" class=\"wp-image-4932\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/04\/image.png?w=437&amp;ssl=1 437w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/04\/image.png?resize=150%2C150&amp;ssl=1 150w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/04\/image.png?resize=300%2C300&amp;ssl=1 300w\" sizes=\"auto, (max-width: 437px) 100vw, 437px\" \/><\/figure>\n\n\n\n<p>Converted this RANSAC 2D line fitting pseudocode into Unity c#  <a rel=\"noreferrer noopener\" aria-label=\"http:\/\/www.visual-experiments.com\/demo\/ransac.js\/ (opens in a new tab)\" href=\"http:\/\/www.visual-experiments.com\/demo\/ransac.js\/\" target=\"_blank\">http:\/\/www.visual-experiments.com\/demo\/ransac.js\/<\/a><\/p>\n\n\n\n<p>What is RANSAC? <a rel=\"noreferrer noopener\" aria-label=\"https:\/\/en.wikipedia.org\/wiki\/Random_sample_consensus (opens in a new tab)\" href=\"https:\/\/en.wikipedia.org\/wiki\/Random_sample_consensus\" target=\"_blank\">https:\/\/en.wikipedia.org\/wiki\/Random_sample_consensus<\/a><\/p>\n\n\n\n<p><strong>Source code:<\/strong><br><a rel=\"noreferrer noopener\" aria-label=\"https:\/\/gist.github.com\/unitycoder\/53495435c28853ef6522ff60d5c6a091 (opens in a new tab)\" href=\"https:\/\/gist.github.com\/unitycoder\/53495435c28853ef6522ff60d5c6a091\" target=\"_blank\">https:\/\/gist.github.com\/unitycoder\/53495435c28853ef6522ff60d5c6a091<\/a><br><br><em>*Note this is not optimized at all, just a quick test<\/em><\/p>\n\n\n\n<p><strong>Usage instructions:<\/strong><br>&#8211; Add this script to empty gameobject<br>&#8211; Add gameobjects as a child of that gameobject (place them randomly, but try to make some possible line there)<br>&#8211; Adjust threshold variable inside the script<br>&#8211; Adjust iterations count (if proper line is not found<br>My setup: (see image below)<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"680\" height=\"267\" data-attachment-id=\"4933\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2019\/04\/04\/ransac-2d-line-fitting\/image-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/04\/image-1.png?fit=680%2C267&amp;ssl=1\" data-orig-size=\"680,267\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/04\/image-1.png?fit=680%2C267&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/04\/image-1.png?resize=680%2C267&#038;ssl=1\" alt=\"\" class=\"wp-image-4933\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/04\/image-1.png?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/04\/image-1.png?resize=300%2C118&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/figure>\n\n\n\n<p><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Converted this RANSAC 2D line fitting pseudocode into Unity c# http:\/\/www.visual-experiments.com\/demo\/ransac.js\/ What is RANSAC? https:\/\/en.wikipedia.org\/wiki\/Random_sample_consensus Source code:https:\/\/gist.github.com\/unitycoder\/53495435c28853ef6522ff60d5c6a091 *Note this is not optimized at all, just a quick test Usage instructions:&#8211; Add this script to empty gameobject&#8211; Add gameobjects as a child of that gameobject (place [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4932,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[804],"tags":[65,93,76,1081],"class_list":["post-4931","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripts","tag-2d","tag-algorithm","tag-line","tag-ransac"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/04\/image.png?fit=437%2C436&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-1hx","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/4931","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/comments?post=4931"}],"version-history":[{"count":1,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/4931\/revisions"}],"predecessor-version":[{"id":4934,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/4931\/revisions\/4934"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/4932"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=4931"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=4931"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=4931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}