The position of a point

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.
The position of a point
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 θ\thetaθ, the point will have new coordinates, which we’ll call xx'x′, yy'y′, and zz'z′. The equations for the new coordinates use the cmath library functions sin and cos, as shown here:
After a θ\thetaθ rotation around the x-axis:x=xx' = xx′=xy=ycos(θ)zsin(θ)y'=y\cos(\theta)-z\sin(\theta)y′=ycos(θ)−zsin(θ)z=ysin(θ)+zcos(θ)z'=y\sin(\theta)+z\cos(\theta)z′=ysin(θ)+zcos(θ)
After a θ\thetaθ rotation around the y-axis:x=xcos(θ)+zsin(θ)x'=x\cos(\theta)+z\sin(\theta)x′=xcos(θ)+zsin(θ)y=yy'=yy′=yz=xsin(θ)+zcos(θ)z'=-x\sin(\theta)+z\cos(\theta)z′=−xsin(θ)+zcos(θ)
After a θ\thetaθ rotation around the z-axis:x=xcos(θ)ysin(θ)x'=x\cos(\theta)-y\sin(\theta)x′=xcos(θ)−ysin(θ)y=xsin(θ)+ycos(θ)y'=x\sin(\theta)+y\cos(\theta)y′=xsin(θ)+ycos(θ)z=zz'=zz′=z

My answer:

to be continued…

reference:

整理自《Data Structures and Other Objects Using C++ ( Fourth Edition )》Michael Main, Walter Savitch. p120

上一篇:2008 年研究生入学考试数学一填空题第 2 题解析


下一篇:[codeforces923D]Picking Strings