Specify, design, and implement a class that can be used to keep track of positio
ID: 3549153 • Letter: S
Question
Specify, design, and implement a class that can be used to keep track of position of a point in three-dimensional space. For example consider the point drawn at the topof the next coloumn. The point shown there has three coordinates;
continue question in the picture below
x=2.5,y=0, and z=2.0.Include member functions to set a ppoint to specified
x = 2.5, y = 0, and z = 2.0. Include member functions to set a point to a specified location, to shift a point a given amount along one of the axes, and to retrieve the coordinates of a point. Also provide member functions that will rotate the point by a specified angle around a specified axis. To compute these rotations, you will need a bit of trigonometry. Suppose you have a point with coordinates x, y, and z. After rotating this point (counterclockwise) by an angle theta, the point will have new coordinates, which we'll call x ', y '. and z'. The equations for the new coordinates use the cmath library functions s in and cos, as shown here: After a theta rotation around the x-axis: x' = x y' = y cos ( theta ) - z sin( theta ) z' = y sin( theta ) + z cos( theta ) After a theta rotation around the y-axis: x' = x cos( theta ) + z sin( theta ) y' = y z ' = - x sin( theta ) + z cos( theta ) After a theta rotation around the z-axis: x ' = x cos( theta ) - y sin( theta ) y' = x sin( theta ) + y cos ( theta ) z' = zExplanation / Answer
*********************************************************************************/
#include <iostream.h>
#include <math.h>
#include <conio.h>
#include "TDPoint.h"
//---------------------------------------------------------------------------
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
TDPoint MyPoint(2.5,0,2.0);
cout<<"The original coordinate of my point are:"<<endl;
cout<<endl;
cout<<"x = "<<MyPoint.get_x()<<endl;
cout<<"y = "<<MyPoint.get_y()<<endl;
cout<<"z = "<<MyPoint.get_z()<<endl;
//Rotate 45 degree around the x-axis
MyPoint.rotate_x(45);
cout<<endl;
cout<< "After a 45 degree rotation around the x-axis "<<endl;
cout<< "The new coordinates of the point are: "<<endl;
cout<<endl;
cout<<"x = "<<MyPoint.get_x()<<endl;
cout<<"y = "<<MyPoint.get_y()<<endl;
cout<<"z = "<<MyPoint.get_z()<<endl;
getchar();
return 0;
}
//---------------------------------------------------------------------------
// TDpoint.cpp File
#include <math.h>
#include "TDPoint.h"
TDPoint::TDPoint(double ini_x, double ini_y, double ini_z)
{
x = ini_x;
y = ini_y;
z = ini_z;
}
void TDPoint::shift(double delta_x, double delta_y, double delta_z)
{
x += delta_x;
y += delta_y;
z += delta_z;
}
void TDPoint::rotate_x( double c)
{
double new_x;
double new_y;
double new_z;
double theta; // angle in radians
theta = (c * M_PI)/180;
new_x = x;
new_y = y*cos(theta) - z*sin(theta);
new_z = y*sin(theta) + z*cos(theta);
x = new_x;
y = new_y;
z = new_z;
}
void TDPoint::rotate_y( double c)
{
double new_x;
double new_y;
double new_z;
double theta; // angle in radians
theta = (c * M_PI)/180;
new_x = x*cos(theta) + z*sin(theta);
new_y = y;
new_z = z*cos(theta) - x*sin(theta);
x = new_x;
y = new_y;
z = new_z;
}
void TDPoint::rotate_z( double c)
{
double new_x;
double new_y;
double new_z;
double theta; // angle in radians
theta = (c * M_PI)/180;
new_x = x*cos(theta) - y*sin(theta);
new_y = x*sin(theta) + y*cos(theta);
new_z = z;
x = new_x;
y = new_y;
z = new_z;
}
//***************************************************************************************
//TDpoint.h Header File
#ifndef TDPoint_H
#define TDPoint_H
class TDPoint
{
public:
//CONSTRUCTOR
TDPoint(double ini_x, double ini_y, double ini_z);
//CONSTANT MEMBER FUNCTION
double get_x() const { return x; } // inline implementation
double get_y() const { return y; }
double get_z() const { return z; }
//MODIFICATION MEMBER FUNCTIONS
void shift(double delta_x, double delta_y, double delta_z);
void rotate_x( double c); // c is the angle in celcius degree
void rotate_y( double c);
void rotate_z( double c);
private:
double x; // x coordinate of this point
double y; // y coordinate of this point
double z; // z coordinate of this point
};
#endif
//*********************************************************************************************************
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.