Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Inner product of the two vectors u = (ux, uy) and v = (vx, vy) is defined as: u*v = (ux, uy) * (vx, vy)

Inner product of the two vectors u = (ux, uy) and v = (vx, vy) is defined as:

u*v = (ux, uy) * (vx, vy) = ux * vx + uy * vy

A. Write a C program to compute the inner product of two vectors using the definition. Function should take as arguments the four vector components and return their inner product. Function prototype should be:

double inner_product (double ux, double uy, double vx, double vy);

------------------------------------------------------------------------------------------------

It can be shown that the cosine angle formed between two vectors u and v is given by the expression:

cos() = u*v / sqrt((u*u) * (v*v))

B. Write C program that will compute the angle for any two given vectors u and v

(i) input the two vectors by readin the 2 cartesian compnent values for each one of the vectors (4 numbers in total)

(ii) use the function in part A to compute the inner dot products involved in the expression above (notice there are 3 inner products in that expression)

(iii) compute the angle using the acos() funct from math.h

(iv) print out the value for angle in degrees (notice the acos() funct reutrns values in radians- multiply result of acos() funct by 180/pi)

---------------------------------------------------------------------------------------------------

C. Use previsouly developed codes as functions and develop new code that will be computing all three angles of a plane triangle and will report any angles that are obtuse by identifying the vertex the obtuse angle responds to

(i) input the coordinates of the 3 triangle vertices as 3 pairs of x and y coordinates

(ii) for each of the triangle's vertices form, you need to form the vectors that correspond to the triangle's sides for example for vertex 1, the two vectors should be:

u = (x2-x2, y2-y1) and v = (x3-x1, y3-x1)

then repeat for other two vertices

(iii) find the angle formed by the two vectors using the codes developed in part A and try to shorten the new code by converting the code of part B into a function: make a function out of the entire part B code; the prototype for this function could look like:

double angle (double ux, double uy, double vx, double vy);

(iv) test the angles for obtuseness and report the results

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions