0

currently struggling with a project for my computing class in c++. Being asked to rotate a point in 3d space by 3 angles relative to the 3 axis.

feel like im kinda close on having all the parts needed just struggling to put them together, lecture notes were a bit vague on multiplying matrices :( . any help is appreciated.

#include "stdafx.h"
#include <iostream>

using namespace std;
int main()
{
std::cout << "Enter a number for x";
int x;
std::cin >> x;
std::cout << "Enter a number for y";
int y;
std::cin >> y;
std::cout << "Enter a number for z";
int z;
std::cin >> z;
std::cout << "Enter value for Theta";
int theta;
std::cin >> theta;
std::cout << "Enter value for Beta";
int beta;
std::cin >> beta;
std::cout << "Enter value for Gamma";
int gamma;
std::cin >> gamma;


//function allows the insertion of xyz and the three angles


{void RTheta(const double& theta, double array[3][3]);

int array =
{
    {cos(theta), sin(theta), 0},                        //the matrice for theta values
    {sin(theta), cos(theta), 0},
    {0,0,1}
};
std::cout << RTheta;                                    //outputs value for theta

}

{
    void RBeta(const double& beta, double array[3][3]);

    int array =
    {
        {cos(beta), 0, -sin(beta)},                         //the matrice for beta values
        {0, 1, 0},                                          //outputs values for beta
        {sin(beta), 0, cos(beta)}
    };
    std::cout << RBeta;
}
{
    void RGamma(const double& gamma, double array[3][3]);

    int array =
    {
        {1,0,0},                                            //the matrice for gamma
        {0,cos(gamma), sin(gamma)},                         //outputs values for gamma
        {0, -sin(gamma), cos(gamma)}
    };
    std::cout << RGamma;
}
return 0;
}

the question if this helps: i.imgur.com/eN5RqEe.png

  • 1
    It looks like you are trying to define functions within functions. C++ doesn't allow that. Define those functions outside `main`. You may find it easier to put them above `main` because you won't need forward declarations. Best suggestion I have for you is [to crack a good book and read up on proper syntax](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – user4581301 Feb 27 '17 at 00:41
  • Looking at your text, it says for Q21 `the next exercise can include myArray.h`. You don't include it. Also, the previous question talks about developing *functions*, not *a class*; a class would make more sense if it had a member `void RTheta(const double& theta, double array[3][3])`, as that signature doesn't have the `(x, y, z)` coordinate. – Ken Y-N Feb 27 '17 at 00:48
  • @user4581301 thanks for the reply, im new to c++ and have been really struggling. just to clarify do you mean moving all the bit about inputting x,y, theta etc above the main function? And also how does the second part look? im struggling to figure out how to tie everything together. – Josh Kellock Feb 27 '17 at 00:54
  • BTW, if you just want to learn how to multiply a matrix by a vector, Wikipedia shows [how `(x' y' z')` is calculated](https://en.wikipedia.org/wiki/Matrix_multiplication#Square_matrix_and_column_vector). – Ken Y-N Feb 27 '17 at 00:59

1 Answers1

1

You need to start thinking from an abstraction point of view and not get lost in the details. You need the abstractions Point and Transform and create functions that work with those abstractions.

If you are working with 2D points, use:

struct Point
{
   double x;
   double y;
};

If you need to work with 3D points, use:

struct Point
{
   double x;
   double y;
   double z;
};

If you are interested only in rotational transforms, you can use the following for 2D transforms:

struct Transform
{
    double matrix[2][2];
};

For 3D transforms, you can use:

struct Transform
{
    double matrix[3][3];
};

and then add functions to construct points, transforms and performs operations on them. E.g.

Point constructPoint(double x, double y);

Transfrom constructIdentityTransform();
Transfrom constructRotateAroundXTransform(double xrot);
Transfrom constructRotateAroundYTransform(double yrot);
Transfrom constructRotateAroundZTransform(double yrot);

Transform operator*(Transform const& lhs, Transform const& rhs);

Point operator*(Transform const& trans, Point const& p);

I hope this gives you enough information to complete the rest.

R Sahu
  • 204,454
  • 14
  • 159
  • 270