Need Help Rotating An Image Around A Graph

Discussion in 'C++' started by AJ, Dec 15, 2009.

  1. AJ

    AJ Guest

    AJ

    Hey everybody, I don't know if this a programming question or more of
    a math question. I need to rotate a image around a canvas window that
    represents a graph. So what i know is this i take the images x and y
    coordinates and put them into the atan2 function that gives me the
    original angle. In my main program i have a variable named theta that
    increments each frame. The theta variable tells me how many degrees to
    rotate the original image to get the next frame. Know i am confused
    with how to use the new angle and to find the new position of the
    image. I am really stumped. What I have worked out so far is that i
    will probably need to use cosine or sine with the new angle. But from
    what I can understand the x and y are different so what should i enter
    into the trig functions to get the new image.

    Here is the program thus far
    ##########################################################################################
    ConvertPoint::ConvertPoint(double& x, double& y, double angle)
    {
    // x_rot, y_rot and a are all member variables
    x_rot = x;
    y_rot = y;
    a = angle;

    x_rot = x_rot - 250;
    y_rot = y_rot - 250;

    double angle = atan2(x_rot,y_rot)
    a = a + angle;

    }
    ##########################################################################################
    AJ, Dec 15, 2009
    #1
    1. Advertising

  2. AJ wrote:
    > Hey everybody, I don't know if this a programming question or more of
    > a math question. [..]


    Either way, it seems off-topic. Programming questions should go to the
    'comp.programming' newsgroup, and math questions should go to 'sci.math'
    hierarchy. Here we talk C++ language. There is also the newsgroup
    'comp.graphics.algorithms' where folks can help you to rotate your
    images efficiently.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Dec 15, 2009
    #2
    1. Advertising

  3. AJ

    AJ Guest

    On Dec 15, 3:30 pm, Victor Bazarov <> wrote:
    > AJ wrote:
    > > Hey everybody, I don't know if this a programming question or more of
    > > a math question. [..]

    >
    > Either way, it seems off-topic.  Programming questions should go to the
    > 'comp.programming' newsgroup, and math questions should go to 'sci.math'
    > hierarchy.  Here we talk C++ language.  There is also the newsgroup
    > 'comp.graphics.algorithms' where folks can help you to rotate your
    > images efficiently.
    >
    > V
    > --
    > Please remove capital 'A's when replying by e-mail
    > I do not respond to top-posted replies, please don't ask


    Thank you for informing of the correct groups where i can pose my
    question.
    As for a c++ language question I need help solving an error i keep
    receiving.

    the error is:
    csci135p6spinmain.cpp:72: error: ‘circle’ was not declared in this
    scope
    csci135p6spinmain.cpp:73: error: ‘line’ was not declared in this scope

    Here is the Program
    ###################################################################################
    #include <iostream>
    #include <fstream>
    #include <sstream>
    #include <string>
    #include "csci135canvas.h"
    #include "csci135p6spincircle.h"
    #include "csci135p6spinline.h"
    #include "csci135p6spinconvertpoint.h"

    using namespace std;

    void PaintFunction(Canvas &canvas)
    {
    canvas.Erase();
    double theta = 0;

    ifstream image;
    string specs;

    image.open("image.canvas.txt");

    if(image.is_open())
    {
    while(image.good())
    {
    string type;
    getline(image,specs);
    stringstream paint(specs);
    paint>>type;

    if(type == "circle")
    {
    double xcenter, ycenter, radius;

    stringstream art(specs);
    paint>>xcenter>>ycenter>>radius;

    Circle circle(xcenter,ycenter,radius);
    circle.draw(canvas,theta);
    }

    else if(type == "line")
    {
    double xpos1, ypos1, xpos2, ypos2;

    stringstream art(specs);
    paint>>xpos1>>ypos1>>xpos2>>ypos2;

    Line line(xpos1,ypos1,xpos2,ypos2);
    line.draw(canvas,theta);
    }
    else if(type != "circle" && type != "line")
    cout<<"Invaild Input in image.canvas File:"<<endl;

    }
    image.close();

    while(true)
    {
    canvas.Erase();
    canvas.Invalidate();
    circle.draw(canvas,theta);
    line.draw(canvas,theta);
    theta++;
    if (theta == 361)
    theta = 0;

    usleep(40000);
    }
    }
    else
    cout<<"Error Opening File:"<<endl;

    }
    int main()
    {
    Canvas canvas(500,500); // sets canvas to desired size
    canvas.Go("CSCI 135 Project 6",PaintFunction); //opens a canvas
    window

    return 0;
    }
    ###################################################################################

    Thank You ahead of time for you help and time.
    AJ, Dec 15, 2009
    #3
  4. AJ

    Jonathan Lee Guest

    On Dec 15, 3:50 pm, AJ <> wrote:
    > Thank you for informing of the correct groups where i can pose my
    > question.
    > As for a c++ language question I need help solving an error i keep
    > receiving.


    The objects "line" and "circle" only exist until the end of the if
    statements where they are declared. By line 72 and 73 they don't
    exist.

    --Jonathan
    Jonathan Lee, Dec 15, 2009
    #4
  5. AJ

    AJ Guest

    On Dec 15, 3:57 pm, Jonathan Lee <> wrote:
    > On Dec 15, 3:50 pm, AJ <> wrote:
    >
    > > Thank you for informing of the correct groups where i can pose my
    > > question.
    > > As for a c++ language question I need help solving an error i keep
    > > receiving.

    >
    > The objects "line" and "circle" only exist until the end of the if
    > statements where they are declared. By line 72 and 73 they don't
    > exist.
    >
    > --Jonathan


    So how do i fix the problem ?
    AJ, Dec 15, 2009
    #5
  6. AJ

    Jonathan Lee Guest

    On Dec 15, 4:04 pm, AJ <> wrote:
    > On Dec 15, 3:57 pm, Jonathan Lee <> wrote:
    > > The objects "line" and "circle" only exist until the end of the if
    > > statements where they are declared. By line 72 and 73 they don't
    > > exist.

    >
    > > --Jonathan

    >
    > So how do i fix the problem ?


    Move them into scope. At the very least move them to the beginning
    of the "if(image.is_open())" block. Of course, you'll need to make
    some adjustments to the way you set the circle and line parameters.
    You won't be able to do this in the constructor any more.

    --Jonathan
    Jonathan Lee, Dec 15, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mark | r

    rotating an image

    mark | r, Jul 2, 2003, in forum: HTML
    Replies:
    4
    Views:
    4,725
    Mark Parnell
    Jul 2, 2003
  2. bob
    Replies:
    0
    Views:
    428
  3. Dr Ann Huxtable

    Missing Graph.h and (Graph.lib) woes - any help

    Dr Ann Huxtable, Dec 21, 2004, in forum: C Programming
    Replies:
    6
    Views:
    650
    Dr Ann Huxtable
    Dec 21, 2004
  4. Jef Driesen
    Replies:
    3
    Views:
    2,543
    mlimber
    Jan 24, 2006
  5. Emilio Mayorga
    Replies:
    6
    Views:
    329
    Martien Verbruggen
    Oct 8, 2003
Loading...

Share This Page