# Avoiding self intersection for 3d spline-tube

**URL:** https://discourse.processing.org/t/avoiding-self-intersection-for-3d-spline-tube/31285
**Category:** Coding Questions
**Created:** [July 17, 2021, 7:04am UTC](https://discourse.processing.org/t/avoiding-self-intersection-for-3d-spline-tube/31285 "2021-07-17T07:04:17Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![dehyde](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dehyde/32/5153_2.png) [@dehyde](https://discourse.processing.org/u/dehyde)
#### Post date: [July 17, 2021, 7:04am UTC](https://discourse.processing.org/t/avoiding-self-intersection-for-3d-spline-tube/31285/1 "2021-07-17T07:04:17Z")

</div>

Hi

I’m trying to create a curved 3d tube using Shapes3d library.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/ae9518a7dc6f940172772cc8aa732743d24f42f7.png)

The shape of the spline is done randomly using PVectors:

```auto
for (int i=0; i<complexity; i++){
    knots[i] = new PVector(random(-2,2)*300,random(-2,2)*300,random(-2,2)*300);
  }

Oval hexagon = new Oval(60.0, 60);
shape = new Tube(path, hexagon);

```

I want to make it more realistic by avoiding intersection of the tube with itself, so it will look like some sort of knot, but still maintain a randomness factor to the generation (a new “knot” each time).

I’m not sure how to approach this problem, any idea would be appreciated

---

<div class="post-metadata">

### Author: ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)
#### Post date: [July 17, 2021, 7:10am UTC](https://discourse.processing.org/t/avoiding-self-intersection-for-3d-spline-tube/31285/2 "2021-07-17T07:10:30Z")

</div>

You might consider having each cross-section of string repel every other cross section of string with a distance-dependent force. That is, if two sections are close, the force that pushes them apart is quite high, while if they are far apart, the force is negligible. You may need to simulate the string for a while to get it to a point where it doesn’t self-intersect.

You might also want tension that pulls adjacent sections together, so the string looks string-like.

---

<div class="post-metadata">

### Author: ![dehyde](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dehyde/32/5153_2.png) [@dehyde](https://discourse.processing.org/u/dehyde)
#### Post date: [July 17, 2021, 3:53pm UTC](https://discourse.processing.org/t/avoiding-self-intersection-for-3d-spline-tube/31285/3 "2021-07-17T15:53:48Z")

</div>

Do you consider the PVectors as sections?  
I wonder if it’s good enough to help the string avoid itself between sections.
