Need Help Rotating An Image Around A Graph

A

AJ

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;

}
##########################################################################################
 
V

Victor Bazarov

AJ said:
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
 
A

AJ

AJ said:
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

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.
 
J

Jonathan Lee

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
 
A

AJ

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 ?
 
J

Jonathan Lee

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top