How to 3D flow field?

Hi all,

I’m playing around with Dan Shiffmann Perlin noise flow field with Processing 4 and I wondered how to upgrade his example to use it to move particles in a 3D flow field. Currently my code is :

import peasy.*;

PeasyCam cam;
int scale = 50;
int cols, rows, dep;
float zoff = 0.;
float inc = 0.1;

void setup() {
  size(800, 800, P3D);
  background(250);
  cam = new PeasyCam(this, 500);
  cols = width / scale;
  rows = height / scale;
  dep = width / scale;
}

void draw() {
  background(250);
  translate(-width/2, -height/2);
  rotateY(PI/3);
  float yoff = .0;
  for (int y = 0; y < rows; y++) {
    float xoff = .0;
    for (int x = 0; x < cols; x++) {
      for (int z = 0; z < dep; z++) {
        float angle1 = noise(xoff, yoff, zoff) * TWO_PI;
        float angle2 = noise(yoff, zoff, xoff) * TWO_PI;

        float x1 = cos(angle1) * cos(angle2);
        float y1 = sin(angle1) * cos(angle2);
        float z1 = sin(angle2);
        PVector v = new PVector(x1, y1, z1);
        
        xoff += inc;

        push();
        translate(x * scale, y * scale, z * scale);
        rotate(v.heading());
        stroke(0);
        line(0, 0, scale, 0);
        pop();
      }
    }
    yoff += inc;
    zoff += 0.0005;
  }
}

I added a third dimension loop and a angle2 variable initialized with noise() function, but I’m not quite sure what maths I should use to combine it with the angle1 noise.

Any help would be greatly appreciated !

Thanks.

A flow field is a vector field – a function that at any point (x,y) or (x,y,z) gives a vector (vx,vy) or (vx,vy,vz). Using noise functions to generate 2 angles, such as in polar coordinates, will give you uneven behavior at the poles. You could, instead, use 3 functions, for x, y, and z, and leave the angles out of it.

But also keep in mind that you do not need to use noise functions. A flow field can use any function, or combination of functions, that results in a vector. For instance this image uses a sum of seven rotated sine function:

3-D flow fields have the drawback that they are hard to see. An alternative to trying to see lines from every point in space is to trace only the endpoints as they move through interesting fields. Some functions converge into interesting stable regions called Strange Attractors. My favorite one, shown here: Steven Dollins: "Scatter 2 million particles and move them as P…" - genart.social - A Home For Generative Artists just uses a sine function around the swapped dimensions and adds in a "gravity’ component to keep the particles near the origin.

If you do want to trace the flow lines, you might see things better if you restrict yourself to a subset of points. Here: Steven Dollins: "Pardon my bed head. I just woke up. #generative…" - genart.social - A Home For Generative Artists I start the points randomly on the surface of a sphere and walk them outwards.