How does sin() work?
in
Programming Questions
•
1 year ago
I am starting to think I have a fundamental misunderstanding of how sin() works.
e.g. the following code (just lines 12 and 14 are of interest here)
The first time through the draw() function, the angle is, I think 0 so sin(0)*amplitude = 0*50 = 0
Next time through and the angle is now -PI so sin(-PI)*amplitude = 0*50 = 0
And the angle becomes -2*PI and so sin(-2*PI)*amplitude = 0*50 = 0
and so on....
But how does this allow for the other value? It seems to me that the code should only give values of 0.
Thanks,
Shane
e.g. the following code (just lines 12 and 14 are of interest here)
- float XsinVal, angle, frequency = PI;
- int XequiPos = 100; //the x-coordinate of the equilibrium position
- int YequiPos = 100; //the y-coordinate of the oscillation
- int amplitude = 50;
- void setup() {
- size (300, 300);
- }
- void draw() {
- background (127);
- stroke(0);
- fill(0);
- XsinVal = sin(radians(angle))*amplitude;
- ellipse(XequiPos + XsinVal, YequiPos, 3, 3);
- angle -= frequency;
- }
The first time through the draw() function, the angle is, I think 0 so sin(0)*amplitude = 0*50 = 0
Next time through and the angle is now -PI so sin(-PI)*amplitude = 0*50 = 0
And the angle becomes -2*PI and so sin(-2*PI)*amplitude = 0*50 = 0
and so on....
But how does this allow for the other value? It seems to me that the code should only give values of 0.
Thanks,
Shane
1