Question:
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 at the picture below. The point shown there has three coordinates: 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 (counter-clockwise) by an angle θ, 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 sin and cos, as shown here:
After a θ rotation around the x-axis:x′=xy′=ycos(θ)−zsin(θ)z′=ysin(θ)+zcos(θ)
After a θ rotation around the y-axis:x′=xcos(θ)+zsin(θ)y′=yz′=−xsin(θ)+zcos(θ)
After a θ rotation around the z-axis:x′=xcos(θ)−ysin(θ)y′=xsin(θ)+ycos(θ)z′=z
My answer:
to be continued…
reference:
整理自《Data Structures and Other Objects Using C++ ( Fourth Edition )》Michael Main, Walter Savitch. p120