FineKernelToolKit
2.8.10
|
00001 /**************************************************************************** 00002 * 00003 * Copyright (c) 1999-2011, Fine Kernel Project, All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, 00006 * with or without modification, are permitted provided that the 00007 * following conditions are met: 00008 * 00009 * - Redistributions of source code must retain the above 00010 * copyright notice, this list of conditions and the 00011 * following disclaimer. 00012 * 00013 * - Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the 00015 * following disclaimer in the documentation and/or 00016 * other materials provided with the distribution. 00017 * 00018 * - Neither the name of the copyright holders nor the names 00019 * of its contributors may be used to endorse or promote 00020 * products derived from this software without specific 00021 * prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00029 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00031 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 00032 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00033 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 ****************************************************************************/ 00037 /**************************************************************************** 00038 * 00039 * Copyright (c) 1999-2011, Fine Kernel Project, All rights reserved. 00040 * 00041 * 本ソフトウェアおよびソースコードのライセンスは、基本的に 00042 * 「修正 BSD ライセンス」に従います。以下にその詳細を記します。 00043 * 00044 * ソースコード形式かバイナリ形式か、変更するかしないかを問わず、 00045 * 以下の条件を満たす場合に限り、再頒布および使用が許可されます。 00046 * 00047 * - ソースコードを再頒布する場合、上記の著作権表示、本条件一覧、 00048 * および下記免責条項を含めること。 00049 * 00050 * - バイナリ形式で再頒布する場合、頒布物に付属のドキュメント等の 00051 * 資料に、上記の著作権表示、本条件一覧、および下記免責条項を 00052 * 含めること。 00053 * 00054 * - 書面による特別の許可なしに、本ソフトウェアから派生した製品の 00055 * 宣伝または販売促進に、本ソフトウェアの著作権者の名前または 00056 * コントリビューターの名前を使用してはならない。 00057 * 00058 * 本ソフトウェアは、著作権者およびコントリビューターによって「現 00059 * 状のまま」提供されており、明示黙示を問わず、商業的な使用可能性、 00060 * および特定の目的に対する適合性に関す暗黙の保証も含め、またそれ 00061 * に限定されない、いかなる保証もないものとします。著作権者もコン 00062 * トリビューターも、事由のいかんを問わず、損害発生の原因いかんを 00063 * 問わず、かつ責任の根拠が契約であるか厳格責任であるか(過失その 00064 * 他の)不法行為であるかを問わず、仮にそのような損害が発生する可 00065 * 能性を知らされていたとしても、本ソフトウェアの使用によって発生 00066 * した(代替品または代用サービスの調達、使用の喪失、データの喪失、 00067 * 利益の喪失、業務の中断も含め、またそれに限定されない)直接損害、 00068 * 間接損害、偶発的な損害、特別損害、懲罰的損害、または結果損害に 00069 * ついて、一切責任を負わないものとします。 00070 * 00071 ****************************************************************************/ 00072 #ifndef __FK_VECTOR_HEADER__ 00073 #define __FK_VECTOR_HEADER__ 00074 00075 #include <FK/Base.h> 00076 #include <string> 00077 #include <vector> 00078 00079 const double FK_VECTOREPS = 1.0e-12; 00080 00082 enum fk_Axis { 00083 fk_X, 00084 fk_Y, 00085 fk_Z 00086 }; 00087 00088 class fk_OrthoMatrix; 00089 class fk_Matrix; 00090 class fk_FVector; 00091 00093 00110 class fk_Vector { 00111 00112 public: 00113 double x; 00114 double y; 00115 double z; 00116 00118 00123 fk_Vector(double x = 0.0, double y = 0.0, double z = 0.0); 00124 00126 fk_Vector(const fk_Vector &); 00127 00129 fk_Vector(const fk_FVector &); 00130 00132 virtual ~fk_Vector() {} 00133 00135 //@( 00136 00138 00145 fk_Vector & operator -(void) const; 00146 00147 //@) 00148 00150 //@( 00151 00153 00166 bool operator ==(const fk_Vector &) const; 00167 00169 00182 bool operator !=(const fk_Vector &) const; 00183 00185 00196 bool operator >(const fk_Vector &) const; 00197 00199 00210 bool operator <(const fk_Vector &) const; 00211 00213 00216 bool operator >=(const fk_Vector &) const; 00217 00219 00222 bool operator <=(const fk_Vector &) const; 00223 00224 //@) 00225 00227 //@( 00228 00230 fk_Vector & operator =(const fk_Vector &); 00231 00233 fk_Vector & operator =(const fk_FVector &); 00234 00236 00250 fk_Vector & operator *=(double); 00251 00253 00269 fk_Vector & operator /=(double); 00270 00272 00286 fk_Vector & operator +=(const fk_Vector &); 00287 00289 00303 fk_Vector & operator -=(const fk_Vector &); 00304 00306 00323 fk_Vector & operator *=(const fk_Matrix &); 00324 00326 00343 fk_Vector & operator *=(const fk_OrthoMatrix &); 00344 //@) 00345 00347 //@( 00348 00350 00356 virtual void set(double x, double y, double z = 0.0); 00357 00359 00368 double dist(void) const; 00369 00371 00381 double dist2(void) const; 00382 00384 00397 bool normalize(void); 00398 00400 00403 virtual void init(void); 00404 00406 00409 bool isZero(void) const; 00410 00412 00427 fk_Vector proj(const fk_Vector &Q) const; 00428 00430 00438 fk_Vector perp(const fk_Vector &Q) const; 00439 00440 #ifndef FK_DOXYGEN_USER_PROCESS 00441 00442 virtual void Print(void) const; 00443 virtual void Print(std::string) const; 00444 00445 #endif 00446 00448 //@( 00449 friend double operator *(const fk_Vector &, const fk_Vector &); 00450 friend fk_Vector operator +(const fk_Vector &, const fk_Vector &); 00451 friend fk_Vector operator -(const fk_Vector &, const fk_Vector &); 00452 friend fk_Vector operator *(const fk_Vector &, double); 00453 friend fk_Vector operator *(double, const fk_Vector &); 00454 friend fk_Vector operator /(const fk_Vector &, double); 00455 friend fk_Vector operator ^(const fk_Vector &, const fk_Vector &); 00456 //@) 00457 }; 00458 00459 00461 00478 double operator *(const fk_Vector &, const fk_Vector &); 00479 00481 00491 fk_Vector operator +(const fk_Vector &, const fk_Vector &); 00492 00494 00504 fk_Vector operator -(const fk_Vector &, const fk_Vector &); 00505 00507 00517 fk_Vector operator *(const fk_Vector &, double); 00518 00520 00530 fk_Vector operator *(double, const fk_Vector &); 00531 00533 00541 fk_Vector operator /(const fk_Vector &, double); 00542 00544 00573 fk_Vector operator ^(const fk_Vector &, const fk_Vector &); 00574 00576 00586 class fk_HVector: public fk_Vector { 00587 public: 00588 double w; 00589 00591 fk_HVector(void); 00592 00594 00598 fk_HVector(const fk_Vector &v, double w = 1.0); 00599 00601 virtual ~fk_HVector() {} 00602 00604 fk_HVector(const fk_HVector &); 00605 00607 //@( 00608 00610 00624 bool operator ==(const fk_HVector &) const; 00625 00627 00641 bool operator !=(const fk_HVector &) const; 00642 //@) 00643 00645 //@( 00646 00648 fk_HVector & operator =(const fk_HVector &); 00649 00651 00654 fk_HVector & operator =(const fk_Vector &); 00655 00657 00672 fk_HVector & operator *=(const fk_Matrix &); 00673 00675 00690 fk_HVector & operator *=(const fk_OrthoMatrix &); 00691 00692 //@) 00693 00695 //@( 00696 00698 00705 void set(const fk_Vector &v); 00706 00708 00715 void set(const fk_Vector &v, double w); 00716 00718 00726 void set(double x, double y, double z = 0.0); 00727 00729 00736 void set(double x, double y, double z, double w); 00737 00739 00744 void setw(double w); 00745 00747 00751 fk_Vector getV(void) const; 00752 00754 00758 double getw(void) const; 00759 00761 00765 void ispos(void); 00766 00768 00772 void isvec(void); 00773 00775 00778 void init(void); 00779 00780 #ifndef FK_DOXYGEN_USER_PROCESS 00781 00782 void Print(void) const; 00783 void Print(std::string) const; 00784 00785 #endif 00786 00788 //@( 00789 friend double operator *(const fk_HVector &, const fk_HVector &); 00790 friend fk_HVector operator *(const fk_Matrix &, const fk_HVector &); 00791 friend fk_HVector operator *(const fk_OrthoMatrix &, const fk_HVector &); 00792 //@) 00793 }; 00794 00795 00797 00809 double operator *(const fk_HVector &, const fk_HVector &); 00810 00812 00824 fk_HVector operator *(const fk_Matrix &, const fk_HVector &); 00825 00827 00839 fk_HVector operator *(const fk_OrthoMatrix &, const fk_HVector &); 00840 00841 00843 00857 class fk_FVector { 00858 public: 00859 float x; 00860 float y; 00861 float z; 00862 00864 fk_FVector(void); 00865 00867 fk_FVector(const fk_FVector &); 00868 00870 00874 fk_FVector(const fk_Vector &); 00875 00877 00881 fk_FVector & operator =(const fk_Vector &); 00882 }; 00883 00884 #endif /* !__FK_VECTOR_HEADER__ */