1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_basegfx.hxx"
30 #include <basegfx/vector/b3dvector.hxx>
31 #include <basegfx/matrix/b3dhommatrix.hxx>
33 //////////////////////////////////////////////////////////////////////////////
37 B3DVector
& B3DVector::normalize()
39 double fLen(scalar(*this));
41 if(!::basegfx::fTools::equalZero(fLen
))
43 const double fOne(1.0);
45 if(!::basegfx::fTools::equal(fOne
, fLen
))
49 if(!::basegfx::fTools::equalZero(fLen
))
61 B3DVector
B3DVector::getPerpendicular(const B3DVector
& rNormalizedVec
) const
63 B3DVector
aNew(*this);
64 aNew
= cross(aNew
, rNormalizedVec
);
69 B3DVector
B3DVector::getProjectionOnPlane(const B3DVector
& rNormalizedPlane
) const
71 B3DVector
aNew(*this);
72 aNew
= cross(aNew
, rNormalizedPlane
);
73 aNew
= cross(aNew
, rNormalizedPlane
);
75 aNew
.mfX
= mfX
- aNew
.mfX
;
76 aNew
.mfY
= mfY
- aNew
.mfY
;
77 aNew
.mfZ
= mfZ
- aNew
.mfZ
;
82 B3DVector
& B3DVector::operator*=( const ::basegfx::B3DHomMatrix
& rMat
)
84 const double fTempX( rMat
.get(0,0)*mfX
+ rMat
.get(0,1)*mfY
+ rMat
.get(0,2)*mfZ
);
85 const double fTempY( rMat
.get(1,0)*mfX
+ rMat
.get(1,1)*mfY
+ rMat
.get(1,2)*mfZ
);
86 const double fTempZ( rMat
.get(2,0)*mfX
+ rMat
.get(2,1)*mfY
+ rMat
.get(2,2)*mfZ
);
94 B3DVector
operator*( const ::basegfx::B3DHomMatrix
& rMat
, const B3DVector
& rVec
)
96 B3DVector
aRes( rVec
);
100 bool areParallel( const B3DVector
& rVecA
, const B3DVector
& rVecB
)
102 // i think fastest is to compare relations, need no square or division
103 if(!fTools::equal(rVecA
.getX() * rVecB
.getY(), rVecA
.getY() * rVecB
.getX()))
106 if(!fTools::equal(rVecA
.getX() * rVecB
.getZ(), rVecA
.getZ() * rVecB
.getX()))
109 return (fTools::equal(rVecA
.getY() * rVecB
.getZ(), rVecA
.getZ() * rVecB
.getY()));
112 } // end of namespace basegfx
114 //////////////////////////////////////////////////////////////////////////////