阅读背景:

三维向量的标准化,两点距离,点乘,叉乘_jiuweihuaxiang的专栏

来源:互联网 
#include <iostream>
using namespace std;
struct vector
{  
	float x;
	float y;
	float z;

};
 vector c;
 float Get_Length(vector &a)
 {
	 return a.x*a.x+a.y*a.y+a.z*a.z;
 }
 float Distance(vector &a,vector &b)
 {
	 vector c;
	 c.x = a.x -b.x;
	 c.y = a.y -b.y;
	 c.z = a.z -b.z;
	 float distance=sqrt(Get_Length(c));
	return distance;
 }
 float Dot_Porduct(vector &a,vector &b)
 {
	 return a.x*b.x+a.y*b.y+a.z*b.z;
 }

 vector Cross_Product(vector &a,vector &b)
 { 
	 vector c;
	 c.x=a.y*b.z-a.z-b.y;
	 c.y=a.z*b.x-a.x*b.z;
	 c.z=a.x*b.y-a.y*b.x;
	 return c;
 }
  vector Normal(vector &a)
  {
	  float length=sqrt(Get_Length(a));
	  vector normal;
	  normal.x=a.x/length;
	  normal.y=a.y/length;
	  normal.z=a.z/length;
	  return normal;
}
  void main()
  {
	  vector a;
	  vector b;
	  vector normal;
	  cout<<"Enter 3 numbers :"<<endl;
	  cin>>a.x>>a.y>>a.z;
	  cout<<"Enter 3 numbers :"<<endl;
	  cin>>b.x>>b.y>>b.z;	  
	  cout<<"a=("<<a.x<<","<<a.y<<","<<a.z<<")"<<endl;
	  cout<<"b=("<<b.x<<","<<b.y<<","<<b.z<<")"<<endl;
		 normal= Normal(a);
	  cout<<"The normal of a is ("<<normal.x<<","<<normal.y<<","<<normal.z<<")"<<endl;
	     float dis= Distance(a,b);
	  cout<<"The distance a and b is "<<dis<<endl;
	    float dot = Dot_Porduct(a,b);
	 cout<<"The dot_product of a and b is "<<dot<<endl;
	    vector c = Cross_Product(a,b);
     cout<<"The corss_product of a and b is ("<<c.x<<","<<c.y<<","<<c.z<<")"<<endl;
  }#include <iostream>
using namespace std;
struct



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: