1 /* 2 * frame.cc -- ePiX orthonormal basis 3 * 4 * This file is part of ePiX, a C++ library for creating high-quality 5 * figures in LaTeX 6 * 7 * Version 1.0.23 8 * Last Change: January 10, 2007 9 */ 10 11 /* 12 * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 13 * Andrew D. Hwang <rot 13 nujnat at zngupf dot ubylpebff dot rqh> 14 * Department of Mathematics and Computer Science 15 * College of the Holy Cross 16 * Worcester, MA, 01610-2395, USA 17 */ 18 19 /* 20 * ePiX is free software; you can redistribute it and/or modify it 21 * under the terms of the GNU General Public License as published by 22 * the Free Software Foundation; either version 2 of the License, or 23 * (at your option) any later version. 24 * 25 * ePiX is distributed in the hope that it will be useful, but WITHOUT 26 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 27 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 28 * License for more details. 29 * 30 * You should have received a copy of the GNU General Public License 31 * along with ePiX; if not, write to the Free Software Foundation, Inc., 32 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 33 */ 34 #include "constants.h" 35 #include "functions.h" 36 37 #include "errors.h" 38 #include "triples.h" 39 #include "frame.h" 40 41 namespace ePiX { 42 43 // standard basis frame()44 frame::frame() 45 : m_e1(E_1), m_e2(E_2), m_e3(E_3) { } 46 47 // frame constructor, suitable for (sea,sky,eye) frames: Usually we 48 // know the eye vector and want to preserve its direction. The frame 49 // is guaranteed to be right-handed, and the first arg is immaterial. frame(P arg1,P arg2,P arg3)50 frame::frame(P arg1, P arg2, P arg3) 51 { 52 if (norm(arg2*arg3) < EPIX_EPSILON) // too nearly linearly dependent 53 epix_error("Linearly dependent arguments to frame"); 54 55 // partial Gram-Schmidt 56 arg3 *= 1/norm(arg3); // normalize eye 57 58 arg2 %= arg3; // orthogonalize sky_vector, preserving screen direction 59 arg2 *= 1/norm(arg2); // and normalize 60 61 m_e1 = arg2*arg3; 62 m_e2 = arg2; 63 m_e3 = arg3; 64 } 65 66 rot1(double angle)67 frame& frame::rot1(double angle) 68 { 69 P temp2(m_e2); 70 P temp3(m_e3); 71 72 m_e2 = (Cos(angle)*(temp2)) - (Sin(angle)*(temp3)); 73 m_e3 = (Sin(angle)*(temp2)) + (Cos(angle)*(temp3)); 74 75 return *this; 76 } 77 78 rot2(double angle)79 frame& frame::rot2(double angle) 80 { 81 P temp3(m_e3); 82 P temp1(m_e1); 83 84 m_e3 = (Cos(angle)*(temp3)) - (Sin(angle)*(temp1)); 85 m_e1 = (Sin(angle)*(temp3)) + (Cos(angle)*(temp1)); 86 87 return *this; 88 } 89 rot3(double angle)90 frame& frame::rot3(double angle) 91 { 92 P temp1(m_e1); 93 P temp2(m_e2); 94 95 m_e1 = (Cos(angle)*(temp1)) - (Sin(angle)*(temp2)); 96 m_e2 = (Sin(angle)*(temp1)) + (Cos(angle)*(temp2)); 97 98 return *this; 99 } 100 101 // frame elements sea() const102 P frame::sea() const 103 { 104 return m_e1; 105 } sky() const106 P frame::sky() const 107 { 108 return m_e2; 109 } eye() const110 P frame::eye() const 111 { 112 return m_e3; 113 } 114 } // end of namespace 115