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

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:

уаxis х-аxis Coordinates of this location: z-axis X= 2.5 y= 0 Z= 2.0

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

xis -xis Coordinates of this location: z-axis X= 2.5 y= 0 Z= 2.0

Step by Step Solution

3.48 Rating (155 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Here is an example of a class for a line segment in threedimensional space using ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Data Structures and Other Objects Using Java Questions!