// This ensures that this file is included at most once // in any program, as there may be multiple include // statements. #pragma once #include // Class declaration class Vector_3d; /////////////////////////// // Function declarations // /////////////////////////// ////// // These query the arguments, but do not change them ////// // Calculate the inner product of u and v. double inner( Vector_3d const &u, Vector_3d const &v ); // Calculate the norm (length) of u. double norm( Vector_3d const &u ); // Calculate u + v. Vector_3d add( Vector_3d const &u, Vector_3d const &v ); // Calculate a*u for a scalar 'a'. Vector_3d mul( double const a, Vector_3d const &u ); // Calculate u*a for a scalar 'a'. Vector_3d mul( Vector_3d const &u, double const a ); // Calculate -u. Vector_3d negate( Vector_3d const &u ); // Calculate u - v. Vector_3d sub( Vector_3d const &u, Vector_3d const &v ); // Calculate (1/a)*u for a non-zero scalar 'a'. Vector_3d div( Vector_3d const &u, double const a ); // Calculate the projection of u onto v. Vector_3d proj( Vector_3d const &u, Vector_3d const &v ); // Calculate the cross product u x v. Vector_3d cross( Vector_3d const &u, Vector_3d const &v ); // Determine whether u and v are equal. bool equal( Vector_3d const &u, Vector_3d const &v ); // Return a string representation of u. std::string to_string( Vector_3d const &u ); ////// // These modify the first vector passed ////// // Normalize u if it is not the zero vector. void normalize( Vector_3d &u ); // Add v to u. void add_to( Vector_3d &u, Vector_3d const &v ); // Subtract v from u. void sub_from( Vector_3d &u, Vector_3d const &v ); // Multiply u by the scalar a. void mul_by( Vector_3d &u, double const a ); // Divide u by the non-zero scalar a. void div_by( Vector_3d &u, double const a ); //////////////////////// // Vector_3d class // //////////////////////// // Store the three components of a 3-dimensional vector. class Vector_3d { public: double x_; double y_; double z_; };