In three-dimensional space, a line segment is defined by its two endpoints. Specify, design, and implement a
Question:
In three-dimensional space, a line segment is defined by its two endpoints. Specify, design, and implement a class for a line segment. The class should have two private instance variables that are 3D locations from the previous project.
Data from Previous Project
Specify, design, and implement a class that can be used to keep track of the position of a location in three-dimensional space. For exampleex, acmonpslieder this location:
The location shown in the picture has three coordinates: x = 2.5, y = 0, and z = 2.0. Include methods to set a location to a specified point, to shift a location a given amount along one of the axes, and to retrieve the coordinates of a location. Also provide methods that will rotate the location by a specified angle around a specified axis.
To compute these rotations, you will need a bit of trigonometry. Suppose you have a location with co-ordinates x, y, and z. After rotating this location by an angle θ, the location will have new coordinates, which we’ll call x', y', and z'. The equations for the new coordinates use the java.lang methods Math.sin and Math.cos, as shown here:
After a θ rotation around the x-axis:
x' = x
y' = y cos (θ) – z sin(θ)
z' = y sin(θ) + z cos(θ)
After a θ rotation around the y-axis:
x' = x cos (θ) + z sin(θ)
y' = y
z' = –x sin(θ) + z cos (θ)
After a θ rotation around the z-axis:
x' = x cos (θ) – y sin(θ)
y' = x sin(θ) + y cos (θ)
z' = z
Step by Step Answer: