Avoiding self intersection for 3d spline-tube

Hi

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

The shape of the spline is done randomly using PVectors:

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

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.

1 Like

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