Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members Related Pages Search
fungvector.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <cmath>
00019
00020 #include "fungvector.h"
00021 #include "sphericalcoord.h"
00022 #include "cylindricalcoord.h"
00023 #include "cartesian3dcoord.h"
00024
00025
00026 FungVector::FungVector(float x, float y, float z)
00027 {
00028 this->x = x;
00029 this->y = y;
00030 this->z = z;
00031 }
00032
00033 FungVector::FungVector(SphericalCoord &s)
00034 {
00035 Cartesian3DCoord c = s.toCartesianCoord();
00036
00037 this->x = c.x();
00038 this->y = c.y();
00039 this->z = c.z();
00040 }
00041
00042 FungVector::FungVector(CylindricalCoord &s)
00043 {
00044 Cartesian3DCoord c = s.toCartesianCoord();
00045
00046 this->x = c.x();
00047 this->y = c.y();
00048 this->z = c.z();
00049 }
00050
00051
00052 FungVector::~FungVector()
00053 {
00054
00055 }
00056
00057 void FungVector::toArray(float vec[3])
00058 {
00059 vec[0] = x;
00060 vec[1] = y;
00061 vec[2] = z;
00062 }
00063
00064 FungVector FungVector::normal(FungVector p1, FungVector p2, FungVector p3)
00065 {
00066 FungVector ret(0,0,0);
00067 cross_product(p1,p2,p3,&ret);
00068 normalize(&ret);
00069 return ret;
00070 }
00071
00072 void FungVector::cross_product(FungVector &u, FungVector &v, FungVector &w, FungVector *result)
00073 {
00074 float v1[3];
00075 float v2[3];
00076
00077 v1[0] = u.x - v.x;
00078 v1[1] = u.y - v.y;
00079 v1[2] = u.z - v.z;
00080
00081 v2[0] = v.x - w.x;
00082 v2[1] = v.y - w.y;
00083 v2[2] = v.z - w.z;
00084
00085 result->x = v1[1]*v2[2] - v1[2]*v2[2];
00086 result->y = v1[2]*v2[0] - v1[0]*v2[2];
00087 result->z = v1[0]*v2[1] - v1[1]*v2[0];
00088 }
00089
00090 float FungVector::magnitude(FungVector &v)
00091 {
00092 return sqrt(v.x*v.x+v.y*v.y+v.z*v.z);
00093 }
00094
00095 void FungVector::normalize(FungVector *v)
00096 {
00097 float length = magnitude(*v);
00098 v->x /= length;
00099 v->y /= length;
00100 v->z /= length;
00101 }
00102
|