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

From Progzoo
Jump to: navigation, search
Line 1: Line 1:
 +
==Dot Product==
 
<question>
 
<question>
 
Calculate the dot product of two vectors.
 
Calculate the dot product of two vectors.
Line 19: Line 20:
 
   float A[]={1,0,1};
 
   float A[]={1,0,1};
 
   float B[]={1,1,2};
 
   float B[]={1,1,2};
   float d = dorproduct(A,B);
+
   float d = dotproduct(A,B);
 
   cout << d<< endl;
 
   cout << d<< endl;
 
   return 0;
 
   return 0;
Line 30: Line 31:
 
using namespace std;
 
using namespace std;
  
float dorproduct(float a[3], float b[3]){
+
float dotproduct(float a[3], float b[3]){
 
   float r = a[0]*b[0]+a[1]*b[1]+a[2]*b[2];
 
   float r = a[0]*b[0]+a[1]*b[1]+a[2]*b[2];
 
   return r;
 
   return r;
Line 39: Line 40:
 
   float A[]={1,0,1};
 
   float A[]={1,0,1};
 
   float B[]={1,1,2};
 
   float B[]={1,1,2};
   float d = dorproduct(A,B);
+
   float d = dotproduct(A,B);
 
   cout << d<< endl;
 
   cout << d<< endl;
 
   return 0;
 
   return 0;
Line 45: Line 46:
 
]]></answer>
 
]]></answer>
 
</question>
 
</question>
 
+
==Cross Product==
 
<question>
 
<question>
 
Calculate the cross product of two vectors.
 
Calculate the cross product of two vectors.

Revision as of 08:32, 23 November 2011

Dot Product

Calculate the dot product of two vectors. Fill in the details in the function dotproduct

Wikipedia includes a good article on dot products. http://en.wikipedia.org/wiki/Dot_product#Definition



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

Cross Product

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

Wikipedia includes a good article on cross products. http://en.wikipedia.org/wiki/Cross_product#Coordinate_notation



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