The thing is, we are here to help, not do the work for you. If you have any trouble or questions, we will help you.
Also, what does this 3d sine wave look like?
Or...
If you want it to look like the last image, take a closer look at it, it has some useful equations for you. Take a look at the walls of the graph.
So all i have to do is plug the equations into my code like this:
for(int x = 0; x < 7; x++){
for(int y = 0; y < 7; y++){
Z = sin(phase + sqrt(pow(map(x,0,7,-PI,PI),2) + pow(map(y,0,7,-PI,PI),2)));
Z = round(map(Z,-1,1,0,7));
setvoxel(x,y,Z);
}
}
My only question now is how would i vary the phase?
To animate, work out the previous z cooridinate for the x and y and the new coordintate. If they are different, then clear the old one ans set the new one.
If you want it faster, save the coordinates in an array.
PaulMurrayCbr:
To animate, work out the previous z cooridinate for the x and y and the new coordintate. If they are different, then clear the old one ans set the new one.
If you want it faster, save the coordinates in an array.
Maybe this will help:
x: sin wave
y: cos wave
z: time
If you think about it, if you just consider 1 dimension then you will get a sin wave, if you consider 2 dimensions then you get a circle, and if you consider 3 dimensions you get a moving circular spiral.
OK so i got that now all i have to do is make it move by varying the phase. A lot of people have told me to vary it between 0 and 2PI, how would i do that? Would i use a for loop and what would i increment it by?
circuitdh:
OK so i got that now all i have to do is make it move by varying the phase. A lot of people have told me to vary it between 0 and 2PI, how would i do that? Would i use a for loop and what would i increment it by?
Thanks for all the help and responses! :]
for (phase = 0; phase<TWO_PI ; phase+=increment) { /...
The amount of increment really depends on how rapidly you want it to change.
So, I got bored and decided that the best way to show you was to build my own led cube and program it for you, but I didn't want it to be a wussy cube, so I made it RGB to make it pop. Anyways checks to see if anybody believed that story
void sineWave3d(){
byte y[8][8];
float rads = 0;
float t = 0;
while(1){
for(int x = 0; x < 8; x++){
for(int z = 0; z < 8; z++){
rads = ((float)sqrt((x-4)*(x-4) + (z-4)*(z-4)) / 4.) * 3 + t; //change that 3 to make it shrink/expand
t += 0.005; //time, change this to make it speed up/slow down
while(t > TWO_PI) //limit to 2PI, wrap around if overflow
t -= TWO_PI;
while(rads > TWO_PI) //limit to 2PI, wrap around if overflow
rads -= TWO_PI;
setLED(x, y[x][z] , z, 0, 0, 0); //clear old LED
y[x][z] = 4 + sin(rads) * 3.999; //this is where the magic happens
setLED(x, y[x][z], z, r, g, b);
}
}
delay(50);
}
}
This works because the LED chosen to light up is based on the distance from the center, that distance is put into the sine function. Then a time variable is added, which causes an animation. If you want to make more sense of it, convert this code for yourself and simply comment "t += 0.005" which will make it all stand still.
my last and final question is how would i alter the direction/axis of the sine wave? (its going side to side instead of up/down)
THAN YOU so much for the help
Post your code, because if it is going side to side, you are doing something wrong.
setLED(x, y[x][z], z, r, g, b);
This code right here should only variate the y position, which makes me believe that your setVoxel function is mixing up the y position with the x or z position...