Sine wave output generation

This is a discussion on Sine wave output generation within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, I am doing a project, and currently stuck at middle of c++ programming. I am anticipating an output ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    2

    Sine wave output generation

    Hi everyone,

    I am doing a project, and currently stuck at middle of c++ programming. I am anticipating an output which the value is fluctuating between -1 and 1, just as sine wave. The software I am using is Microsoft Visual Studio.

    To cut it short, I will roughly jot down the important part of my program code:

    Code:
    #include <cmath> //header to retrieve trigonometry function
    
    ...
    int x = 0;
    long double rad = 0;
    long double sin (long double y)
    long double result;
    
    int main()
    {
    
    ...
    
    outputgenerate();
    
    ...
    
    }
    
    outputgenerate()
    {
    rad = (x/180) * M_PI; //(M_PI is defined as 3.14159) convert degree to radian
    result = sin (rad); // the result will show the sine wave
    
    x += 1;
    if (x = 361)
    {
    x = 0; //x is the value of angle which increase from 0 to 360, then back to zero again, thus formed a loop
     }
    }
    I suppose other parts of my programming is running fine, because I am doing the robot simulation based on Open Dynamics Engine, and the robot runs fine with simpler code.

    The only problem faced at the moment is the sine function. Please provide me some advise for the situation above, Thank you very much.

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    344
    Code:
    if (x = 361)
    This assigns 361 to x. Use == if you want a comparison.

    Also be aware that you're redefining sin() to use long doubles, which may confuse things if you link it against a standard library implementation which doesn't use them.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    2
    You got it right, my problem solved.

    Appreciated for helping!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Efficient Sine Wave Generation
    By samGwilliam in forum C++ Programming
    Replies: 1
    Last Post: 05-24-2007, 07:37 PM
  2. Sine Wave Program
    By Stiks in forum C Programming
    Replies: 10
    Last Post: 10-15-2005, 01:35 AM
  3. Help producing sine wave
    By ricky1981 in forum C++ Programming
    Replies: 9
    Last Post: 10-31-2003, 09:20 PM
  4. ...simple sine wave?
    By Sebastiani in forum C++ Programming
    Replies: 27
    Last Post: 12-15-2002, 02:12 PM
  5. Sine Wave Program Help
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-19-2001, 01:33 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21