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

We wish to write a set of C functions to work with 3-D vectors, Write C function

ID: 3590342 • Letter: W

Question

We wish to write a set of C functions to work with 3-D vectors, Write C functions as follows: . VectorMagnitude -Input. An array that represents a 3-D vector p·Na vrVJ -Output: The magnitude of the input vector Ipl = /+1 ? DotProduct Input: Two arrays of three elements each, that represent vectors and Output 1: The dot product of these two vectors p. V, * V, +1. Output2: The angle between the two vectors (in degrees) cos must call the function VectorMagnitude twice. 2 +1, * 14 "(R ) ( Note that this calculation . CrossProduct -Input: Two arrays of three elements each, that represent vectors , and -Output: A 3-element array that represents the cross product of the two input vectors. The cross product is described below - Output2: The angle between the two input vectors (in degrees). The method for calculating the angle between the two input vectors, using the cross product is described below The cross product of two vectors is defined as the formal determinant of the following matrix Va The cross product can be used to find the gle between two vectors 180 where G = pi G. Note that this calculation requires three calls to Vectorlagnitude. Also note that the value inside the parenthesis of the sin-| function might need limiting between HINT: Your functions will have to pass arrays back and forth. A pointer argument may also be essary for the angle between the two vectors. Write a C program that prompts the user to choose between the following options ·M for vector magnitude. This option prompts the user to enter in a single 3-D vector D for dot product. This option prompts the user to euter in two 3-D vectors. C for cross product. This option prompts the user to enter in two 3-D vectors. Print the output of the appropriate calculations to the screen.

Explanation / Answer

Following is the program :

#include<stdio.h>
#include<string.h>
#include<math.h>

float vectormagnitude(float* );
float dotproduct(float* , float* );
float dotangle(float* ,float* );
float* crossproduct(float* ,float* );
float crossangle(float*,float*,float*);
float rescp[3];
int main()
{

   int choice;
   float vector[3],vector2[3]; float res,angle;
   int i=1;
   do
   {
   printf("enter your choce 1.M 2.D 3.C ");
   scanf("%d",&choice);
  
   switch(choice)
   {
       case 1:
       printf("enter the vector for magnitude calculation ");
       scanf("%f%f%f",&vector[0],&vector[1],&vector[2]);
       res=vectormagnitude(vector);
       printf("magnitude of this vector is =%f",res);
       break;
      
       case 2:
       printf("enter the two vectors for dot product ");
       printf("first vector ");
       scanf("%f%f%f",&vector[0],&vector[1],&vector[2]);
       printf("second vector ");
       scanf("%f%f%f",&vector2[0],&vector2[1],&vector2[2]);
       res=dotproduct(vector,vector2);
       printf("dot product for these vectors are=%f ",res);
       angle=dotangle(vector,vector2);
       printf("angle b/w these two vectors=%f",angle);
       break;
      
       case 3:
       printf("enter the two vectors for cross product ");
       printf("first vector ");
       scanf("%f%f%f",&vector[0],&vector[1],&vector[2]);
       printf("second vector ");
       scanf("%f%f%f",&vector2[0],&vector2[1],&vector2[2]);
       float *resu=crossproduct(vector,vector2);
       printf("cross product for these vectors is=%f i % f j %f k ",resu[0],resu[1],resu[2]);
       angle=crossangle(vector,vector2,resu);
       printf("angle b/w these two vectors=%f",angle);
       break;
      
       default:printf("enter a correct value ");
      
   }
   printf(" do you want to continue? please press 0/1 ?? ");
   scanf("%d",&i);
} while(i);
   return 0;
}


float vectormagnitude(float* v)
{
   float res=0;
   res=sqrt(pow(v[0],2)+pow(v[1],2)+pow(v[2],2));
   return res;
}

float dotproduct(float *v1, float *v2)
{
   float res=0;
   res=v1[0]*v2[0]+v1[1]*v2[1]+v1[2]*v2[2];
   return res;
}

float dotangle(float *v1,float *v2)
{
   float res=0;
   res=(dotproduct(v1,v2)/(vectormagnitude(v1)+vectormagnitude(v2)));
  
   float resu=acos(res);
   return resu*(180.0/3.14152);
  
}

float* crossproduct(float *v1,float *v2)
{
  
  
   rescp[0]=(v1[1]*v2[2]-v1[2]*v2[1]);
   rescp[1]=(v1[2]*v2[0]-v1[0]*v2[2]);
   rescp[2]=(v1[0]*v2[1]-v1[1]*v2[0]);
   return rescp;
  
}

float crossangle(float *v1,float* v2,float *res)
{
   float res0=(vectormagnitude(res)/(vectormagnitude(v1)+vectormagnitude(v2)));
   float res1=res0;
   float ans=asin(res1);
   return ans*(180.0/3.14152);
}

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