C++ :: How To Calculate X And Y In Sine Wave
Apr 24, 2012
I have the following initial code:
Code:
double objectAngle = -90.0f;
double objectSpeed = 3.0f; // meters per second
double objectDistance = 300.0f;
double objectTime = 0.0f;
double objectHeading = 90.0f;
double elapsedTimePerCycle = 1.0f;
My coordinate system looks like this:
Code:
90 y
|
|
|
+-180 -------------------- 0 x
|
|
|
-90
I want to calculate a new x,y such that it follows a sine wave like pattern until it gets to point (0,0). I want the width of the arc to go out to about -45 degrees, and the same on the other side to about -135 degrees.
How can I compute these new x,y coordinates in C++?
View 14 Replies
ADVERTISEMENT
May 4, 2014
I am currently working on an arcade game for my final assignment this year. I am struggling to get a sine wave movement with the saucer. Here is the code for it:
void ArcadeGame::spawnSaucer() {
Texture* pTexture = getTexture("saucertexture");
m_pSaucer = new GameObject(pTexture, "saucer");
m_pSaucer -> setPosition(1000, 300);
m_pSaucer -> setVelocity(-1, 10 * sin(1 * 3 * PI / 180), sin(1) * OBJECT_DEFAULT_SPEED);
addGameObject(m_pSaucer);
m_pSaucer->setSolid(true);
}
View 8 Replies
View Related
Mar 7, 2014
I need to create a sinewave. I have the values in an Excel file. The code reads the excel file and prints the values in the cmd but I need it to print back into excel as a sine wave. Pretty sure its currently values for a triangle wave but whatever I want a wave before I care about the type.
Description: Creates an array of values of a triangle wave, prints the result to the screen and creates a CSV (comma separated variable) file of data points. Allows user to enter number of amplitude and number of cycles
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define N_SAMPLES 1000 // crashes if array size > 1000?
#define UP 1
#define DOWN 0
[Code] ....
View 11 Replies
View Related
Mar 11, 2013
I'm doing a mixer with wave files. I can play and even apply the reverse effect to them. the logarithm is like this:
for( unsigned int i=0; i<sampleCount/2; i++ )
{
// swapping with the other half
double temp = samples[i];
samples[i] = samples[sampleCount-i-1];
samples[sampleCount-i-1] = temp;
}
Now I want to apply these effects to the files: delay, slow, and fast but I don't know how to do it. The teacher told me that to do it slow I need to double the Samples so I tried to do this samples[i] = samples[sampleCount*2]; it does not work......Also I apply the contrary to do make the sound fast samples[i] = samples[sampleCount/2]; the samething I don't get the sound desired.
For the daley part I'm thinking on play the audio one without touch it and then repit it 8 times or more to create the delay.... I did it like this:
double temp = samples[i];
samples[i] = samples[sampleCount-i-1]+ (samples[sampleCount -i-1]*8);
It didn't work..why the use of -i-1 after sampleCount!!
View 1 Replies
View Related
May 31, 2012
I have problem with this code:
Code:
#include <string>
#include <fstream>
#include <iostream>
#include <cstdlib>
using namespace std;
// multiplier
const double MULTIPLIER = 0.0000001;
[Code] .....
It should cut wav files into smaller pieces using text file .lab (the values multiplied by * 0.0000001 gives time in second. For example, i have such file with recorded yes and no: [URL] ..... and such boundaries [URL] .... It all should be in the same folder, then, after puting "yesno.wav" into command line and press enter it should gives 2 files with yes and no words. But it doesnt - i obtained one file with silent and one short sound. The record is recorded by Audacity, default sample rate 44100, default sample format 16-bit.
View 10 Replies
View Related
Jun 2, 2013
I have built the wave tool and now am trying to run my source code through it. But it just doesn't want to find the include directory. I just don't understand. Here's my command:
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
Perhaps it how I built it since there is no info on how to do this? I just ran ../b2.exe from the boost_1_53_0/tools directory.
I'm running CYGWIN_NT-6.1-WOW64 TARDIS 1.7.18(0.263/5/3) 2013-04-19 10:39 i686 Cygwin with a g++ version of 4.5.3. g++ has no problem finding the default include directory (I don't have to specify the -I switch). The -I switch doesn't seem to work for any of the other include directories that I wan to use either, but I want this cleared up before I get into that since it might be related.
View 2 Replies
View Related
Apr 21, 2014
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include "dp_lib.h"
int main() {
int A =1;
[Code]...
im new to coding but ive written this code for an assignment and it creates 2 sine waves and adds them together but i want to be able to create a range of different sine waves at different frequencies and play them one after the other like in my code,but with the end result being that i would like each sine wave to represent a different note, so when your on the the console screen the user will be able to choose from a select number of notes and input them in any order so that the WAV file produced plays the sine waves in the order the user chooses so they can make a simple tune. but my code only plays it in the order it is in the code
View 8 Replies
View Related
Apr 26, 2013
I am basically trying to make a program for a calculator. I am struggling with how to do the sine calculation. this calculation will take place at line 158.
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double firstNumber = 0.0;
double secondNumber = 0.0;
char operation =' ';
[Code] ....
View 1 Replies
View Related
Apr 18, 2014
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include "dp_lib.h"
int main() {
int A =1;
float* data;
[Code] ...
I am doing ive written this code that creates 2 sine waves and adds them together but my question is that im trying to write a code where i can create multiple sine waves assign each sine wave to a separate values (musical notes ie A B C) and then be able to add them together in any order to create a tune.
View 2 Replies
View Related
May 21, 2014
I'm having trouble with getting a sine function to work. All variables are defined earlier in the same section. I have the code in a button (where I figured it would go) but I get the following error:
WindowsFormsApplication2.Math does not contain a definition for 'Sin'
For reference, I am using Microsoft Visual Studio Express 2013, and am coding a Windows Forms Application.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
[Code] ....
I've tried other functions as well (abs, sqrt, etc.) to no avail, as Math only seems to pop up with two options: Equals and ReferenceEquals.
View 2 Replies
View Related
Dec 22, 2014
Write a C program with a separate function which calculates the sine function from the first principles according to the formula below. The code should find the sine value in 5 stages and then final answer
formula below :
sin(x) = x −x3/3!+x5/5!−x7/7!+x9/9!
I have done the code and it just gives me a final sine wave
it should find a error then plus one so on till it gets the answer
Link:
These are images of what it should look like and the image of a the formula ....
View 7 Replies
View Related
Jun 3, 2013
I am writing a program to solve a triangle. Given any three pieces of information, find the other three. I am having trouble with SSA. I use the cosine law to find the unknown side. Then I use the sine law to find the other two angles. The sine law will give me each of the other angles. If one of the unknown angles is over 90 degrees, my program gives an angle as under 90 degrees. Not surprisingly, the correct angle and my wrong angle add up to 180 degrees. If you draw out the triangle you can deduce the right answer. How to have my program find out when the angle needs to be over 90 degrees.
View 5 Replies
View Related
Nov 10, 2012
My assignment is to create a C++ Program to find the sine of a number without any library other than iostream by using Taylor Series:
sin (x) = (x/1!) - (x^3/3!) + (x^5/5!) - (x^7/7!) + (x^9/9!) ...... (x^n/n!).
Here is what i have done till now:
#include <iostream>
double fact (int f); //declaration of factorial function
double power(double x, int y); //declaration of power function
double sin(int x); //declaration of sine function
//double cos(int x); //declaration of cosine function
//double tan(int x); //declaration of tangent function
[code]....
View 3 Replies
View Related
Jul 12, 2013
I'm trying to write a program to calculate an approximate value of e using the formula e = 1 + 1/1! + 1/2! + ....... 1/n!...However, I'm always getting nearly 2.291481 as answer.Here is my code :
Code:
//Approximate the value of e
#include <stdio.h>
int main(void) {
int n, j;
printf("Please enter value of n : ");
scanf("%d", &n);
[code]....
I know I'm not supposed to use system("PAUSE"), but this is self-study.
View 8 Replies
View Related
Oct 7, 2013
I'm trying to successfully run a program that calculates your BMI but, although it runs, it is not giving the the correct math. Instead, it gives me the number i've submitted as my weight as an answer. I'm using Visual Studio 2008 and the formula: weight / (height/100)*2
Here is my code
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int weight;
int height;
double BMI;
[Code] ....
View 2 Replies
View Related
Jan 1, 2013
Let's say I want to calculate something like PI using some algorithm, but with the number of digits I want to.
View 1 Replies
View Related
Nov 22, 2014
I want calculate sum of every digit in my zip code so I wrote implementation function like that but, it shows "0" as answers, then I realize it should be call first, I add correctionDigitOf() in to constructor "Zipcode::Zipcode" then My zipcode are all "0' after I do this .....
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <ctime>
#include <cmath>
using namespace std;
class Zipcode {
[Code] ....
View 1 Replies
View Related
Aug 7, 2012
Contributions won't calculate ...
#include <stdio.h>
#include <conio.h>
int main() {
float tax;
float salary;
float taxable;
float taxmo;
float contributions;
[Code] .....
View 1 Replies
View Related
Mar 22, 2013
I was given an assignment for class to calculate the area of a circle using only the radius as a user input and not using Pi in the code. I need to do this by calculating the areas of a series of rectangles under the curve and adding them together. Using nested loops to continuously reduce the size of these rectangles until the approximated area value is within a margin of error less than 0.1%.
Code:
#include<iostream>
#include<cmath>
using namespace std;
int main ()
[Code] .....
View 7 Replies
View Related
Feb 20, 2014
My question is not in c++ programing , but because my aim is to make code that calculate the three angles between two vector i ask my question here
So as the title i have three point that create two vector and I want to get the angles in x,y and z of the point2
I used crosproduct that give me one angle without axe , I don't know in which axe this angle
My aim is the three angles for the 3 axes ....
View 7 Replies
View Related
Aug 3, 2014
Now I know there's a simple way to calculate highest value. But here i have this algorithm which i understood part of it.
I know that *largest is point to the first element of begin which is 5. so in the first if statement its 5<5 at the first iteration ?
// i marked the parts i didnt understand with " //"
Code:
#include <stdio.h>
int *print(int *begin ,int *end ){
if(begin==end)
return 0;
int *largest = begin;
[Code] ....
View 10 Replies
View Related
May 23, 2013
I have to calculate the value of PI with the accuracy (eps) given by the user. I started with this but I just got stuck now, I don't know what is going on with the code or why does it get stuck in the second iteration...
PHP Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(){
float eps=0.000001;
[Code] ....
View 4 Replies
View Related
Nov 23, 2013
What the range of values and how to calculate them?
int Num = rand() % 350 + 13 / 10
View 2 Replies
View Related
Jul 11, 2014
I have a program that will calculate max, average, etc from a file of numbers. However, I cannot get it to calculate standard deviation.
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cmath>
[code]....
View 4 Replies
View Related
Jan 3, 2013
calculate the factorial with function
The program should then calculate the factorial of the number n, where n!= n×(n −1)...× 2×1
the output like this:
Enter number: 4
Factorial of 4! = 24
Enter number: 6
Factorial of 6! = 720
Enter number: 3
Factorial of 3! = 6
Enter number: 0
Factorial of 0! = 1
Enter number: -5
Factorial of -5! = -1
Press any key to continue . ....
View 7 Replies
View Related
Dec 29, 2012
How can we calculate tax of vehicle with polymorphism? There are 3 types of vehicles: long, commercial, and private vehicles' classes. There is a common class about all vehicles.
BASE class:
1.Brand and series name (such as Toyota Corrolla, Isuzu etc.)
2.Year of production (you can term it model)
3.Engine size in dm3
4.Owner’s name (including surname) and identity
5.Plate number.
COMMERCİAL :
1.Number of seats (apart from the driver)
2.Data to indicate whether the commercial vehicle is allowed to operate at night.
LONG :
1.The tonnage (max load in tons)
2.Data to indicate whether the long vehicle is allowed to carry goods internationally.
PRİVATE:
1.The class label which can be one of {A,B,C} .
View 1 Replies
View Related