Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that reads in a pair of 2D vectors and outputs the angle between

ID: 3655446 • Letter: W

Question

Write a program that reads in a pair of 2D vectors and outputs the angle between the vectors in degrees. The main routine of the program is already provided in vector2D_angle_template.cpp (which you copied into vector2D_angle.cpp). DO NOT MODIFY ANY OF THE CODE in procedure main. Your task is to add ve functions normalize(), dot_product(), radians2degrees(),compute_vector_angle(), and output_angle() so that the program produces the desired results. A) Write a function normalize() which normalizes vector(x, y) by dividing by its length. The length of vector (x, y) is (x2 + y2)^(.5). Input to the function are the coordinates x and y. The function does not return any value. The function has two parameters: 1) a number x of type double representing the rst coordinate of the vector;  2)a number y of type double representing the second coordinate of the vector. The function does not return any value. B) Write a function dot_product() which returns the dot product of two vectors. Input to the function are the coordinate (x1, y1) and (x2, y2) of two vectors. Output is the dot product. The function has four parameters: 1) a number x1 of type double representing the first x coordinate;  2)a number y1 of type double representing the first y coordinate;  3)a number x2 of type double representing the second x coordinate;  4)a number y2 of type double representing the second y coordinate; Function dot_product returns a number of type double representing the dot product of (x1, y1) and (x2, y2). C) Write a function compute_vector_angle() which returns the angle in RADIANS between vectors (x1, y1) and (x2, y2). Input to the function are the vector coordinates (x1, y1) and (x2,y2). Output is the angle in radians. The function has four parameters:  1) a number x1 of type double representing the x coordinate of the first vector;  2) a number y1 of type double representing the y coordinate of the first vector;  3) a number x2 of type double representing the x coordinate of the second vector;  4) a number y2 of type double representing the y coordinate of the second vector. Function compute_vector_angle returns a number of type double representing the angle in radians between vectors (x1, y1) and (x2, y2). D) Write a function radians2degrees() which converts radians to degrees. Input to the function is an angle in radians. Output is the angle in degrees. The function has one parameter, a number radians of type double, representing the angle in radians. The function returns a number of type double representing the angle coverted to degrees. E) 19. Write a function output_angle() which outputs "Angle between vectors (x1, y1) and (x2, y2) = angle degrees" where x1, y1, x2, and y2 are the vector coordinates and angle is the angle between the vectors in degrees. For instance, if (x1, y1) = (1, 0) and (x2, y2) = (1.5, 1.5), then the angle is 45 degrees, and output_angle() should print "Angle between vectors (1,0) and (1.5,1.5) = 45 degrees." Use the default output format for x; y and angle. The function has five parameters:  1) a number x1 of type double representing the x coordinate of the first vector;  2) a number y1 of type double representing the y coordinate of the first vector;  3) a number x2 of type double representing the x coordinate of the second vector;  4) a number y2 of type double representing the y coordinate of the second vector.  5) a number angle of type double representing the angle in degrees. The function does not return any value.

Explanation / Answer

" double calcAngle(double fromX, double fromY, double fromAngle, double toX, double toY) { double d = 0.0; double Ux = 0.0, Uy = 0.0, Vx = 0.0, Vy = 0.0; d = sqrt( calcDistanceSquared(fromX, fromY, toX, toY) ); Ux = (toX - fromX) / d; Uy = (toY - fromY) / d; Vx = cos(fromAngle * (cPI / 180.0)); Vy = sin(fromAngle * (cPI / 180.0)); return atan2(((Ux * Vy) - (Uy * Vx)), ((Ux * Vx) + (Uy * Vy))) * 180.0 / cPI; } "Can you understand?

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote