Sine wave Generation
I am working on a project that I want to output a sine wave of 50Hertz. I have defined it as follows:
`float amplitude = 10.0f;
float frequency = 50.0f;
//float phase = 0.0f;
float samples = 150.0f;
for (int t = 0; t<samples; t++)
{
float wt = (float)(amplitude * Math.Sin((2.0f * Math.PI * frequency * t /
samples)));``
}`
When I run the code I am not getting the expected results when I plot the values on a graph. Does any one know if I am doing this right or what my problem is. Thanks
See also questions close to this topic

Adding kepypress events to basic calculator form
I have made a basic calculator form in visual studio that is fully functional using the mouse click events. I am trying to add keyboard press events so you can use keyboard or mouse but am having trouble figuring it out.
I added some code for the keypress event but it only works if I mouse click the button first then the keyboard event will work, if I mouse select another number it stops working.
//Code that handles click events private void number_Click(object sender, EventArgs e) { if((txtResult.Text == "0")(operation)) { txtResult.Clear(); } //Cast button to the object sender operation = false; Button button = (Button)sender; //If the button pressed is a "." then check if the txtResult already contains //a ".", if it does contain a "." then do nothing if (button.Text == ".") { if (!txtResult.Text.Contains(".")) { txtResult.Text = txtResult.Text + button.Text; } }else txtResult.Text = txtResult.Text + button.Text; } //Keyboard press event code private void num1_key(object sender, KeyPressEventArgs e) { if (e.KeyChar == '1') { //If keyboard '1' pressed perform number_click() btn1.PerformClick(); e.Handled = true; } }
Is there anything glaringly obvious Im missing or am I on the wrong track?

Radio Streaming API
I was wondering if anyone knows of a good Radio Streaming API that I can use to allow users to search and listen to radio on my site.
I found TuneIn and iHeartRadio years back, but I can no longer find any information about these APIs, are they no longer live? I've seen some sites that offer Radio Streaming powered by TuneIn. If not available, any others I could use?
Thank you

Orchard Background tasks
I ve been wondering does orchard create a new thread each time it sweeps after 60 secondes ?
lets say for instance you have a background task which can be multiple tasks that we'll iterate :
public class MyBackGroundTask : IBackgroundTask { public void Sweep() { var AwaitingTasks = _TasksServices.GetAwaitingTasks(); foreach(var awaitingTask in AwaitingTasks) { // do something } } }
those tasks can take up to 30 minutes for example . does orchard creates a new thread for the Sweep() after one minute or he'll wait for the previous executed task to end ?
if so is there any good approach i can take to create a good queuing system ?
thanks in advance

Asteroids libGDX cosine and sine rotation equations, shooting bullets at wrong angle
I've made a Asteroids game for a Android device, but had trouble noticing that the player was standing in a direction but firing the bullet in another slightly displaced direction. I've looked through the code and it only happens when the player accelerates and rotates. Not when the player is only rotating. I hope this code is enough to tell you something about it to give me a suggestion.
The player is rotating in the correct direction while the bullet isn't. I tried putting the update functions in different orders but that didn't help either. I do not see what the problem is because when shooting the player class creates a bullet every time with the radians from the player. So I think it has something to do with that the radians aren't updated when the bullet is fired.
private void initForces() { maxSpeed = 300; acceleration = 200; friction = 10; } private void initRotationSpeed() { // Radians are used to determine the angle the player points in radians = MathUtils.PI / 2; rotationSpeed = 3; } public void shoot() { final int MAX_BULLETS = 4; if (bullets.size() == MAX_BULLETS  isHit()) return; bullets.add(new Bullet(x, y, radians)); } public void update(float dt) { if (updateCheckIfPlayerHit(dt)) { return; } updateCheckExtraLives(); // Forces updateAcceleration(dt); updateRotationSpeed(dt); updateTurning(dt); updateFriction(dt); // Set shape setShape(); // Screen wrap wrap(); } private void updateTurning(float dt) { // Turning: Tilt the screen to left or right to rotate the ship final float ROTATION_SENSITIVITY = 3; if (left  Gdx.input.getAccelerometerX() > ROTATION_SENSITIVITY) { radians += rotationSpeed * dt; } else if (right  Gdx.input.getAccelerometerX() < ROTATION_SENSITIVITY) { radians = rotationSpeed * dt; } } private void updateRotationSpeed(float dt) { x += dx * dt; y += dy * dt; } private void updateAcceleration(float dt) { // Accelerating if (up  Gdx.input.isTouched() && Gdx.input.getX() > 0 && Gdx.input.getX() < Gdx.graphics.getWidth() / 2) { dx += MathUtils.cos(radians) * acceleration * dt; dy += MathUtils.sin(radians) * acceleration * dt; } } private void updateFriction(float dt) { // Friction float vector = (float)Math.sqrt(dx * dx + dy * dy); if (vector > 0) { dx = (dx / vector) * friction * dt; dy = (dy / vector) * friction * dt; } if (vector > maxSpeed) { dx = (dx / vector) * maxSpeed; dy = (dy / vector) * maxSpeed; } }
Bullet.java
package com.mygdx.entities; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.MathUtils; public class Bullet extends SpaceObject { private float lifeTime; private float lifeTimer; private boolean remove; Bullet(float x, float y, float radians) { this.x = x; this.y = y; this.radians = radians; float speed = 350; dx = MathUtils.cos(radians) * speed; dy = MathUtils.sin(radians) * speed; width = height = 2; lifeTimer = 0; lifeTime = 1; } public boolean shouldRemove() { return remove; } public void update(float dt) { updateRotationSpeed(dt); wrap(); updateLifeTime(dt); } private void updateRotationSpeed(float dt) { x += dx * dt; y += dy * dt; } private void updateLifeTime(float dt) { // How long time the bullet is supposed to live lifeTimer += dt; if (lifeTimer > lifeTime) { remove = true; } } public void draw(ShapeRenderer shapeRenderer) { shapeRenderer.setColor(1, 1, 1, 1); shapeRenderer.begin(ShapeRenderer.ShapeType.Line); shapeRenderer.circle(x  width / 2, y  height / 2, width / 2); shapeRenderer.end(); } }
And to shoot with the player the code is:
if (Gdx.input.justTouched() && Gdx.input.getX() > Gdx.graphics.getWidth() / 2 && Gdx.input.getX() < Gdx.graphics.getWidth()) { player.shoot(); }

sine wave generation in c++
I am trying to generate a set of points, which when plotted as a graph represent a sine wave of 1 cycle. The requirements are :
 a sine wave of 1 cycle
 lower limit = 29491
 upper limit = 36043
 no of points = 100
 Amplitude = 3276
 zero offset = 32767
Code :
int main() { ofstream outfile; outfile.open("data.dat",ios::trunc  ios::out); for(int i=0;i<100;i++) { outfile << int(3276*sin(i)+32767) << "\n"; } outfile.close(); return 0; }
I am generating and storing the points in a file. When these points are plotted I get the following graph.
But I only need one cycle. How can I do this?
 a sine wave of 1 cycle

Why does sin not work on my Python?
When trying to do some basic trigonometry for Python turtle I decided to use sin, so I used:
import math num = math.sin(15)
It returned
0.650287840157
. I tried using the value but it was way off so I checked on my real calculator and I got0.2588190451
which did work.I tried to make it into
15.0
to see if it was to do with integer rounding because the value was not a float but it still returned the exact same result.Am I using it wrong or is there just an error in the library's function?