Question
This is to be written in C programming. Im quite new to programming, so please keep it simple and do not use arrays and strings.
#include
#include
// Purpose: Computes the dot product of the vectors (x1, y1, z1) and (x2, y2, z2)
// Args: float x1, float y1, float z1, float x2, float y2, float z2
// Returns: float - the dot product
float dot_product( float x1, float y1, float z1, float x2, float y2, float z2 ){
//Your code here
}
/*
* Purpose: Computes the cross product of the vectors (x1, y1, z1) and (x2, y2, z2)
* and stores the result using the pointers result_x, result_y and result_z
* Args: float x1, float y1, float z1, float x2, float y2, float z2,
* float* result_x, float* result_y, float* result_z
*/
void cross_product( float x1, float y1, float z1,
float x2, float y2, float z2,
float* result_x, float* result_y, float* result_z){
//Your code here
}
// Purpose: Computes the norm of the vector (x, y, z)
// Args: float x, float y, float z
// Returns: float - the norm
//You may want to use the sqrt() function from math.h
/otice that it is included above and instructions for use in CLion below.
float norm( float x, float y, float z ){
//Your code here
}
int main(){
float x1, y1, z1;
float x2, y2, z2;
float x3, y3, z3;
x1 = 1;
y1 = 2;
z1 = 3;
x2 = 4;
y2 = 5;
z2 = 6;
float d = dot_product(x1,y1,z1, x2,y2,z2);
cross_product(x1,y1,z1, x2,y2,z2, &x3,&y3,&z3);
float n1 = norm(x1,y1,z1);
float n2 = norm(x2,y2,z2);
printf("v1 = (%f %f %f) ", x1, y1, z1);
printf("v2 = (%f %f %f) ", x2, y2, z2);
printf("v1 (dot) v2 = %f ", d);
printf("v3 = v1 x v2 = (%f %f %f) ", x3, y3, z3);
printf("norm(v1) = %f ", n1);
printf("norm(v2) = %f ", n2);
//Since (x3, y3, z3) is the cross product of v1 and v2, it should be
//orthogonal to both v1 and v2 (so the dot product should be zero).
float d13 = dot_product(x1,y1,z1, x3,y3,z3);
float d23 = dot_product(x2,y2,z2, x3,y3,z3);
printf("v1 (dot) v3 = %f ", d13);
printf("v2 (dot) v3 = %f ", d23);
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started