Firework: Circle with cosine & sine but in 3D....?

Hello all,

I made a fire work in 2D (its movement is 2D anyway) with a simple formula using cos and sin.

  void move() {

    // Spark move 

    // move 
    x = centerX+cos(angle)*radius;
    y = centerY+sin(angle)*radius;

    radius+=radius_Add; 

    if (radius>maxRadius)
      isDead=true;
  }// function 

My question is, how can I make it so that the movement would be 3D (sparks fly away forming a full sphere)

  void move() {

    // Spark move 

    // move 
    x = centerX+cos(angle)*radius;
    y = centerY+sin(angle)*radius;
    z = centerZ+????????????(angle)*radius;

    radius+=radius_Add; 

    if (radius>maxRadius)
      isDead=true;
  }// function 

(full 2D movement sketch Some Movies I made )

Thanks all!

Chrisir

1 Like

One way is to rotateY before translating x,y – so different circles of sparks will fly in different directions. This won’t look like a sphere, though, more like a beachball.

Another option is to plot the point on a sphere, then scale it as it flies out. Multiple methods of doing that – one by you (!)…

2 Likes

Hello @Chrisir,

This was just me tinkering with formulas.
There may be something useful in this for you; I know I will play with this some more!
Thanks for inspiring me.

void draw()
  {
  translate(width/2, height/2);
  rotateX(TAU/4);
  
  for(float angle = 0; angle < TAU; angle += TAU/100)
   {
   move(angle, t, radius);
   strokeWeight(3);
   stroke(255, 255, 0);
   point(x, y, z);
   }
   
  radius += radius_Add;
  t += .1;
  }


void move(float angle, float t, float radius) 
  {
  x = radius*cos(angle);
  y = radius*sin(angle);
  z = 100*(1-pow(exp(1.0), 1-t/5));
  
  //radius += radius_Add;
  //t += .1;
  }

2 Likes
float t, radius;
float x, y, z;
float radius_Add=2; 

float yadd=-9; 

float speed= 44; 

void setup() {
  size(1900, 900, P3D);
  background(0);
  y=height-533;
}

void draw() {
  // background(0); 
  translate(width/2, height/2);
  // rotateX(TAU/4);

  for (float angle = 0; angle < TAU; angle += TAU/speed) {
    move(angle, t, radius);
    strokeWeight(3);
    stroke(255, 255, 0);
    point(x, y, z);
  }

  radius += radius_Add;
  t += .1;

  y += yadd; 
  yadd += 0.09;

  speed+=1;
  if (speed>100)
    speed=100;
}

void move(float angle, float t, float radius) {

  x = radius*cos(angle);
  z = radius*sin(angle);

  // y = 4- 100*(1-pow(exp(1.0), 1-t/5));
  //radius += radius_Add;
  //t += .1;
}
3 Likes

I like it!

I had the formula for capacitors charging on my mind and did not want the fireworks to end.

:slight_smile:

1 Like

Thanks again!

4 Likes