Closest Points

Learning Objectives

Extend your vector3D class to perform cross products and compute closest points.


In the previous two experiments, you created a vector class to represent 3D vectors using 4D homogeneous coordinates and provided the class with many different methods for the different vector operations. In this experiment, we will extend the class by adding the following operations:

  • parallel projection
  • perpendicular projection
  • cross product of two vectors
  • closest point on a 3D line from another point in space
  • closest point on a plane from another point in space

The closest point algorithms are ternary operations since three vectors appear in their formulas. Therefore, the implementation of these algorithms will require the use of functions as opposed to overloading operators. You should have two different functions of the form v1.function( vector v2, vector v3 ). You may want to call one closestpointLine and one closestpointPlane for example. The vectors involved are not interchangeable, and therefore comments in your class header file will be needed to instruct the user in the appropriate use of the function.

Closely related to the question of the closest point is the distance of an object from that point. No additional class method is needed, however, since the distance is simply the magnitude of the vector between two points, and you should already have a vector magnitude method in your class.

Prelab Questions and Exercises

1. In some rectangular coordinate system, the location of Tom Swift’s ship is given by (282, 791, 456) km. A meteoroid is sighted at position (151, 366, 965) km, and is traveling along the direction (12, 31, –46) km. Determine the location of the meteoroid at its closest approach to Tom’s ship. How close will the meteoroid come to the ship?

2. A nearby lunar surface is a large plane (which we will unrealistically assume is an infinite plane). Three points on the moon are located at (377, 912, 598) km, (385, 920, 593) km, and (388, 914, 604) km. Determine an equation of this plane, and find the closest point on the plane to Tom’s ship. How close is the moon from the ship?

3. To write a method for a closest point algorithm, one of the three vectors must be singled out as the object, and the other two are the inputs to the method. Which of the three vectors will you choose as your object? Why? (Your choice will probably be related to either ease of code or ease of understanding, but it is up to you to describe why you think your choice is good.)

Laboratory Procedures

1. Extend your 3D vector class to include the three new operations listed in the introduction.

2. Create a program that reports on the closest points of different objects from a ship in space. Specifically, the program should do the following steps:
• asks the user to enter the components of a ship in space
• asks the user to enter the parameters of a moving object (3D line: point and direction)
• reports the closest point the object will have to the ship
• reports the closest distance between the object and the ship
• asks the user to enter three points on a surface (plane: normal and constant)
• reports the closest point on the surface to the ship
• reports the closest distance between the surface and the ship

3. Test your code with the scenarios described in the prelab questions.

4. Execute the above program, for your instructor’s verification.

5. Save your class files! We will use them again in future labs.

Postlab Questions

1. We assumed the moon was an infinite plane. More realistically, the moon would have finite dimensions. What modifications would be needed to the closest point algorithm to find the closest point to a finite subset of an infinite plane? (You may discuss this in generalities.)

2. If the moon was a perfect sphere, then the closest point on the sphere to another point in space is a fairly simple problem. Draw a picture of this situation, including the vector from the point in space to the closest point on the sphere. Label the important points on your picture, and determine a formula for the magnitude of the vector.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License