三维向量的标准化,两点距离,点乘,叉乘
2013-09-18 16:46
288 查看
#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; }
相关文章推荐
- 向量的点乘和叉乘
- 求三维空间中距离最近的两点
- 向量的点乘与叉乘
- Unity计算两点之间的距离或者向量的长度常用方法
- 向量的点乘与叉乘的几何意义
- 向量的点乘与叉乘
- 向量的叉乘即3D中任意两个三维向量的叉乘(向量积)推导及代码实现
- 向量的点乘与叉乘(转载)
- 四元数和向量相乘,向量间的点乘和叉乘
- 三维场景计算任意两点的空间距离
- Unity 点乘(Dot)、叉乘(Cross)判断移动方向、朝向等向量问题
- 三维向量叉乘推导
- 向量的点乘和叉乘
- 【Unity】向量点乘与叉乘
- 四元数和向量相乘,向量间的点乘和叉乘
- 3D三维向量的单位化、正规化、标准化推导及代码实现
- 向量的点乘与叉乘
- 向量的点乘与叉乘的意义(用法)
- 向量的点乘与叉乘
- 向量的点乘和叉乘(dot product & cross product)