1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_BASEGFX_VECTOR_B3DVECTOR_HXX
21 #define INCLUDED_BASEGFX_VECTOR_B3DVECTOR_HXX
23 #include <basegfx/tuple/b3dtuple.hxx>
24 #include <basegfx/basegfxdllapi.h>
30 /** Base Point class with three double values
32 This class derives all operators and common handling for
33 a 3D data class from B3DTuple. All necessary extensions
34 which are special for 3D Vectors are added here.
38 class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B3DVector
: public ::basegfx::B3DTuple
41 /** Create a 3D Vector
43 The vector is initialized to (0.0, 0.0, 0.0)
49 /** Create a 3D Vector
52 This parameter is used to initialize the X-coordinate
56 This parameter is used to initialize the Y-coordinate
60 This parameter is used to initialize the Z-coordinate
63 B3DVector(double fX
, double fY
, double fZ
)
64 : B3DTuple(fX
, fY
, fZ
)
67 /** Create a copy of a 3D Vector
70 The 3D Vector which will be copied.
72 B3DVector(const B3DVector
& rVec
)
76 /** constructor with tuple to allow copy-constructing
77 from B3DTuple-based classes
79 B3DVector(const ::basegfx::B3DTuple
& rTuple
)
83 /** *=operator to allow usage from B3DVector, too
85 B3DVector
& operator*=( const B3DVector
& rPnt
)
93 /** *=operator to allow usage from B3DVector, too
95 B3DVector
& operator*=(double t
)
103 /** assignment operator to allow assigning the results
104 of B3DTuple calculations
106 B3DVector
& operator=( const ::basegfx::B3DTuple
& rVec
)
114 /** Calculate the length of this 3D Vector
116 @return The Length of the 3D Vector
118 double getLength() const
120 double fLen(scalar(*this));
121 if((0.0 == fLen
) || (1.0 == fLen
))
126 /** Calculate the length in the XZ-Plane for this 3D Vector
128 @return The XZ-Plane Length of the 3D Vector
130 double getXZLength() const
132 double fLen((mfX
* mfX
) + (mfZ
* mfZ
)); // #i73040#
133 if((0.0 == fLen
) || (1.0 == fLen
))
138 /** Calculate the length in the YZ-Plane for this 3D Vector
140 @return The YZ-Plane Length of the 3D Vector
142 double getYZLength() const
144 double fLen((mfY
* mfY
) + (mfZ
* mfZ
));
145 if((0.0 == fLen
) || (1.0 == fLen
))
150 /** Set the length of this 3D Vector
153 The to be achieved length of the 3D Vector
155 B3DVector
& setLength(double fLen
)
157 double fLenNow(scalar(*this));
159 if(!::basegfx::fTools::equalZero(fLenNow
))
161 const double fOne(1.0);
163 if(!::basegfx::fTools::equal(fOne
, fLenNow
))
165 fLen
/= sqrt(fLenNow
);
176 /** Normalize this 3D Vector
178 The length of the 3D Vector is set to 1.0
180 B3DVector
& normalize();
182 /** get a 3D Vector which is perpendicular to this and a given 3D Vector
184 @attention This only works if this and the given 3D Vector are
187 @param rNormalizedVec
188 A normalized 3D Vector.
191 A 3D Vector perpendicular to this and the given one
193 B3DVector
getPerpendicular(const B3DVector
& rNormalizedVec
) const;
195 /** Calculate the Scalar product
197 This method calculates the Scalar product between this
198 and the given 3D Vector.
204 The Scalar Product of two 3D Vectors
206 double scalar(const B3DVector
& rVec
) const
208 return ((mfX
* rVec
.mfX
) + (mfY
* rVec
.mfY
) + (mfZ
* rVec
.mfZ
));
211 /** Transform vector by given transformation matrix.
213 Since this is a vector, translational components of the
214 matrix are disregarded.
216 B3DVector
& operator*=( const B3DHomMatrix
& rMat
);
218 static const B3DVector
& getEmptyVector()
220 return static_cast<const B3DVector
&>( ::basegfx::B3DTuple::getEmptyTuple() );
224 // external operators
227 /** Test two vectors which need not to be normalized for parallelism
236 bool if the two values are parallel. Also true if
237 one of the vectors is empty.
239 BASEGFX_DLLPUBLIC
bool areParallel( const B3DVector
& rVecA
, const B3DVector
& rVecB
);
241 /** Transform vector by given transformation matrix.
243 Since this is a vector, translational components of the
244 matrix are disregarded.
246 BASEGFX_DLLPUBLIC B3DVector
operator*( const B3DHomMatrix
& rMat
, const B3DVector
& rVec
);
248 /** Calculate the Cross Product of two 3D Vectors
257 The Cross Product of both 3D Vectors
259 inline B3DVector
cross(const B3DVector
& rVecA
, const B3DVector
& rVecB
)
262 rVecA
.getY() * rVecB
.getZ() - rVecA
.getZ() * rVecB
.getY(),
263 rVecA
.getZ() * rVecB
.getX() - rVecA
.getX() * rVecB
.getZ(),
264 rVecA
.getX() * rVecB
.getY() - rVecA
.getY() * rVecB
.getX());
267 } // end of namespace basegfx
269 #endif // INCLUDED_BASEGFX_VECTOR_B3DVECTOR_HXX
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */