1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: b3dvector.cxx,v $
10 * $Revision: 1.9.4.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basegfx.hxx"
33 #include <basegfx/vector/b3dvector.hxx>
34 #include <basegfx/matrix/b3dhommatrix.hxx>
36 //////////////////////////////////////////////////////////////////////////////
40 B3DVector
& B3DVector::normalize()
42 double fLen(scalar(*this));
44 if(!::basegfx::fTools::equalZero(fLen
))
46 const double fOne(1.0);
48 if(!::basegfx::fTools::equal(fOne
, fLen
))
52 if(!::basegfx::fTools::equalZero(fLen
))
64 B3DVector
B3DVector::getPerpendicular(const B3DVector
& rNormalizedVec
) const
66 B3DVector
aNew(*this);
67 aNew
= cross(aNew
, rNormalizedVec
);
72 B3DVector
B3DVector::getProjectionOnPlane(const B3DVector
& rNormalizedPlane
) const
74 B3DVector
aNew(*this);
75 aNew
= cross(aNew
, rNormalizedPlane
);
76 aNew
= cross(aNew
, rNormalizedPlane
);
78 aNew
.mfX
= mfX
- aNew
.mfX
;
79 aNew
.mfY
= mfY
- aNew
.mfY
;
80 aNew
.mfZ
= mfZ
- aNew
.mfZ
;
85 B3DVector
& B3DVector::operator*=( const ::basegfx::B3DHomMatrix
& rMat
)
87 const double fTempX( rMat
.get(0,0)*mfX
+ rMat
.get(0,1)*mfY
+ rMat
.get(0,2)*mfZ
);
88 const double fTempY( rMat
.get(1,0)*mfX
+ rMat
.get(1,1)*mfY
+ rMat
.get(1,2)*mfZ
);
89 const double fTempZ( rMat
.get(2,0)*mfX
+ rMat
.get(2,1)*mfY
+ rMat
.get(2,2)*mfZ
);
97 B3DVector
operator*( const ::basegfx::B3DHomMatrix
& rMat
, const B3DVector
& rVec
)
99 B3DVector
aRes( rVec
);
103 bool areParallel( const B3DVector
& rVecA
, const B3DVector
& rVecB
)
105 // i think fastest is to compare relations, need no square or division
106 if(!fTools::equal(rVecA
.getX() * rVecB
.getY(), rVecA
.getY() * rVecB
.getX()))
109 if(!fTools::equal(rVecA
.getX() * rVecB
.getZ(), rVecA
.getZ() * rVecB
.getX()))
112 return (fTools::equal(rVecA
.getY() * rVecB
.getZ(), rVecA
.getZ() * rVecB
.getY()));
115 } // end of namespace basegfx
117 //////////////////////////////////////////////////////////////////////////////