Designated 'zones' for bezier arguments

I am trying to make a 3d project that has some bezier curves ‘spewing’ out of the center of the entire project. I want to restrict the arguments to their own ‘zones’, and by that I mean that I want to keep the arguments within a certain range of units from the center, for example keeping the first control point within 50 to 100 units from 0,0,0 in all directions. I am new to processing 3, and I would like if someone could take the time to explain to me how to restrict things to a ‘zone’. Thanks!
I have the code here below:
int amount=300;
int[]a=new int[amount];
int[]b=new int[amount];
int[]c=new int[amount];
int[]d=new int[amount];
int[]e=new int[amount];
int[]f=new int[amount];
int[]x=new int[amount];
int[]y=new int[amount];
int[]z=new int[amount];
void setup(){
size(725,725,P3D);
background(0);
noFill();
stroke(255);
strokeWeight(1);
smooth();
for(int i=0;i<amount;i++){
a[i]=int(random(-50,50));
b[i]=int(random(-50,50));
c[i]=int(random(-50,50));
d[i]=int(random(-100,100));
e[i]=int(random(-100,100));
f[i]=int(random(-100,100));
x[i]=int(random(-150,150));
y[i]=int(random(-150,150));
z[i]=int(random(-150,150));
}
}
void draw(){
background(0);
translate(width/2,height/2);
rotateY(frameCount/100.0);
stroke(255);
box(300);
for(int i=0;i<amount;i++){
stroke(random(0,255),random(0,255),random(0,255));
bezier(0,0,0,a[i],b[i],c[i],d[i],e[i],f[i],x[i],y[i],z[i]);
}
}

1 Like

And by that I mean that I want to keep the arguments within a certain range of units from the center, for example keeping the first control point within 50 to 100 units from 0,0,0 in all directions

If I understand you correctly, then your difficulty is that when choosing a “range”, you actually want two separate things, which just happen to sound like one thing.

First, you want your control points to be in random directions, and
Second, you want those control points to be within some upper and lower bounded range from the center.

In which case, how about treating them as vectors?

For each control point, create a vector with each component in the range -1, 1 with PVector c1 = new PVector(random(-1,1), random(-1,1), random(-1,1). Then, after normalizing that vector, scale it to be within the bounded distance from the center c1.mult(random(50, 100)).

Here is a full modification

int amount=300;

int[]a=new int[amount];
int[]b=new int[amount];
int[]c=new int[amount];
int[]d=new int[amount];
int[]e=new int[amount];
int[]f=new int[amount];
int[]x=new int[amount];
int[]y=new int[amount];
int[]z=new int[amount];
void setup(){
  size(725,725,P3D);
  background(0);
  noFill();
  stroke(255);
  strokeWeight(1);
  smooth();
  for(int i=0;i<amount;i++){

    PVector c1 = new PVector(random(-1, 1),random(-1, 1),random(-1, 1));
    PVector c2 = new PVector(random(-1, 1),random(-1, 1),random(-1, 1));
    PVector c3 = new PVector(random(-1, 1),random(-1, 1),random(-1, 1));
    
 
    c1.normalize();    
    c2.normalize(); 
    c3.normalize(); 
      
    c1.mult(random(190, 200));
    c2.mult(random(190, 200));    
    c3.mult(random(190, 200));
           
   
    a[i]=int(c1.x);
    b[i]=int(c1.y);
    c[i]=int(c1.z);
    d[i]=int(c2.x);
    e[i]=int(c2.y);
    f[i]=int(c2.z);
    x[i]=int(c3.x);
    y[i]=int(c3.y);
    z[i]=int(c3.z);
  }
}
void draw(){
  background(0);
  translate(width/2,height/2);
  rotateY(frameCount/100.0);
  stroke(255);
  box(400);
  for(int i=0;i<amount;i++){
    stroke(random(0,255),random(0,255),random(0,255));
    bezier(0,0,0,a[i],b[i],c[i],d[i],e[i],f[i],x[i],y[i],z[i]);
  }
}

Do note that as you’ve written it, you’ve hard coded your first control point to always be at 0,0,0 with bezier(0,0,0,a[i],b[i],c[i],d[i],e[i],f[i],x[i],y[i],z[i]); I’m not sure if that was intentional. Also note that the approach suggested above will not prevent the actual path generated from crossing through a region you didn’t want to allow the control points in (since a sequence of two randomly generated control points can be on opposite ends of the cube).

If you want to also prevent the path from even crossing through a forbidden region, then you might try something like

int amount=200;

int[]q=new int[amount];
int[]r=new int[amount];
int[]s=new int[amount];
int[]a=new int[amount];
int[]b=new int[amount];
int[]c=new int[amount];
int[]d=new int[amount];
int[]e=new int[amount];
int[]f=new int[amount];
int[]x=new int[amount];
int[]y=new int[amount];
int[]z=new int[amount];
void setup(){
  size(725,725,P3D);
  background(0);
  noFill();
  stroke(255);
  strokeWeight(1);
  smooth();
  for(int i=0;i<amount;i++){
    PVector c0 = new PVector(random(-1, 1),random(-1, 1),random(-1, 1));
    PVector c1 = new PVector(random(-1, 1),random(-1, 1),random(-1, 1));
    PVector c2 = new PVector(random(-1, 1),random(-1, 1),random(-1, 1));
    PVector c3 = new PVector(random(-1, 1),random(-1, 1),random(-1, 1));
    
    c0.normalize();
    c1.normalize();    
    c2.normalize(); 
    c3.normalize(); 
    
    if(c1.dot(c0) < 0) c1.mult(-1);
    if(c2.dot(c1) < 0) c2.mult(-1);
    if(c3.dot(c2) < 0) c3.mult(-1);
    
    c0.mult(random(190, 200));
    c1.mult(random(190, 200));
    c2.mult(random(190, 200));    
    c3.mult(random(190, 200));
       
    
    q[i]=int(c0.x);
    r[i]=int(c0.y);
    s[i]=int(c0.z);
    a[i]=int(c1.x);
    b[i]=int(c1.y);
    c[i]=int(c1.z);
    d[i]=int(c2.x);
    e[i]=int(c2.y);
    f[i]=int(c2.z);
    x[i]=int(c3.x);
    y[i]=int(c3.y);
    z[i]=int(c3.z);
  }
}
void draw(){
  background(0);
  translate(width/2,height/2);
  rotateY(frameCount/100.0);
  stroke(255);
  box(400);
  for(int i=0;i<amount;i++){
    stroke(random(0,255),random(0,255),random(0,255));
    bezier(q[i],r[i],s[i],a[i],b[i],c[i],d[i],e[i],f[i],x[i],y[i],z[i]);
  }
}

Which would result in something like this.

The relevant sequence there is

  if(c1.dot(c0) < 0) c1.mult(-1);
  if(c2.dot(c1) < 0) c2.mult(-1);
  if(c3.dot(c2) < 0) c3.mult(-1);

Which serves to check if a given vector is going in the opposite direction as a preceding vector, and, if it is, multiplies it by -1, thereby ensuring the path between them doesn’t cross the sphere.

4 Likes

Wow! Thank you. It probably will take me a while to digest it all but I bet I can understand it if I take my time. I have worked with PVector before, but I did not understand it very well. All i knew I could use it for was to make some planets on another project that I made orbit around the sun that I made.