#include "stdafx.h" #include "Matrix3.h" #include #include Vector3::Vector3(float theta, float phi) { set_unit(theta,phi); } void Vector3::set_unit(float theta, float phi) { float cos_th=(float)cos(theta); value[0]=cos_th*(float)cos(phi); value[1]=cos_th*(float)sin(phi); value[2]=(float)sin(theta); } bool Vector3::operator==(const Vector3& a) const { return value[0]==a.value[0] && value[1]==a.value[1] && value[2]==a.value[2]; } void Vector3::cross(const Vector3& a, const Vector3& b) { value[0]=a.value[1]*b.value[2]-a.value[2]*b.value[1]; value[1]=a.value[2]*b.value[0]-a.value[0]*b.value[2]; value[2]=a.value[0]*b.value[1]-a.value[1]*b.value[0]; } float Vector3::stp(const Vector3&a, const Vector3& b) const { Vector3 ab; ab.cross(a,b); return (*this)*ab; } #if 0 float Vector3::operator*(const Vector3& a) const { return value[0]*a.value[0]+value[1]*a.value[1]+value[2]*a.value[2]; } #endif float Vector3::operator*(const float a[3]) const { return value[0]*a[0]+value[1]*a[1]+value[2]*a[2]; } void Vector3::operator-=(const Vector3& a) { value[0]-=a.value[0]; value[1]-=a.value[1]; value[2]-=a.value[2]; } void Vector3::operator+=(const Vector3& a) { value[0]+=a.value[0]; value[1]+=a.value[1]; value[2]+=a.value[2]; } void Vector3::orthog(const Vector3& a) { float dot; Vector3 at; while (dot=a*(*this),fabs(dot)>FLT_EPSILON*2) { at=a; at*=dot; operator-=(at); normalize(); } }