# Intersecting Curves after random growth

**URL:** <https://discourse.mcneel.com/t/intersecting-curves-after-random-growth/92179>\
**Category:** Grasshopper\
**Created:** [November 15, 2019, 7:59pm UTC](https://discourse.mcneel.com/t/intersecting-curves-after-random-growth/92179 "2019-11-15T19:59:25Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![malte92](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/malte92/32/187187_2.png) [@malte92](https://discourse.mcneel.com/u/malte92)\
**Post date:** [November 15, 2019, 7:59pm UTC](https://discourse.mcneel.com/t/intersecting-curves-after-random-growth/92179/1 "2019-11-15T19:59:25Z")

</div>

Hi guys,

I am relatively new about Anemon and growth processes in Grasshopper. I have created a growth process and would like to add more conditions to it. In this case, it is pentagons that are randomly mirrored randomly on one side of the pentagon. However, they intersect. I’ve tried a collision component but i have no clue how to fix this.  
Do you have any idea how I can get it to be an arbitrarily growing pattern, with the pentagons neither overlapping nor crossing?

Best regards.

 ![Unbenannt](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/b/a/bad07f44d91e7b2526da9478eb36d68323b6800b.png) ![Unbenannt2](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/5/7/575dd8f5992d4744d6d3cd69546494a650b179e7.png) [Curve intersec.gh](https://discourse.mcneel.com/uploads/short-url/kTLWcWXNIK4Z1eZobzQnXlAKObl.gh) (8.7 KB)

---

<div class="post-metadata">

**Author:** ![maje90](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/maje90/32/771922_2.png) [@maje90](https://discourse.mcneel.com/u/maje90)\
**Post date:** [November 15, 2019, 8:37pm UTC](https://discourse.mcneel.com/t/intersecting-curves-after-random-growth/92179/2 "2019-11-15T20:37:42Z")

</div>

Other than intersecting you have also a lot of overlapping polygons (duplicates)…  
Let’s find a solution that solve both problems at the same time.

For example, by making the polygon a surface, and joining the surface to a total main polysurface, you can then use only naked edges where to try to add a new polygon (surface) … (internal edges are not suitable for a new surface origin)  
 ![2019-11-15%2021_37_10-Window](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/3/4/34e7c715ae429d51a29523efca4a6387a6951e08.png)

---

<div class="post-metadata">

**Author:** ![maje90](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/maje90/32/771922_2.png) [@maje90](https://discourse.mcneel.com/u/maje90)\
**Post date:** [November 15, 2019, 8:58pm UTC](https://discourse.mcneel.com/t/intersecting-curves-after-random-growth/92179/3 "2019-11-15T20:58:13Z")

</div>

![2019-11-15%2021_55_23-Window](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/c/6/c61659fb8cf91cadd1e6bf298477dcee4af9e0e5.png)  
[Curve intersec\_re.gh](https://discourse.mcneel.com/uploads/short-url/ArWVD6lrIh792iQz8J3rjrXX5HK.gh) (13.7 KB)

Like this.

Interesting/cute pattern…  
In this solution new element is added only if it touch main polysurface on just one side.  
It could fit in some other places, but it is discarded anyway.

---

<div class="post-metadata">

**Author:** ![Joseph\_Oster](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/joseph_oster/32/549124_2.png) [@Joseph\_Oster](https://discourse.mcneel.com/u/Joseph_Oster)\
**Post date:** [November 15, 2019, 9:03pm UTC](https://discourse.mcneel.com/t/intersecting-curves-after-random-growth/92179/4 "2019-11-15T21:03:41Z")

</div>

Looks great, would love to see it. Do you mind posting a more readable version of your code so I can replace these missing R6 bits to make it work in R5? Mass Multiplication?

![missing](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/6/9/69e24ffd0875a5f339ff56c1fb86c5220f5cd719.png)

Funny thing is that the code appears to work, except for detecting overlaps.

---

<div class="post-metadata">

**Author:** ![maje90](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/maje90/32/771922_2.png) [@maje90](https://discourse.mcneel.com/u/maje90)\
**Post date:** [November 15, 2019, 9:05pm UTC](https://discourse.mcneel.com/t/intersecting-curves-after-random-growth/92179/5 "2019-11-15T21:05:09Z")

</div>

![2019-11-15%2022_02_36-Window](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/6/8/681bdd7ab8e74290910416181f1459a5722b9a40.png)  
[Curve intersec\_re\_V2.gh](https://discourse.mcneel.com/uploads/short-url/w1i5E9GzCbBgEkepvo8QMl2KBG7.gh) (15.5 KB)

Ok, small edit and different result.  
As wanted!

Still, the method to check if to discard a new surface is incomplete, it could fail (and will).  
(it is only checking vertexes of new polygon on main polysurface, mid-segment intersection could happen… always check results)

---

<div class="post-metadata">

**Author:** ![maje90](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/maje90/32/771922_2.png) [@maje90](https://discourse.mcneel.com/u/maje90)\
**Post date:** [November 15, 2019, 9:06pm UTC](https://discourse.mcneel.com/t/intersecting-curves-after-random-growth/92179/6 "2019-11-15T21:06:49Z")

</div>

![asd2](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/1/b/1bfba1804ea3acc02e6e07492c7d6206fd4a5d2c.png)  
The V2 is just the 0.9999 scaling part, you can skip it to have “V1” version…

---

<div class="post-metadata">

**Author:** ![Joseph\_Oster](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/joseph_oster/32/549124_2.png) [@Joseph\_Oster](https://discourse.mcneel.com/u/Joseph_Oster)\
**Post date:** [November 15, 2019, 9:24pm UTC](https://discourse.mcneel.com/t/intersecting-curves-after-random-growth/92179/7 "2019-11-15T21:24:38Z")

</div>

Thanks, but no joy in R5. Can’t seem to make V1 work. ☹

Aha! Modified to your V2 and it appeared to work at first but some overlaps happen eventually?

 ![Curve%20intersec_re_V2_R5](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/c/f/cff415686721893ec4068d67b4d65ee4d9ac2c9c.png)  
[Curve intersec\_re\_V2\_R5.gh](https://discourse.mcneel.com/uploads/short-url/zyJeVoYd0Nw1LDXUvOfFg3rt4m8.gh) (15.8 KB)

---

<div class="post-metadata">

**Author:** ![malte92](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/malte92/32/187187_2.png) [@malte92](https://discourse.mcneel.com/u/malte92)\
**Post date:** [November 15, 2019, 9:37pm UTC](https://discourse.mcneel.com/t/intersecting-curves-after-random-growth/92179/8 "2019-11-15T21:37:48Z")

</div>

Thank you so much for the explanation Riccardo, thats what i was aiming for 👍

---

<div class="post-metadata">

**Author:** ![maje90](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/maje90/32/771922_2.png) [@maje90](https://discourse.mcneel.com/u/maje90)\
**Post date:** [November 15, 2019, 10:02pm UTC](https://discourse.mcneel.com/t/intersecting-curves-after-random-growth/92179/9 "2019-11-15T22:02:08Z")

</div>

Seems like my brep closest point test is completely failing on R5.  
I’m finishing another version, I’ll post it compatible with R5.

---

<div class="post-metadata">

**Author:** ![Joseph\_Oster](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/joseph_oster/32/549124_2.png) [@Joseph\_Oster](https://discourse.mcneel.com/u/Joseph_Oster)\
**Post date:** [November 15, 2019, 10:05pm UTC](https://discourse.mcneel.com/t/intersecting-curves-after-random-growth/92179/10 "2019-11-15T22:05:09Z")

</div>

I removed Cull i and now it appears to work in R5?

 ![Curve%20intersec_re_V2b_R5](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/e/1/e15b70f4b8d52f839efa7951bbf17f3c122ec5ff.png)  
[Curve intersec\_re\_V2b\_R5.gh](https://discourse.mcneel.com/uploads/short-url/pdDVZ6VE9frxs3ZUjkxbyMTr2b0.gh) (16.7 KB)

---

<div class="post-metadata">

**Author:** ![maje90](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/maje90/32/771922_2.png) [@maje90](https://discourse.mcneel.com/u/maje90)\
**Post date:** [November 15, 2019, 10:34pm UTC](https://discourse.mcneel.com/t/intersecting-curves-after-random-growth/92179/11 "2019-11-15T22:34:40Z")

</div>

![2019-11-15%2023_24_22-Window](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/2/f/2f0e5a9f7b51196edb5e2844a5dc2ed8b5c68134.png)  
For large element count the loop would exponentially waste attempts on non-suitable edges (and that would have a growing fail rate over time), so I added a point list to store there failed attempts (by saving edge mid-point, as index is unusable in this situation), so it can avoid attempt again from the same edge.

In pic, point are old failed attempts.  
Further check should be done in big count, as this method still leave “attempt-able” a lot of edges that are clearly not suitable…

Up to V2 new elements could still intersect in some way with main polysurface, added a reverse test (inverse as previous method) that work in parallel.

Sorry for the messy descriptions… 😅

[Curve intersec\_re\_V3.gh](https://discourse.mcneel.com/uploads/short-url/1wDb74nzZ2FoSCpGtU72nK08viX.gh) (22.3 KB)  
[Curve intersec\_re\_V3\_RH5.gh](https://discourse.mcneel.com/uploads/short-url/vkmU9RQeXSeLAKs7JPMPwOm3kvb.gh) (22.9 KB)  
RH5 convert surface to curve (and opposite) in different ways, so vertex index of surface id different from RH6.
