sinewave

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ciencia
    New Member
    • Aug 2008
    • 1

    sinewave

    I need help as soon as possible on making a sine wave I'm trying to do the equation y = Acos(2 (pi)/B x - 2(pi)/B P) amplitude A, period B, and phase shift P. It is not working out too well so can anyone help me refine this?

    Code


    #include <math.h>
    #include <stdio.h>
    #include <windows.h>

    #include "resource.h "

    // your path for this include may vary
    #include "GraphicsFramew ork.h"

    // Global variable to store the graphics framwork object
    GraphicsFramewo rk* PGraphics;

    HWND HOutput = 0; // handle to the output control
    HWND HDialog = 0;


    void DrawStuff()
    {
    COLORREF green = RGB(0, 255, 0); // green color to draw with
    COLORREF purple = RGB(255, 0, 255); // purple color to draw with

    char str[32]; // string to store user input
    double amplitude;
    double period;
    double phaseAngle;
    const double PI = 3.1415927; // constant Pi
    RECT rect; // rectangle for the output window
    int xMin, xMax, wdRect; // min & max x rectangle coords
    int y, x;

    // clear the scene and add an axis
    PGraphics->ClearScene(RGB (0, 0, 0));
    PGraphics->AddAxis(RGB(15 0, 150, 150), 10);

    // get the rectangle info for this window
    GetClientRect(H Output, &rect);
    wdRect = rect.right - rect.left;
    xMin = -wdRect / 2;
    xMax = wdRect / 2;

    // get the user input from the edit boxes and
    // convert string input to double
    GetDlgItemText( HDialog, IDC_EDIT_AMPLIT UDE, str, 32);
    amplitude = atof(str);
    GetDlgItemText( HDialog, IDC_EDIT_PERIOD , str, 32);
    period = atof(str);
    GetDlgItemText( HDialog, IDC_EDIT_PHASEA NGLE, str, 32);
    phaseAngle = atof(str);

    // Add the for loop here, that creates the points (x,y)
    //one pixel at a time and then adds the points via the
    // command PGraphics->AddPoint(x,y,g reen)
    y = amplitude cos(2(3.14)/period) x - (2(3.14)/period) phaseAngle);



    // draw the points
    PGraphics->Draw();
    }

    /*
    DialogProc
    this is the window event handler for the main dialog
    */
    BOOL CALLBACK DialogProc (HWND hwnd,
    UINT message,
    WPARAM wParam,
    LPARAM lParam)
    {
    switch(message)
    {
    case WM_INITDIALOG:
    // dialog is initializing - store the picture box handle in a global variable for later
    HOutput = GetDlgItem(hwnd , IDC_PICTURE_OUT PUT);

    // instantiate and initialize our graphics framework object
    PGraphics = new GraphicsFramewo rk(HOutput);

    break;

    case WM_COMMAND:
    switch(LOWORD(w Param))
    {
    case IDC_BTN_DRAW:
    // draw button was pressed
    DrawStuff();
    break;
    case IDC_BTN_CLEAR:
    // clear button was pressed so clear the scene and draw the empty scene
    PGraphics->ClearScene(RGB (0, 0, 0));
    PGraphics->Draw();
    break;
    case IDCANCEL:
    // user is quitting so release the GraphicsFramewo rk object and quit
    delete PGraphics;
    PostQuitMessage (0);
    break;
    }

    }
    return FALSE;
    }

    // this is the main function that starts the application
    int WINAPI WinMain(HINSTAN CE hInst, HINSTANCE hPrevInst, char * cmdParam, int cmdShow)
    {
    // create the main window
    // store its handle in a global if needed
    HDialog = CreateDialog (GetModuleHandl e(NULL),
    MAKEINTRESOURCE (IDD_DIALOG1),
    0,
    DialogProc);

    // make the dialog visible
    ShowWindow(HDia log, SW_SHOW);

    // standard windows message loop
    MSG msg;
    int status;
    while ((status = GetMessage (&msg, 0, 0, 0)) != 0)
    {
    if (status == -1)
    return -1;
    // avoid processing messages for the dialog
    if (!IsDialogMessa ge (HDialog, & msg))
    {
    TranslateMessag e ( & msg );
    DispatchMessage ( & msg );
    }
    }

    return (int)(msg.wPara m);
    }
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    You wrote ( or more likely copypasted ) the whole windows application source and screwed entirely the very line of ( you own ) calculation with phase, amplitude and stuff. You can't just leave blanks for multiplications like in formulas, use that starry stuff for it. And you know, your compiler must have written something like 'error: line xxx: wrong_stuff_goe s_here' - it's useful to tell us about them to let people not guess.

    Comment

    Working...