Hello :)
So my assignment had me create a class for a 3 dimensional point system and initialize it to zero.
It then has me add 2 to each point, then rotate it on the x axis by 90 degrees, then the y axis by 180 degrees, and then z axis by 45 degrees.
I am not entirely sure if my outputs are correct because he didn't give us any sample outputs, but my answers seem off. For the point (1,1,1), which gets shifted to (3,3,3,) I get: (0,-4.24264,-3). For (0,0,0), which gets shifted to (2,2,2), I get -2.22045e-16,-2.82843,-2). It seems the problem is with the X and maybe Y coordinate.
Ill just link the member functions since those are what I think I'm having a problem with
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
void point::shift_x(double amount)
{
x = x+amount;
}
void point::shift_y(double amount)
{
y=y+amount;
}
void point::shift_z(double amount)
{
z=z+amount;
}
void point::rotate_x(double a)
{
double tempy;
double tempz;
tempy = y;
tempz = z;
double pithree;
pithree = atan(1.0) * 4.0;
a=a*(pithree/180);
y= (tempy*cos(a))-(tempz*sin(a));
z= (tempy*sin(a))+(tempz*cos(a));
}
void point::rotate_y(double a)
{
double tempx;
double tempz;
tempx = x;
tempz = z;
double pione;
pione = atan(1.0)*4.0;
a = a*(pione/180);
x = (tempx*cos(a))+(tempz*sin(a));
z= (tempz*cos(a))-(tempx*sin(a));
}
void point::rotate_z(double a)
{
double tempx;
double tempy;
tempx = x;
tempy = y;
double pitwo;
pitwo = atan(1.0)*4.0;
a = a*(pitwo/180);
x = (tempx*cos(a))- (y*sin(a));
y = (tempx*sin(a))+(tempy*cos(a));
}
|
The double a is just the degree we rotate by, and the double amount is 2.0. If anyone could look over this and see any problems with the equations you'd really be helping me out. He gave us those rotation formulas.