# Need Help Rotating An Image Around A Graph

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

1. ### AJGuest

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

2. ### Victor BazarovGuest

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
images efficiently.

V
--

Victor Bazarov, Dec 15, 2009

3. ### AJGuest

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
> images efficiently.
>
> V
> --

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")
{

stringstream art(specs);

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
4. ### Jonathan LeeGuest

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
5. ### AJGuest

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
6. ### Jonathan LeeGuest

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