Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am writting a c++ progarm and I got a most, but when i debug this program it giving me negative orginal points. Can you

I am writting a c++ progarm and I got a most, but when i debug this program it giving me negative orginal points. Can you please take a look.

Specify, design and implement a class that can be used to keep track of the position of a point in three-dimensional space. For example, consider the point drawn here: y-axis | | | | | x-axis .-----------------------------> / / / . ( 2.5, 0 ,2.0) / / / z-axis The point shown above has three coordinates: x = 2.5, y = 0, and z = 2.0. Include member functions to set a point to a specific 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 specied 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 by an angle alpha,the point will have new coordinates,which we'll call x',y', and z'. The equation for the new coordinates use the math.h library functions sin and cos, as shown here: After an alpha rotation around the x-axis: x' = x y' = y cos(alpha) - z sin(alpha) z' = y sin(alpha) + z cos(alpha) After an alpha rotation around the y-axis : x' = x cos(alpha) + z sin(alpha) y' = y z' = -x sin(alpha) + z cos(alpha) After an alpha rotation around the z-axis: x' = x cos(alpha) - y sin(alpha) y' = x sin(alpha) + y cos(alpha) z' = z Note: alpha is in radians use this formula to convert degrees to radians R = ( C * PI) / 180 where R : radians C : degrees PI : constant pi = 3.1415926.

-------------------------------------------------------------------------

#include #include #include using namespace std;

const double M_PI = 3.14159; class TDpoint { public:

double new_x, new_y, new_z, thata;

//delacring the constructor funnctions TDpoint(double x, double y, double z);

//delcaring the variables for the member functions double Input_x() const { return x; } double InPut_y() const { return y; } double Input_z() const { return z; }

void shiftPoint(double delta_x, double delta_y, double delta_z); void rotate_x(double angle); void rotate_y(double angle); void rotate_z(double angle);

private: double x, y, z; };

TDpoint::TDpoint(double x, double y, double z) { x = x; y = y; z = z; } void TDpoint::shiftPoint(double delta_x, double delta_y, double delta_z) { x = x + delta_x; y = y + delta_y; z = z + delta_z; } void TDpoint::rotate_x(double angle) { thata = (angle*M_PI) / 180; new_x = x; new_y = y*cos(thata) - z*sin(thata); new_z = y*sin(thata) + z*cos(thata); x = new_x; y = new_y; z = new_z; } void TDpoint::rotate_y(double angle) { thata = (angle*M_PI) / 180; new_x = x*cos(thata) + z*sin(thata); new_y = y; new_z = y*sin(thata) - z*cos(thata); x = new_x; y = new_y; z = new_z; } void TDpoint::rotate_z(double angle) { thata = (angle*M_PI) / 180; new_x = x*cos(thata) + z*sin(thata); new_y = y*cos(thata) - z*sin(thata); new_z =z; x = new_x; y = new_y; z = new_z; }

int main() { double x, y, z, degree; cout << "Please enter the three points." << endl; cout << "x = "; cin >> x; cout << "y = "; cin >> y; cout << "z="; cin >> z;

TDpoint Points(x, y, z);

cout << "Original corrdinate poitns are: "; cout <<"x =" <> degree; Points.rotate_x(degree); cout << endl; cout << "After a " << degree << " degree rataion around the a-axis" << endl; cout << "New coordinate points are: "; cout << "x =" << Points.Input_x() << endl; cout << "y= " << Points.InPut_y() << endl; cout << "z = " << Points.Input_z() << endl;

system("pause"); return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 11g SQL

Authors: Jason Price

1st Edition

0071498508, 978-0071498500

More Books

Students also viewed these Databases questions