Difference between revisions of "C++:3D Exercises"

From Progzoo
Jump to: navigation, search
Line 1: Line 1:
The normal to the plane has also been shown.
 
 
<question>
 
<question>
 +
Calculate the cross product of two vectors.
 +
Fill in the details in the function '''crossproduct'''
 
<prog><![CDATA[
 
<prog><![CDATA[
 
#include <math.h>
 
#include <math.h>
Line 15: Line 16:
 
float *crossproduct(float a[3], float b[3]){
 
float *crossproduct(float a[3], float b[3]){
 
   float *r = new float[3];
 
   float *r = new float[3];
   r[0] = a[1]*b[2]-a[2]*b[1];
+
   // Your code goes here
  r[1] = a[2]*b[0]-a[0]*b[2];
 
  r[2] = a[0]*b[1]-a[1]*b[0];
 
 
   return r;
 
   return r;
 
}
 
}
Line 23: Line 22:
 
int main(int argc, char **argv)
 
int main(int argc, char **argv)
 
{
 
{
   float *A={1,0,1};
+
   float A[]={1,0,1};
   cout << A[0]<<" "<<A[1]<<" "<<A[2]<< endl;
+
  float B[]={1,1,2};
 +
  float *C = crossproduct(A,B);
 +
   cout << C[0]<<" "<<C[1]<<" "<<C[2]<< endl;
 
   return 0;
 
   return 0;
 
}
 
}
 
]]></prog>
 
]]></prog>
 
</question>
 
</question>

Revision as of 08:21, 23 November 2011

Calculate the cross product of two vectors. Fill in the details in the function crossproduct


[Font] [Default] [Show] [Resize] [History] [Profile]