Go Down

Topic: Sine wave (Read 2819 times)previous topic - next topic

circuitdh

Apr 08, 2016, 01:58 am
Can someone please give me some code for a 3d sine animation on my 8x8x8 led cube

I already have the led cube's basic output function.

declaring  setvoxel(x,y,z);   will set a pixel on the cube on.

declaring  clrvoxel(x,y,z);   will set a pixel on the cube off.

I just need a 3D sine wave code!
I'm usually the one needing help!

aarg

#1
Apr 08, 2016, 02:44 amLast Edit: Apr 08, 2016, 02:46 am by aarg
sin() and cos(), and oh, I forgot DEG_TO_RAD. That's all you really need to get started.
... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

circuitdh

#2
Apr 08, 2016, 03:31 am
can you give me the actual code?
I'm usually the one needing help!

Ps991

#3
Apr 08, 2016, 03:36 amLast Edit: Apr 08, 2016, 03:38 am by Ps991
can you give me the actual code?

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.
If you can't write your program in plain english where anyone could understand it then you have no hope of writing code for it.  -Delta_G

circuitdh

#4
Apr 08, 2016, 04:56 am
Thank you for the help!

So all i have to do is plug the equations into my code like this:

Code: [Select]
`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?

thanks for the help!
I'm usually the one needing help!

PaulMurrayCbr

#5
Apr 08, 2016, 06:22 am
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.

Now what I'd like to see is electron orbitals.
http://paulmurraycbr.github.io/ArduinoTheOOWay.html

circuitdh

#6
Apr 08, 2016, 06:40 am
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.

sorry i don't fully understand what you mean. :{

I haven't taken trig yet...
I'm usually the one needing help!

Ps991

#7
Apr 08, 2016, 07:06 am
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.

If you can't write your program in plain english where anyone could understand it then you have no hope of writing code for it.  -Delta_G

circuitdh

#8
Apr 08, 2016, 07:58 amLast Edit: Apr 08, 2016, 08:23 am 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!  :]
I'm usually the one needing help!

Ps991

#9
Apr 08, 2016, 10:29 am
x: sin(time)
y: cos(time)
z: some function that describes distance per time, for example, 1 circle takes 2PI time, so do (2PI * 8 LEDs) / time

This way it will cycle through the circular motion across the cube every 1 second, slow it down by making (2PI * bigger
If you can't write your program in plain english where anyone could understand it then you have no hope of writing code for it.  -Delta_G

MarkT

#10
Apr 08, 2016, 01:42 pm
and if you consider 3 dimensions you get a moving circular spiral.

helix, not spiral.  spirals are 2D
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

circuitdh

#11
Apr 09, 2016, 01:31 am
sorry but can i please have a small example code?  How would i increment between 0 and 2PI.
Thanks!
I'm usually the one needing help!

Ps991

#12
Apr 09, 2016, 05:39 amLast Edit: Apr 09, 2016, 05:40 am by Ps991
How would i increment between 0 and 2PI.
Code: [Select]
`...rads += 0.01; //0.01 is just an example, rads is a floatif(rads >= TWO_PI)  rads -= TWO_PI; //bring it back into the correct domain...`
If you can't write your program in plain english where anyone could understand it then you have no hope of writing code for it.  -Delta_G

circuitdh

#13
Apr 09, 2016, 06:27 amLast Edit: Apr 09, 2016, 06:52 am by circuitdh
Here is a 2D example of what i'm tring to accomplish I would like to be able to vary the wave with the slider of a.  The output should be between the black lines

Is there an easy way to do this?
Note:  Thank you Ps991 for helping me on this project!

here is a link for the wave
I'm usually the one needing help!

aarg

#14
Apr 09, 2016, 09:37 am
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!  :]
Code: [Select]
`for (phase = 0; phase<TWO_PI ; phase+=increment) { /... `

The amount of increment really depends on how rapidly you want it to change.
... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

Go Up