{"id":2061,"date":"2014-03-30T23:47:14","date_gmt":"2014-03-30T21:47:14","guid":{"rendered":"https:\/\/www.modelical.com\/?p=546"},"modified":"2022-03-21T12:40:33","modified_gmt":"2022-03-21T11:40:33","slug":"grasshopper-scripting-108","status":"publish","type":"post","link":"https:\/\/www.modelical.com\/en\/grasshopper-scripting-108\/","title":{"rendered":"Grasshopper Scripting 108"},"content":{"rendered":"<h2>Useful Stuff (II)<\/h2>\n<p>After the beautiful examples from 107, let&#8217;s see some more examples of iteration that are not easily achievable with plain GH, now involving more transformations and intersections.<\/p>\n<h3>Funicular Solver:<\/h3>\n<p>The problem is as follows. We have a set of lines (red), a set of infinite rays (green) and an anchor point. We want to build a polygon starting from the point, following the first line&#8217;s direction until we reach the first ray, then we continue with the second line&#8217;s direction until the second ray and so on and so forth until we run out of lines or rays. Two images are worth a thousand words:<\/p>\n<p>From this&#8230;<\/p>\n<p><img decoding=\"async\" width=\"800\" height=\"480\" class=\"alignnone size-full wp-image-3945\" alt=\"Funicular1\" src=\"https:\/\/www.modelical.com\/wp-content\/uploads\/2014\/03\/Funicular1.jpg\" srcset=\"https:\/\/www.modelical.com\/wp-content\/uploads\/2014\/03\/Funicular1.jpg 800w, https:\/\/www.modelical.com\/wp-content\/uploads\/2014\/03\/Funicular1-480x288.jpg 480w, https:\/\/www.modelical.com\/wp-content\/uploads\/2014\/03\/Funicular1-768x461.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>We want to achieve this, with A parallel to each other, as well as B, C, etc.<\/p>\n<p><img decoding=\"async\" width=\"800\" height=\"480\" class=\"alignnone size-full wp-image-3946\" alt=\"Funicular2\" src=\"https:\/\/www.modelical.com\/wp-content\/uploads\/2014\/03\/Funicular2.jpg\" srcset=\"https:\/\/www.modelical.com\/wp-content\/uploads\/2014\/03\/Funicular2.jpg 800w, https:\/\/www.modelical.com\/wp-content\/uploads\/2014\/03\/Funicular2-480x288.jpg 480w, https:\/\/www.modelical.com\/wp-content\/uploads\/2014\/03\/Funicular2-768x461.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>So let&#8217;s see some code:<\/p>\n<pre class=\"lang:c# decode:true\">  private void RunScript(List&lt;Line&gt; x, List&lt;Line&gt; y, Point3d p, ref object A)\r\n  {\r\n    \/\/a little of care about our inputs is always good\r\n    if(x != null &amp;&amp; y != null &amp;&amp; p.IsValid)\r\n    {\r\n      \/\/see what we'll run out of before, lines or rays\r\n      int c = Math.Min(x.Count, y.Count);\r\n      \/\/declare a list for our points\r\n      List&lt;Point3d&gt; ptList = new List&lt;Point3d&gt;();\r\n      \/\/add the anchor point\r\n      ptList.Add(p);\r\n      \/\/iterate through lines and rays\r\n      for (int i = 0; i &lt; c; i++)\r\n      {\r\n\r\n        \/\/pick the current line and ray\r\n        Line ln = x[i];\r\n        Line ray = y[i];\r\n        \/\/find the starting point of the line\r\n        Point3d pt1 = ln.From;\r\n        \/\/build a transformation between the current point and the start of the current line\r\n        Transform xForm = Transform.Translation(ptList[i] - pt1);\r\n        \/\/move the line to its position\r\n        ln.Transform(xForm);\r\n        \/\/holders for the intersection t values\r\n        double lnt = 0.0;\r\n        double rayt = 0.0;\r\n        \/\/perform the intersection\r\n        if(!Rhino.Geometry.Intersect.Intersection.LineLine(ln, ray, out lnt, out rayt))\r\n        { \r\n          \/\/if went wront, tell the user\r\n          Print(\"Intersection at step {0} failed\", i);\r\n\r\n        }\r\n        else\r\n        { \r\n          \/\/if went well, create a point and add it to the list\r\n          Point3d pt = ln.PointAt(lnt);\r\n          ptList.Add(pt);\r\n        }\/\/end if\r\n      }\/\/end loop\r\n      \/\/start again with the newly added point  \r\n\r\n      \/\/output the points\r\n      A = ptList;\r\n    }\r\n  }<\/pre>\n<p>You can <a title=\"B11_GHS_108_FunicularExample\" href=\"https:\/\/www.modelical.com\/wp-content\/uploads\/2014\/03\/B11_GHS_108_Funicular.zip\">download the example here (0.9.0014)<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Useful Stuff (II) After the beautiful examples from 107, let&#8217;s see some more examples of iteration that are not easily achievable with plain GH, now involving more transformations and intersections. Funicular Solver: The problem is as follows. We have a set of lines (red), a set of infinite rays (green) and an anchor point. We [&hellip;]<\/p>\n","protected":false},"author":64,"featured_media":27189,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[4],"tags":[423,418],"class_list":["post-2061","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-guidelines","tag-technology-c","tag-technology-grasshopper"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Grasshopper Scripting 108 - Modelical<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.modelical.com\/en\/grasshopper-scripting-108\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Grasshopper Scripting 108 - Modelical\" \/>\n<meta property=\"og:description\" content=\"Useful Stuff (II) After the beautiful examples from 107, let&#8217;s see some more examples of iteration that are not easily achievable with plain GH, now involving more transformations and intersections. Funicular Solver: The problem is as follows. We have a set of lines (red), a set of infinite rays (green) and an anchor point. We [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.modelical.com\/en\/grasshopper-scripting-108\/\" \/>\n<meta property=\"og:site_name\" content=\"Modelical\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Modelical\/\" \/>\n<meta property=\"article:published_time\" content=\"2014-03-30T21:47:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-03-21T11:40:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.modelical.com\/wp-content\/uploads\/2014\/03\/Funicular2.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"480\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Roberto Molinos\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@modelical\" \/>\n<meta name=\"twitter:site\" content=\"@modelical\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Roberto Molinos\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/grasshopper-scripting-108\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/grasshopper-scripting-108\\\/\"},\"author\":{\"name\":\"Roberto Molinos\",\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/#\\\/schema\\\/person\\\/3ad52fd99e6b5b98a59ef24c76a7c2d5\"},\"headline\":\"Grasshopper Scripting 108\",\"datePublished\":\"2014-03-30T21:47:14+00:00\",\"dateModified\":\"2022-03-21T11:40:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/grasshopper-scripting-108\\\/\"},\"wordCount\":143,\"image\":{\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/grasshopper-scripting-108\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.modelical.com\\\/wp-content\\\/uploads\\\/2014\\\/03\\\/Funicular2-400x250-1.jpg\",\"keywords\":[\"Tec C#\",\"Tec Grasshopper\"],\"articleSection\":[\"Guidelines\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/grasshopper-scripting-108\\\/\",\"url\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/grasshopper-scripting-108\\\/\",\"name\":\"Grasshopper Scripting 108 - Modelical\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/grasshopper-scripting-108\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/grasshopper-scripting-108\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.modelical.com\\\/wp-content\\\/uploads\\\/2014\\\/03\\\/Funicular2-400x250-1.jpg\",\"datePublished\":\"2014-03-30T21:47:14+00:00\",\"dateModified\":\"2022-03-21T11:40:33+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/#\\\/schema\\\/person\\\/3ad52fd99e6b5b98a59ef24c76a7c2d5\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.modelical.com\\\/en\\\/grasshopper-scripting-108\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/grasshopper-scripting-108\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.modelical.com\\\/wp-content\\\/uploads\\\/2014\\\/03\\\/Funicular2-400x250-1.jpg\",\"contentUrl\":\"https:\\\/\\\/www.modelical.com\\\/wp-content\\\/uploads\\\/2014\\\/03\\\/Funicular2-400x250-1.jpg\",\"width\":400,\"height\":250},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/\",\"name\":\"Modelical\",\"description\":\"We build information\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/#\\\/schema\\\/person\\\/3ad52fd99e6b5b98a59ef24c76a7c2d5\",\"name\":\"Roberto Molinos\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9346c12c96cb942be9bb8b2454e296662a1baa0b4cd461ab315ae9a5185b0db6?s=96&d=initials&r=g&initials=ro\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9346c12c96cb942be9bb8b2454e296662a1baa0b4cd461ab315ae9a5185b0db6?s=96&d=initials&r=g&initials=ro\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9346c12c96cb942be9bb8b2454e296662a1baa0b4cd461ab315ae9a5185b0db6?s=96&d=initials&r=g&initials=ro\",\"caption\":\"Roberto Molinos\"},\"sameAs\":[\"https:\\\/\\\/www.modelical.com\"],\"url\":\"https:\\\/\\\/www.modelical.com\\\/en\\\/author\\\/roberto\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Grasshopper Scripting 108 - Modelical","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.modelical.com\/en\/grasshopper-scripting-108\/","og_locale":"en_US","og_type":"article","og_title":"Grasshopper Scripting 108 - Modelical","og_description":"Useful Stuff (II) After the beautiful examples from 107, let&#8217;s see some more examples of iteration that are not easily achievable with plain GH, now involving more transformations and intersections. Funicular Solver: The problem is as follows. We have a set of lines (red), a set of infinite rays (green) and an anchor point. We [&hellip;]","og_url":"https:\/\/www.modelical.com\/en\/grasshopper-scripting-108\/","og_site_name":"Modelical","article_publisher":"https:\/\/www.facebook.com\/Modelical\/","article_published_time":"2014-03-30T21:47:14+00:00","article_modified_time":"2022-03-21T11:40:33+00:00","og_image":[{"width":800,"height":480,"url":"https:\/\/www.modelical.com\/wp-content\/uploads\/2014\/03\/Funicular2.jpg","type":"image\/jpeg"}],"author":"Roberto Molinos","twitter_card":"summary_large_image","twitter_creator":"@modelical","twitter_site":"@modelical","twitter_misc":{"Written by":"Roberto Molinos","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.modelical.com\/en\/grasshopper-scripting-108\/#article","isPartOf":{"@id":"https:\/\/www.modelical.com\/en\/grasshopper-scripting-108\/"},"author":{"name":"Roberto Molinos","@id":"https:\/\/www.modelical.com\/en\/#\/schema\/person\/3ad52fd99e6b5b98a59ef24c76a7c2d5"},"headline":"Grasshopper Scripting 108","datePublished":"2014-03-30T21:47:14+00:00","dateModified":"2022-03-21T11:40:33+00:00","mainEntityOfPage":{"@id":"https:\/\/www.modelical.com\/en\/grasshopper-scripting-108\/"},"wordCount":143,"image":{"@id":"https:\/\/www.modelical.com\/en\/grasshopper-scripting-108\/#primaryimage"},"thumbnailUrl":"https:\/\/www.modelical.com\/wp-content\/uploads\/2014\/03\/Funicular2-400x250-1.jpg","keywords":["Tec C#","Tec Grasshopper"],"articleSection":["Guidelines"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.modelical.com\/en\/grasshopper-scripting-108\/","url":"https:\/\/www.modelical.com\/en\/grasshopper-scripting-108\/","name":"Grasshopper Scripting 108 - Modelical","isPartOf":{"@id":"https:\/\/www.modelical.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.modelical.com\/en\/grasshopper-scripting-108\/#primaryimage"},"image":{"@id":"https:\/\/www.modelical.com\/en\/grasshopper-scripting-108\/#primaryimage"},"thumbnailUrl":"https:\/\/www.modelical.com\/wp-content\/uploads\/2014\/03\/Funicular2-400x250-1.jpg","datePublished":"2014-03-30T21:47:14+00:00","dateModified":"2022-03-21T11:40:33+00:00","author":{"@id":"https:\/\/www.modelical.com\/en\/#\/schema\/person\/3ad52fd99e6b5b98a59ef24c76a7c2d5"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.modelical.com\/en\/grasshopper-scripting-108\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.modelical.com\/en\/grasshopper-scripting-108\/#primaryimage","url":"https:\/\/www.modelical.com\/wp-content\/uploads\/2014\/03\/Funicular2-400x250-1.jpg","contentUrl":"https:\/\/www.modelical.com\/wp-content\/uploads\/2014\/03\/Funicular2-400x250-1.jpg","width":400,"height":250},{"@type":"WebSite","@id":"https:\/\/www.modelical.com\/en\/#website","url":"https:\/\/www.modelical.com\/en\/","name":"Modelical","description":"We build information","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.modelical.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.modelical.com\/en\/#\/schema\/person\/3ad52fd99e6b5b98a59ef24c76a7c2d5","name":"Roberto Molinos","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/9346c12c96cb942be9bb8b2454e296662a1baa0b4cd461ab315ae9a5185b0db6?s=96&d=initials&r=g&initials=ro","url":"https:\/\/secure.gravatar.com\/avatar\/9346c12c96cb942be9bb8b2454e296662a1baa0b4cd461ab315ae9a5185b0db6?s=96&d=initials&r=g&initials=ro","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9346c12c96cb942be9bb8b2454e296662a1baa0b4cd461ab315ae9a5185b0db6?s=96&d=initials&r=g&initials=ro","caption":"Roberto Molinos"},"sameAs":["https:\/\/www.modelical.com"],"url":"https:\/\/www.modelical.com\/en\/author\/roberto\/"}]}},"_links":{"self":[{"href":"https:\/\/www.modelical.com\/en\/wp-json\/wp\/v2\/posts\/2061","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.modelical.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.modelical.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.modelical.com\/en\/wp-json\/wp\/v2\/users\/64"}],"replies":[{"embeddable":true,"href":"https:\/\/www.modelical.com\/en\/wp-json\/wp\/v2\/comments?post=2061"}],"version-history":[{"count":0,"href":"https:\/\/www.modelical.com\/en\/wp-json\/wp\/v2\/posts\/2061\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modelical.com\/en\/wp-json\/wp\/v2\/media\/27189"}],"wp:attachment":[{"href":"https:\/\/www.modelical.com\/en\/wp-json\/wp\/v2\/media?parent=2061"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modelical.com\/en\/wp-json\/wp\/v2\/categories?post=2061"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modelical.com\/en\/wp-json\/wp\/v2\/tags?post=2061"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}